Browse Source

add more generic support for attributes to resource....

add support for duration to the PYVR module....

add some more debug about trapping the 500 error, and how to
recover from it properly...

[git-p4: depot-paths = "//depot/": change = 1149]
replace/b43bf02ddeddd088c0e6b94974ca1a46562eb3db
John-Mark Gurney 17 years ago
parent
commit
1bd472a32d
2 changed files with 63 additions and 23 deletions
  1. +36
    -11
      DIDLLite.py
  2. +27
    -12
      pyvr.py

+ 36
- 11
DIDLLite.py View File

@@ -9,26 +9,51 @@ __version__ = '$Change$'

from elementtree.ElementTree import Element, SubElement, tostring, _ElementInterface

class Resource:
class Resource(object):
"""An object representing a resource."""

validattrs = {
'protocolinfo' 'protocolInfo',
'importuri' 'importUri',
'size' 'size',
'duration' 'duration',
'prtection' 'protection,
'bitrate' 'bitrate',
'bitspersample': 'bitsPerSample',
'samplefrequency': 'sampleFrequence',
'nraudiochannels': 'nrAudioChannels',
'resolution' 'resolution',
'colordepth' 'colorDepth',
'tspec' 'tspec',
'alloweduse' 'allowedUse',
'validitystart': 'validityStart',
'validityend' 'validityEnd',
'remainingtime': 'remainingTime',
'usageinfo' 'usageInfo',
'rightsinfouri': 'rightsInfoURI',
'contentinfouri': 'contentInfoURI',
'recordquality': 'recordQuality',
}

def __init__(self, data, protocolInfo):
self.data = data
object.__init__(self)

# Use thses so setattr can be more simple
object.__setattr__(self, 'data', data)
object.__setattr__(self, 'attrs', {})

self.protocolInfo = protocolInfo
self.bitrate = None
self.size = None

def toElement(self):
def __setattr__(self, key, value):
key = key.tolower()
self.attrs[self.validattrs[key]] = value

def toElement(self):
root = Element('res')
root.attrib['protocolInfo'] = self.protocolInfo
root.text = self.data

if self.bitrate is not None:
root.attrib['bitrate'] = str(self.bitrate)

if self.size is not None:
root.attrib['size'] = str(self.size)
for i in self.attrs:
root.attrib[i] = str(self.attrs[i])

return root



+ 27
- 12
pyvr.py View File

@@ -52,7 +52,7 @@ class PYVRShow(VideoItem):
url = urlparse.urljoin(baseurl, url)
self.res = Resource(url,
'http-get:*:%s:*' % self.info['mimetype'])
#self.res.size = self.chapter.size
self.res.duration = self.info['duration']

def doUpdate(self):
pass
@@ -62,6 +62,9 @@ import xml.sax.handler
from xml.sax.saxutils import unescape

class RecordingXML(xml.sax.handler.ContentHandler):
dataels = ('title', 'subtitle', 'duration', 'mimetype', 'link',
'delete', )

def __init__(self):
self.shows = {}
self.data = None
@@ -71,14 +74,14 @@ class RecordingXML(xml.sax.handler.ContentHandler):
self.data.append(chars)

def startElement(self, name, attrs):
if name in ('title', 'subtitle', 'mimetype', 'link', 'delete'):
if name in self.dataels:
self.data = []
self.curel = name
elif name == 'record':
self.currec = {}

def endElement(self, name):
if name in ('title', 'subtitle', 'mimetype', 'link', 'delete'):
if name in dataels:
data = unescape(''.join(self.data))
self.currec[self.curel] = data
elif name == 'record':
@@ -175,33 +178,46 @@ class PYVR(Container):
Container.__init__(self, *args, **kwargs)

self.pathObjmap = {}
self.isPend = False
self.pend = None
self.lastmodified = None
self.newobjs = None
self.objs = {}
self.lastcheck = 0

def checkUpdate(self):
if self.isPend:
if self.pend is not None:
raise self.pend

if time.time() - self.lastcheck < 5:
print '<5'
return

# Check to see if any changes have been made
self.isPend = True
self.lastcheck = time.time()
self.runCheck()

raise self.pend

def runCheck(self):
print 'runCheck'
self.page = getPage(self.url, method='HEAD')
self.page.deferred.addCallback(self.doCheck)
self.page.deferred.addErrback(self.errCheck).addCallback(
self.doCheck)
self.pend = self.page.deferred

raise self.pend
def errCheck(self, x):
print 'errCheck:', `x`
self.runCheck()

def doCheck(self, x):
print 'doCheck:', self.page.status
if self.page.status != '200':
return reactor.callLater(.01, self.runCheck)

self.lastcheck = time.time()
slm = self.page.response_headers['last-modified']
if slm == self.lastmodified:
# Page the same, don't do anything
self.isPend = False
self.pend = None
return

self.page = getPage(self.url)
@@ -213,9 +229,8 @@ class PYVR(Container):
def parsePage(self, page):
slm = self.page.response_headers['last-modified']
self.lastmodified = slm
self.isPend = False
del self.page
del self.pend
self.pend = None

self.newobjs = recxmltoobj(page)
self.doUpdate()


Loading…
Cancel
Save