website has changed

This commit is contained in:
Romain Bignon 2012-01-31 17:51:23 +01:00
commit 27d666dfe1
2 changed files with 58 additions and 65 deletions

View file

@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import re
import datetime import datetime
from .base import PornPage from .base import PornPage
@ -29,47 +30,45 @@ __all__ = ['IndexPage']
class IndexPage(PornPage): class IndexPage(PornPage):
def iter_videos(self): def iter_videos(self):
uls = self.document.getroot().cssselect("ul[class=clearfix]") for li in self.document.getroot().xpath('//ul/li[@class="videoBox"]'):
if not uls: a = li.find('a')
return if a is None or a.find('img') is None:
continue
for ul in uls: thumbnail_url = a.find('img').attrib['src']
for li in ul.findall('li'):
a = li.find('a')
if a is None or a.find('img') is None:
continue
thumbnail_url = a.find('img').attrib['src'] h1 = li.find('h1')
a = h1.find('a')
if a is None:
continue
h1 = li.find('h1') url = a.attrib['href']
a = h1.find('a') _id = url[len('/watch/'):]
if a is None: _id = _id[:_id.find('/')]
continue title = a.text.strip()
url = a.attrib['href'] hours = minutes = seconds = 0
_id = url[len('/watch/'):] div = li.cssselect('h2[class=duration]')
_id = _id[:_id.find('/')] if len(div) > 0:
title = a.text.strip() pack = [int(s) for s in div[0].text.strip().split(':')]
if len(pack) == 3:
hours, minutes, seconds = pack
elif len(pack) == 2:
minutes, seconds = pack
minutes = seconds = 0 rating = 0
div = li.cssselect('div[class=duration_views]') rating_max = 0
if div: div = li.cssselect('div.stars')
h2 = div[0].find('h2') if div:
minutes = int(h2.text.strip()) m = re.match('.*star-(\d).*', div[0].attrib.get('class', ''))
seconds = int(h2.find('span').tail.strip()) if m:
rating = int(m.group(1))
rating_max = 5
rating = 0 yield YoupornVideo(int(_id),
rating_max = 0 title=title,
div = li.cssselect('div[class=rating]') rating=rating,
if div: rating_max=rating_max,
p = div[0].find('p') duration=datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds),
rating = float(p.text.strip()) thumbnail_url=thumbnail_url,
rating_max = float(p.find('span').text.strip()[2:]) )
yield YoupornVideo(int(_id),
title=title,
rating=rating,
rating_max=rating_max,
duration=datetime.timedelta(minutes=minutes, seconds=seconds),
thumbnail_url=thumbnail_url,
)

View file

@ -20,8 +20,9 @@
import re import re
import datetime import datetime
from dateutil.parser import parse as parse_dt
from weboob.tools.browser import BrokenPageError
from .base import PornPage from .base import PornPage
from ..video import YoupornVideo from ..video import YoupornVideo
@ -39,8 +40,11 @@ class VideoPage(PornPage):
return video return video
def get_url(self): def get_url(self):
download_div = self.parser.select(self.document.getroot(), '#download', 1) download_div = self.parser.select(self.document.getroot(), 'div#tab-general-download ul li')
a = self.parser.select(download_div, 'a', 1) if len(download_div) < 1:
raise BrokenPageError('Unable to find file URL')
a = self.parser.select(download_div[0], 'a', 1)
m = re.match('^(\w+) - .*', a.text) m = re.match('^(\w+) - .*', a.text)
if m: if m:
ext = m.group(1).lower() ext = m.group(1).lower()
@ -49,27 +53,25 @@ class VideoPage(PornPage):
return a.attrib['href'], ext return a.attrib['href'], ext
def get_title(self): def get_title(self):
element = self.parser.select(self.document.getroot(), '#videoArea h1', 1) element = self.parser.select(self.document.getroot(), '#videoCanvas h1', 1)
return unicode(element.getchildren()[0].tail).strip() return element.text.strip().decode('utf-8')
DATE_REGEXP = re.compile("\w+ (\w+) (\d+) (\d+):(\d+):(\d+) (\d+)")
MONTH2I = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
def set_details(self, v): def set_details(self, v):
details_div = self.parser.select(self.document.getroot(), '#details', 1) for li in self.parser.select(self.document.getroot(), 'div#tab-general-details ul li'):
for li in details_div.getiterator('li'): span = li.find('b')
span = li.find('span')
name = span.text.strip() name = span.text.strip()
value = span.tail.strip() value = span.tail.strip()
if name == 'Duration:': if name == 'Duration:':
seconds = minutes = 0 m = re.match('((\d+)hrs)?((\d+)min)?(\d+)?', value)
for word in value.split(): if not m:
if word.endswith('min'): raise BrokenPageError('Unable to parse datetime: %r' % value)
minutes = int(word[:word.find('min')]) hours = m.group(2) or 0
elif word.endswith('sec'): minutes = m.group(4) or 0
seconds = int(word[:word.find('sec')]) seconds = m.group(5) or 0
v.duration = datetime.timedelta(minutes=minutes, seconds=seconds) v.duration = datetime.timedelta(hours=int(hours),
minutes=int(minutes),
seconds=int(seconds))
elif name == 'Submitted:': elif name == 'Submitted:':
author = li.find('i') author = li.find('i')
if author is None: if author is None:
@ -83,12 +85,4 @@ class VideoPage(PornPage):
v.rating = float(r[0]) v.rating = float(r[0])
v.rating_max = float(r[2]) v.rating_max = float(r[2])
elif name == 'Date:': elif name == 'Date:':
m = self.DATE_REGEXP.match(value) v.date = parse_dt(value)
if m:
month = self.MONTH2I.index(m.group(1))
day = int(m.group(2))
hour = int(m.group(3))
minute = int(m.group(4))
second = int(m.group(5))
year = int(m.group(6))
v.date = datetime.datetime(year, month, day, hour, minute, second)