diff --git a/weboob/backends/youporn/pages/index.py b/weboob/backends/youporn/pages/index.py index 1c115baa..5104a9cd 100644 --- a/weboob/backends/youporn/pages/index.py +++ b/weboob/backends/youporn/pages/index.py @@ -23,13 +23,45 @@ from weboob.capabilities.video import Video class IndexPage(PornPage): def iter_videos(self): - for h1 in self.document.getiterator('h1'): - a = h1.find('a') - if a is None: - continue + uls = self.document.getroot().cssselect("ul[class=clearfix]") + if not uls: + return - url = a.attrib['href'] - _id = url[len('/watch/'):] - _id = _id[:_id.find('/')] - title = a.text - yield Video(int(_id), title) + for ul in uls: + for li in ul.findall('li'): + a = li.find('a') + if a is None or a.find('img') is None: + continue + + preview_url = a.find('img').attrib['src'] + + h1 = li.find('h1') + a = h1.find('a') + if a is None: + continue + + url = a.attrib['href'] + _id = url[len('/watch/'):] + _id = _id[:_id.find('/')] + title = a.text + + duration = 0 + div = li.cssselect('div[class=duration_views]') + if div: + h2 = div[0].find('h2') + duration = 60 * int(h2.text) + duration += int(h2.find('span').tail) + + rating = 0 + rating_max = 0 + div = li.cssselect('div[class=rating]') + if div: + p = div[0].find('p') + rating = float(p.text.strip()) + rating_max = float(p.find('span').text.strip()[2:]) + yield Video(int(_id), + title, + rating=rating, + rating_max=rating_max, + duration=duration, + preview_url=preview_url)