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
|
|
@ -26,7 +26,8 @@ import re
|
|||
import urllib
|
||||
|
||||
from weboob.capabilities.base import NotAvailable
|
||||
from weboob.capabilities.video import ICapVideo
|
||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||
from weboob.tools.capabilities.thumbnail import Thumbnail
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.misc import to_unicode
|
||||
|
|
@ -39,7 +40,7 @@ from .video import YoutubeVideo
|
|||
__all__ = ['YoutubeBackend']
|
||||
|
||||
|
||||
class YoutubeBackend(BaseBackend, ICapVideo):
|
||||
class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||
NAME = 'youtube'
|
||||
MAINTAINER = 'Christophe Benz'
|
||||
EMAIL = 'christophe.benz@gmail.com'
|
||||
|
|
@ -110,7 +111,7 @@ class YoutubeBackend(BaseBackend, ICapVideo):
|
|||
video.set_empty_fields(NotAvailable)
|
||||
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):
|
||||
YOUTUBE_MAX_RESULTS = 50
|
||||
YOUTUBE_MAX_START_INDEX = 1000
|
||||
yt_service = gdata.youtube.service.YouTubeService()
|
||||
|
|
@ -144,6 +145,9 @@ class YoutubeBackend(BaseBackend, ICapVideo):
|
|||
if nb_yielded == max_results:
|
||||
return
|
||||
|
||||
def latest_videos(self):
|
||||
return self.search_videos(None, ICapVideo.SEARCH_DATE)
|
||||
|
||||
def fill_video(self, video, fields):
|
||||
if 'thumbnail' in fields:
|
||||
video.thumbnail.data = urllib.urlopen(video.thumbnail.url).read()
|
||||
|
|
@ -151,4 +155,21 @@ class YoutubeBackend(BaseBackend, ICapVideo):
|
|||
self._set_video_url(video)
|
||||
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.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 YouTube videos'
|
||||
return
|
||||
raise CollectionNotFound(collection.split_path)
|
||||
|
||||
OBJECTS = {YoutubeVideo: fill_video}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue