diff --git a/modules/youjizz/backend.py b/modules/youjizz/backend.py index 21981e4a..44159c63 100644 --- a/modules/youjizz/backend.py +++ b/modules/youjizz/backend.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Roger Philibert +# Copyright(C) 2010-2014 Roger Philibert # # This file is part of weboob. # @@ -25,7 +25,6 @@ from weboob.capabilities.collection import ICapCollection, CollectionNotFound from weboob.tools.backend import BaseBackend from .browser import YoujizzBrowser -from .video import YoujizzVideo __all__ = ['YoujizzBackend'] @@ -52,11 +51,9 @@ class YoujizzBackend(BaseBackend, ICapVideo, ICapCollection): def fill_video(self, video, fields): if fields != ['thumbnail']: # if we don't want only the thumbnail, we probably want also every fields - with self.browser: - video = self.browser.get_video(YoujizzVideo.id2url(video.id), video) + video = self.browser.get_video(video.id, video) if 'thumbnail' in fields and video.thumbnail: - with self.browser: - video.thumbnail.data = self.browser.readurl(video.thumbnail.url) + video.thumbnail.data = self.browser.readurl(video.thumbnail.url) return video @@ -77,4 +74,4 @@ class YoujizzBackend(BaseBackend, ICapVideo, ICapCollection): return raise CollectionNotFound(collection.split_path) - OBJECTS = {YoujizzVideo: fill_video} + OBJECTS = {BaseVideo: fill_video} diff --git a/modules/youjizz/browser.py b/modules/youjizz/browser.py index d2ccebaf..b4457243 100644 --- a/modules/youjizz/browser.py +++ b/modules/youjizz/browser.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Roger Philibert +# Copyright(C) 2010-2014 Roger Philibert # # This file is part of weboob. # @@ -19,11 +19,9 @@ from weboob.tools.browser2 import PagesBrowser, URL -from weboob.tools.browser.decorators import id2url from .pages.index import IndexPage from .pages.video import VideoPage -from .video import YoujizzVideo __all__ = ['YoujizzBrowser'] @@ -32,11 +30,13 @@ __all__ = ['YoujizzBrowser'] class YoujizzBrowser(PagesBrowser): BASEURL = 'http://www.youjizz.com' - index = URL(r'/?(index.php)?$', IndexPage) + index = URL(r'/?(index.php)?$', + r'/page/\d+.html', + IndexPage) search = URL(r'/search/(?P.+)-(?P\d+).html', IndexPage) video = URL(r'/videos/(?P.*).html', VideoPage) - @id2url(YoujizzVideo.id2url) + @video.id2url def get_video(self, url, video=None): self.location(url) assert self.video.is_here() diff --git a/modules/youjizz/pages/index.py b/modules/youjizz/pages/index.py index 70658c3a..bb7c7cba 100644 --- a/modules/youjizz/pages/index.py +++ b/modules/youjizz/pages/index.py @@ -25,8 +25,7 @@ from weboob.tools.browser2 import HTMLPage from weboob.tools.browser2.page import ListElement, method, ItemElement from weboob.tools.browser2.filters import Filter, Link, CleanText from weboob.capabilities.image import BaseImage - -from ..video import YoujizzVideo +from weboob.capabilities.video import BaseVideo __all__ = ['IndexPage'] @@ -40,7 +39,7 @@ class IndexPage(HTMLPage): next_page = Link(u'//a[text()="Next ยป"]') class item(ItemElement): - klass = YoujizzVideo + klass = BaseVideo class Id(Filter): def filter(self, link): @@ -66,6 +65,7 @@ class IndexPage(HTMLPage): obj_id = Id(Link('.//a')) obj_title = CleanText('.//span[@id="title1"]') obj_duration = Duration(CleanText('.//span[@class="thumbtime"]//span')) + obj_nsfw = True def obj_thumbnail(self): thumbnail = BaseImage(self.xpath('.//img')[0].attrib['data-original']) diff --git a/modules/youjizz/pages/video.py b/modules/youjizz/pages/video.py index 4ded1ccb..2e905a19 100644 --- a/modules/youjizz/pages/video.py +++ b/modules/youjizz/pages/video.py @@ -25,10 +25,9 @@ from weboob.tools.browser2 import HTMLPage from weboob.tools.browser2.page import method, ItemElement from weboob.tools.browser2.filters import CleanText, Env from weboob.capabilities.base import NotAvailable +from weboob.capabilities.video import BaseVideo from weboob.tools.misc import to_unicode -from ..video import YoujizzVideo - __all__ = ['VideoPage'] @@ -36,10 +35,12 @@ __all__ = ['VideoPage'] class VideoPage(HTMLPage): @method class get_video(ItemElement): - klass = YoujizzVideo + klass = BaseVideo obj_id = Env('id') obj_title = CleanText('//title') + obj_nsfw = True + obj_ext = u'flv' def obj_duration(self): # youjizz HTML is crap, we must parse it with regexps diff --git a/modules/youjizz/test.py b/modules/youjizz/test.py index a2a75848..fc05d3b9 100644 --- a/modules/youjizz/test.py +++ b/modules/youjizz/test.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Romain Bignon +# Copyright(C) 2010-2014 Romain Bignon # # This file is part of weboob. # @@ -18,6 +18,7 @@ # along with weboob. If not, see . +from weboob.tools.misc import limit from weboob.tools.test import BackendTest from weboob.capabilities.video import BaseVideo @@ -28,15 +29,16 @@ class YoujizzTest(BackendTest): def test_search(self): self.assertTrue(len(self.backend.search_videos('anus', nsfw=False)) == 0) - l = list(self.backend.search_videos('anus', nsfw=True)) + l = list(limit(self.backend.search_videos('anus', nsfw=True), 100)) self.assertTrue(len(l) > 0) v = l[0] self.backend.fillobj(v, ('url',)) self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url)) - self.backend.browser.openurl(v.url) + r = self.backend.browser.open(v.url, stream=True) + self.assertTrue(r.status_code == 200) def test_latest(self): - l = list(self.backend.iter_resources([BaseVideo], [u'latest_nsfw'])) + l = list(limit(self.backend.iter_resources([BaseVideo], [u'latest_nsfw']), 100)) self.assertTrue(len(l) > 0) v = l[0] self.backend.fillobj(v, ('url',)) diff --git a/modules/youjizz/video.py b/modules/youjizz/video.py deleted file mode 100644 index 06bb0bc5..00000000 --- a/modules/youjizz/video.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2010-2011 Roger Philibert -# -# This file is part of weboob. -# -# weboob is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# weboob is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with weboob. If not, see . - - -from weboob.capabilities.video import BaseVideo - - -__all__ = ['YoujizzVideo'] - - -class YoujizzVideo(BaseVideo): - def __init__(self, *args, **kwargs): - BaseVideo.__init__(self, *args, **kwargs) - self.nsfw = True - self.ext = u'flv' - - @classmethod - def id2url(cls, _id): - return 'http://www.youjizz.com/videos/%s.html' % _id