fix youjizz when duration is not available

This commit is contained in:
Romain Bignon 2011-03-25 08:14:45 +01:00
commit 1d687e3cb7

View file

@ -20,6 +20,7 @@ import datetime
import lxml.html import lxml.html
import re import re
from weboob.capabilities.base import NotAvailable
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.tools.misc import to_unicode from weboob.tools.misc import to_unicode
from weboob.tools.parsers.lxmlparser import select, SelectElementException from weboob.tools.parsers.lxmlparser import select, SelectElementException
@ -42,14 +43,15 @@ class VideoPage(BasePage):
# youjizz HTML is crap, we must parse it with regexps # youjizz HTML is crap, we must parse it with regexps
data = lxml.html.tostring(self.document.getroot()) data = lxml.html.tostring(self.document.getroot())
m = re.search(r'<strong>.*?Runtime.*?</strong> (.+?)<br.*>', data) m = re.search(r'<strong>.*?Runtime.*?</strong> (.+?)<br.*>', data)
try: if m:
if m: txt = m.group(1).strip()
minutes, seconds = (int(v) for v in to_unicode(m.group(1).strip()).split(':')) if txt == 'Unknown':
video.duration = datetime.timedelta(minutes=minutes, seconds=seconds) video.duration = NotAvailable
else: else:
raise Exception() minutes, seconds = (int(v) for v in to_unicode(txt).split(':'))
except Exception: video.duration = datetime.timedelta(minutes=minutes, seconds=seconds)
raise SelectElementException('Could not retrieve video duration') else:
raise SelectElementException('Unable to retrieve video duration')
video_file_urls = re.findall(r'"(http://media[^ ,]+\.flv)"', data) video_file_urls = re.findall(r'"(http://media[^ ,]+\.flv)"', data)
if len(video_file_urls) == 0: if len(video_file_urls) == 0: