Move the "empty search for latest" to collections
There is now a "latest" collection (or "latest_nsfw"). The feature didn't look much used, since it didn't work on many backends. Using collections will make it easy to support other things like most viewed, featured, etc. As a bonus, I added tests for every backend with the feature.
This commit is contained in:
parent
4d628112d5
commit
e958c229e6
32 changed files with 366 additions and 112 deletions
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.video import ICapVideo
|
||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||
from weboob.tools.backend import BaseBackend
|
||||
|
||||
from .browser import YoujizzBrowser
|
||||
|
|
@ -30,7 +31,7 @@ from .video import YoujizzVideo
|
|||
__all__ = ['YoujizzBackend']
|
||||
|
||||
|
||||
class YoujizzBackend(BaseBackend, ICapVideo):
|
||||
class YoujizzBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||
NAME = 'youjizz'
|
||||
MAINTAINER = 'Roger Philibert'
|
||||
EMAIL = 'roger.philibert@gmail.com'
|
||||
|
|
@ -44,7 +45,7 @@ class YoujizzBackend(BaseBackend, ICapVideo):
|
|||
video = self.browser.get_video(_id)
|
||||
return video
|
||||
|
||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||
if not nsfw:
|
||||
return set()
|
||||
with self.browser:
|
||||
|
|
@ -61,4 +62,21 @@ class YoujizzBackend(BaseBackend, ICapVideo):
|
|||
|
||||
return video
|
||||
|
||||
def iter_resources(self, objs, split_path):
|
||||
if BaseVideo in objs:
|
||||
collection = self.get_collection(objs, split_path)
|
||||
if collection.path_level == 0:
|
||||
yield self.get_collection(objs, [u'latest_nsfw'])
|
||||
if collection.split_path == [u'latest_nsfw']:
|
||||
for video in self.browser.latest_videos():
|
||||
yield video
|
||||
|
||||
def validate_collection(self, objs, collection):
|
||||
if collection.path_level == 0:
|
||||
return
|
||||
if BaseVideo in objs and collection.split_path == [u'latest_nsfw']:
|
||||
collection.title = u'Latest Youjizz videos (NSFW)'
|
||||
return
|
||||
raise CollectionNotFound(collection.split_path)
|
||||
|
||||
OBJECTS = {YoujizzVideo: fill_video}
|
||||
|
|
|
|||
|
|
@ -47,9 +47,11 @@ class YoujizzBrowser(BaseBrowser):
|
|||
return self.page.get_video(video)
|
||||
|
||||
def search_videos(self, pattern):
|
||||
if not pattern:
|
||||
self.home()
|
||||
else:
|
||||
self.location('/search/%s-1.html' % (urllib.quote_plus(pattern.encode('utf-8'))))
|
||||
self.location('/search/%s-1.html' % (urllib.quote_plus(pattern.encode('utf-8'))))
|
||||
assert self.is_on_page(IndexPage)
|
||||
return self.page.iter_videos()
|
||||
|
||||
def latest_videos(self):
|
||||
self.home()
|
||||
assert self.is_on_page(IndexPage)
|
||||
return self.page.iter_videos()
|
||||
|
|
|
|||
|
|
@ -19,17 +19,25 @@
|
|||
|
||||
|
||||
from weboob.tools.test import BackendTest
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
|
||||
|
||||
class YoujizzTest(BackendTest):
|
||||
BACKEND = 'youjizz'
|
||||
|
||||
def test_youjizz(self):
|
||||
def test_search(self):
|
||||
self.assertTrue(len(self.backend.search_videos('anus', nsfw=False)) == 0)
|
||||
|
||||
l = list(self.backend.search_videos('sex', nsfw=True))
|
||||
l = list(self.backend.search_videos('anus', nsfw=True))
|
||||
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)
|
||||
|
||||
def test_latest(self):
|
||||
l = list(self.backend.iter_resources([BaseVideo], [u'latest_nsfw']))
|
||||
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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue