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
|
|
@ -10,7 +10,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 CappedBrowser, CappedVideo
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ from .browser import CappedBrowser, CappedVideo
|
|||
__all__ = ['CappedBackend']
|
||||
|
||||
|
||||
class CappedBackend(BaseBackend, ICapVideo):
|
||||
class CappedBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||
NAME = 'cappedtv'
|
||||
MAINTAINER = 'Lord'
|
||||
EMAIL = 'lord@lordtoniok.com'
|
||||
|
|
@ -31,7 +32,7 @@ class CappedBackend(BaseBackend, ICapVideo):
|
|||
with self.browser:
|
||||
return self.browser.get_video(_id)
|
||||
|
||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=None, max_results=None):
|
||||
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=None, max_results=None):
|
||||
with self.browser:
|
||||
return self.browser.search_videos(pattern)
|
||||
|
||||
|
|
@ -45,4 +46,21 @@ class CappedBackend(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'])
|
||||
if collection.split_path == [u'latest']:
|
||||
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']:
|
||||
collection.title = u'Latest CappedTV videos'
|
||||
return
|
||||
raise CollectionNotFound(collection.split_path)
|
||||
|
||||
OBJECTS = {CappedVideo: fill_video}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class IndexPage(BasePage):
|
|||
seconds = parts[0]
|
||||
elif len(parts) == 2:
|
||||
hours = 0
|
||||
minutes , seconds = parts
|
||||
minutes, seconds = parts
|
||||
elif len(parts) == 3:
|
||||
hours, minutes, seconds = parts
|
||||
else:
|
||||
|
|
@ -78,7 +78,6 @@ class IndexPage(BasePage):
|
|||
yield video
|
||||
|
||||
|
||||
|
||||
# parser for the video page
|
||||
class VideoPage(BasePage):
|
||||
def get_video(self, video=None):
|
||||
|
|
@ -118,10 +117,12 @@ class CappedBrowser(BaseBrowser):
|
|||
assert self.is_on_page(VideoPage), 'Should be on video page.'
|
||||
return self.page.get_video(video)
|
||||
|
||||
def search_videos(self,pattern):
|
||||
if not pattern:
|
||||
self.home()
|
||||
else:
|
||||
self.location('/search?s=%s' % (urllib.quote_plus(pattern.encode('utf-8'))))
|
||||
def search_videos(self, pattern):
|
||||
self.location('/search?s=%s' % (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()
|
||||
|
|
|
|||
|
|
@ -10,18 +10,23 @@
|
|||
|
||||
|
||||
from weboob.tools.test import BackendTest
|
||||
|
||||
|
||||
__all__ = ['CappedTest']
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
|
||||
|
||||
class CappedTest(BackendTest):
|
||||
BACKEND = 'cappedtv'
|
||||
|
||||
def test_capped(self):
|
||||
def test_search(self):
|
||||
l = list(self.backend.search_videos('kewlers'))
|
||||
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']))
|
||||
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