use the new URL.id2url decorator
This commit is contained in:
parent
9724dcf461
commit
2db4646779
6 changed files with 22 additions and 57 deletions
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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<pattern>.+)-(?P<pagenum>\d+).html', IndexPage)
|
||||
video = URL(r'/videos/(?P<id>.*).html', VideoPage)
|
||||
|
||||
@id2url(YoujizzVideo.id2url)
|
||||
@video.id2url
|
||||
def get_video(self, url, video=None):
|
||||
self.location(url)
|
||||
assert self.video.is_here()
|
||||
|
|
|
|||
|
|
@ -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'])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
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',))
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue