@@ -10,9 +10,10 @@ from FSStorage import registerklassfun
import os.path
import time
import twisted.web
from twisted.internet import reactor
from twisted.python import log
import twisted.web
import urlparse
def getPage(url, contextFactory=None, *args, **kwargs):
"""Download a web page as a string.
@@ -45,7 +46,7 @@ class PYVRShow(VideoItem):
VideoItem.__init__(self, *args, **kwargs)
url = self.info['link']
sc = urlparse.urlparse(url)
sc = urlparse.urlparse(url)[0]
if not sc:
# need to combine w/ base url
url = urlparse.urljoin(baseurl, url)
@@ -111,25 +112,26 @@ class PYVRShows(Container):
def checkUpdate(self):
self.pyvr.checkUpdate()
if self.pyvr.lastmodified != self.lastmodified:
self.doUpdate(self )
self.doUpdate()
@staticmethod
def getunique(eps, ep):
i = 1
while True:
title = '%s Copy %d' % (ep['subtitle'], i)
if not ret .has_key(title):
if not eps .has_key(title):
return title
i += 1
@staticmethod
def eplisttodict(eps):
ret = {}
for i in eps:
for pos, i in enumerate(e ps) :
title = i['subtitle']
if ret.has_key(title):
print 'WARNING: dup:', `i`, `ret[title]`
title = self.getunique(ret, i)
title = PYVRShows.getunique(ret, i)
i['pos'] = pos
ret[title] = i
return ret
@@ -158,10 +160,13 @@ class PYVRShows(Container):
self.shows = nl
# sort our children
self.sort(lambda x, y: cmp(x.title, y.title))
#self.sort(lambda x, y: cmp(x.title, y.title))
self.sort(lambda x, y: cmp(x.info['pos'], y.info['pos']))
if doupdate:
Container.doUpdate(self)
self.lastmodified = self.pyvr.lastmodified
class PYVR(Container):
def __init__(self, *args, **kwargs):
self.url = kwargs['url']
@@ -178,11 +183,9 @@ class PYVR(Container):
def checkUpdate(self):
if self.isPend:
print 'already'
raise self.pend
if time.time() - self.lastcheck < 5:
print 'escape'
return
# Check to see if any changes have been made
@@ -192,11 +195,9 @@ class PYVR(Container):
self.page.deferred.addCallback(self.doCheck)
self.pend = self.page.deferred
print 'doing raise'
raise self.pend
def doCheck(self, x):
print 'got check'
print `self.page.response_headers`
slm = self.page.response_headers['last-modified']
if slm == self.lastmodified:
@@ -211,7 +212,6 @@ class PYVR(Container):
return self.pend
def parsePage(self, page):
print 'parsing'
slm = self.page.response_headers['last-modified']
self.lastmodified = slm
self.isPend = False
@@ -261,7 +261,6 @@ class PYVR(Container):
def detectpyvrfile(path, fobj):
bn = os.path.basename(path)
if bn == 'PYVR':
print 'detected'
return PYVR, { 'url': fobj.readline().strip() }
return None, None