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:
Laurent Bachelier 2012-03-16 02:55:58 +01:00
commit e958c229e6
32 changed files with 366 additions and 112 deletions

View file

@ -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, BackendConfig
from weboob.tools.value import Value
@ -31,7 +32,7 @@ from .video import ArteVideo
__all__ = ['ArteBackend']
class ArteBackend(BaseBackend, ICapVideo):
class ArteBackend(BaseBackend, ICapVideo, ICapCollection):
NAME = 'arte'
MAINTAINER = 'Romain Bignon'
EMAIL = 'romain@weboob.org'
@ -50,7 +51,7 @@ class ArteBackend(BaseBackend, ICapVideo):
with self.browser:
return self.browser.get_video(_id)
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):
with self.browser:
return self.browser.search_videos(pattern)
@ -65,4 +66,21 @@ class ArteBackend(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 Arte videos'
return
raise CollectionNotFound(collection.split_path)
OBJECTS = {ArteVideo: fill_video}

View file

@ -36,7 +36,7 @@ class ArteBrowser(BaseBrowser):
r'http://videos.arte.tv/\w+/videos/(?P<id>.+)\.html': VideoPage
}
SEARCH_LANG = {'fr': 'recherche', 'de':'suche', 'en': 'search'}
SEARCH_LANG = {'fr': 'recherche', 'de': 'suche', 'en': 'search'}
def __init__(self, lang, quality, *args, **kwargs):
BaseBrowser.__init__(self, *args, **kwargs)
@ -52,9 +52,11 @@ class ArteBrowser(BaseBrowser):
self.location('http://videos.arte.tv/fr/videos/toutesLesVideos')
def search_videos(self, pattern):
if not pattern:
self.home()
else:
self.location(self.buildurl('/%s/do_search/videos/%s' % (self.lang, self.SEARCH_LANG[self.lang]), q=pattern.encode('utf-8')))
self.location(self.buildurl('/%s/do_search/videos/%s' % (self.lang, self.SEARCH_LANG[self.lang]), q=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()

View file

@ -19,13 +19,22 @@
from weboob.tools.test import BackendTest
from weboob.capabilities.video import BaseVideo
class ArteTest(BackendTest):
BACKEND = 'arte'
def test_arte(self):
def test_search(self):
l = list(self.backend.search_videos('arte'))
if len(l) > 0:
v = l[0]
self.backend.fillobj(v, ('url',))
self.assertTrue(v.url and v.url.startswith('rtmp://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
def test_latest(self):
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
assert len(l)
v = l[0]
self.backend.fillobj(v, ('url',))
self.assertTrue(v.url and v.url.startswith('rtmp://'), 'URL for video "%s" not found: %s' % (v.id, v.url))