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
|
|
@ -25,7 +25,7 @@ from re import search, sub
|
|||
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
from weboob.capabilities.gallery import ICapGallery
|
||||
from weboob.capabilities.gallery import ICapGallery, BaseGallery, BaseImage
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter
|
||||
|
||||
|
||||
|
|
@ -60,22 +60,23 @@ class Galleroob(ReplApplication):
|
|||
DESCRIPTION = 'galleroob browses and downloads web image galleries'
|
||||
CAPS = ICapGallery
|
||||
EXTRA_FORMATTERS = {'gallery_list': GalleryListFormatter}
|
||||
COMMANDS_FORMATTERS = {'search': 'gallery_list'}
|
||||
COMMANDS_FORMATTERS = {'search': 'gallery_list', 'ls': 'gallery_list'}
|
||||
COLLECTION_OBJECTS = (BaseGallery, BaseImage, )
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
ReplApplication.__init__(self, *args, **kwargs)
|
||||
|
||||
def do_search(self, pattern=None):
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search PATTERN
|
||||
|
||||
List galleries matching a PATTERN.
|
||||
|
||||
If PATTERN is not given, the command will list all the galleries
|
||||
"""
|
||||
if not pattern:
|
||||
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('search', short=True)
|
||||
return 2
|
||||
|
||||
self.set_formatter_header(u'Search pattern: %s' %
|
||||
pattern if pattern else u'Latest galleries')
|
||||
self.set_formatter_header(u'Search pattern: %s' % pattern)
|
||||
for backend, gallery in self.do('search_gallery',
|
||||
pattern=pattern, max_results=self.options.count):
|
||||
self.add_object(gallery)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class Videoob(ReplApplication):
|
|||
_id, dest = self.parse_command_args(line, 2, 1)
|
||||
video = self.get_object(_id, 'get_video', ['url'])
|
||||
if not video:
|
||||
print >>sys.stderr, 'Video not found: %s' % _id
|
||||
print >>sys.stderr, 'Video not found: %s' % _id
|
||||
return 3
|
||||
|
||||
if not video.url:
|
||||
|
|
@ -109,7 +109,6 @@ class Videoob(ReplApplication):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
if dest is None:
|
||||
ext = video.ext
|
||||
if not ext:
|
||||
|
|
@ -148,7 +147,7 @@ class Videoob(ReplApplication):
|
|||
|
||||
video = self.get_object(_id, 'get_video', ['url'])
|
||||
if not video:
|
||||
print >>sys.stderr, 'Video not found: %s' % _id
|
||||
print >>sys.stderr, 'Video not found: %s' % _id
|
||||
return 3
|
||||
if not video.url:
|
||||
print >>sys.stderr, 'Error: the direct URL is not available.'
|
||||
|
|
@ -179,7 +178,7 @@ class Videoob(ReplApplication):
|
|||
|
||||
video = self.get_object(_id, 'get_video')
|
||||
if not video:
|
||||
print >>sys.stderr, 'Video not found: %s' % _id
|
||||
print >>sys.stderr, 'Video not found: %s' % _id
|
||||
return 3
|
||||
self.format(video)
|
||||
self.flush()
|
||||
|
|
@ -207,22 +206,17 @@ class Videoob(ReplApplication):
|
|||
else:
|
||||
print "on" if self.nsfw else "off"
|
||||
|
||||
def do_search(self, pattern=None):
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search [PATTERN]
|
||||
search PATTERN
|
||||
|
||||
Search for videos matching a PATTERN.
|
||||
|
||||
If PATTERN is not given, this command will search for the latest videos.
|
||||
"""
|
||||
if len(self.enabled_backends) == 0:
|
||||
if self.interactive:
|
||||
print >>sys.stderr, 'No backend loaded. Please use the "backends" command.'
|
||||
else:
|
||||
print >>sys.stderr, 'No backend loaded.'
|
||||
return 1
|
||||
if not pattern:
|
||||
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('search', short=True)
|
||||
return 2
|
||||
|
||||
self.set_formatter_header(u'Search pattern: %s' % pattern if pattern else u'Latest videos')
|
||||
self.set_formatter_header(u'Search pattern: %s' % pattern)
|
||||
self.change_path([u'search'])
|
||||
for backend, video in self.do('search_videos', pattern=pattern, nsfw=self.nsfw,
|
||||
max_results=self.options.count):
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ class BaseGallery(CapBaseObject):
|
|||
self.add_field('description', basestring)
|
||||
self.add_field('cardinality', int)
|
||||
self.add_field('date', datetime, date)
|
||||
self.add_field('rating', (int,long,float), rating)
|
||||
self.add_field('rating_max', (int,long,float), rating_max)
|
||||
self.add_field('rating', (int, long, float), rating)
|
||||
self.add_field('rating_max', (int, long, float), rating_max)
|
||||
self.add_field('thumbnail', Thumbnail, thumbnail)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -55,13 +55,14 @@ class BaseGallery(CapBaseObject):
|
|||
def iter_image(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class BaseImage(CapBaseObject):
|
||||
def __init__(self, _id, index=None, thumbnail=NotLoaded, url=NotLoaded,
|
||||
ext=NotLoaded, gallery=None):
|
||||
|
||||
CapBaseObject.__init__(self, unicode(_id))
|
||||
|
||||
self.add_field('index', int, index) # usually page number
|
||||
self.add_field('index', int, index) # usually page number
|
||||
self.add_field('thumbnail', Thumbnail, thumbnail)
|
||||
self.add_field('url', basestring, url)
|
||||
self.add_field('ext', basestring, ext)
|
||||
|
|
@ -77,6 +78,7 @@ class BaseImage(CapBaseObject):
|
|||
def __iscomplete__(self):
|
||||
return self.data is not NotLoaded
|
||||
|
||||
|
||||
class ICapGallery(IBaseCap):
|
||||
"""
|
||||
This capability represents the ability for a website backend to provide videos.
|
||||
|
|
@ -86,10 +88,9 @@ class ICapGallery(IBaseCap):
|
|||
SEARCH_VIEWS,
|
||||
SEARCH_DATE) = range(4)
|
||||
|
||||
def search_gallery(self, pattern=None, sortby=SEARCH_RELEVANCE, max_results=None):
|
||||
def search_gallery(self, pattern, sortby=SEARCH_RELEVANCE, max_results=None):
|
||||
"""
|
||||
Iter results of a search on a pattern. Note that if pattern is None,
|
||||
it get the latest videos.
|
||||
Iter results of a search on a pattern.
|
||||
|
||||
@param pattern [str] pattern to search on
|
||||
@param sortby [enum] sort by...
|
||||
|
|
|
|||
|
|
@ -66,10 +66,9 @@ class ICapVideo(IBaseCap):
|
|||
SEARCH_VIEWS,
|
||||
SEARCH_DATE) = range(4)
|
||||
|
||||
def search_videos(self, pattern=None, sortby=SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||
def search_videos(self, pattern, sortby=SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||
"""
|
||||
Iter results of a search on a pattern. Note that if pattern is None,
|
||||
it get the latest videos.
|
||||
Iter results of a search on a pattern.
|
||||
|
||||
@param pattern [str] pattern to search on
|
||||
@param sortby [enum] sort by...
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue