enable backends with CLI option

This commit is contained in:
Christophe Benz 2010-04-20 03:05:31 +02:00
commit 44b57a775d

View file

@ -25,16 +25,27 @@ class Videoob(ConsoleApplication):
APPNAME = 'videoob'
CONFIG = {}
def configure_parser(self, parser):
parser.add_option('-b', '--backends', help='what backend(s) to enable (comma separated)')
def main(self, argv):
self.weboob.load_modules(ICapVideoProvider)
self.enabled_backends = None
if self.options.backends:
self.enabled_backends = self.options.backends.split(',')
return self.process_command(*argv[1:])
def iter_enabled_backends(self):
for backend in self.weboob.iter_backends(ICapVideoProvider):
if self.enabled_backends is not None and backend.NAME not in self.enabled_backends:
continue
yield backend
@ConsoleApplication.command('Get video information')
def command_info(self, _id):
for backend in self.weboob.iter_backends(ICapVideoProvider):
try:
video = backend.get_video(_id)
except NotImplementedError:
for backend in self.iter_enabled_backends():
video = backend.get_video(_id)
if video is None:
continue
print u'.------------------------------------------------------------------------------.'
print u'| %-76s |' % (u'%s: %s' % (backend.name, video.title))
@ -57,7 +68,7 @@ class Videoob(ConsoleApplication):
else:
print u'| %-76s |' % 'Last videos'
print u"+------------.-----------------------------------------------------------------'"
for backend in self.weboob.iter_backends():
for backend in self.iter_enabled_backends():
try:
iterator = backend.iter_search_results(pattern)
except NotImplementedError:
@ -69,16 +80,8 @@ class Videoob(ConsoleApplication):
@ConsoleApplication.command('Get video file URL from page URL')
def command_file_url(self, url):
for backend in self.weboob.iter_backends(ICapVideoProvider):
video_url = backend.get_video_url(url)
if video_url:
print video_url
break
@ConsoleApplication.command('Get video title from page URL')
def command_title(self, url):
for backend in self.weboob.iter_backends(ICapVideoProvider):
video_title = backend.get_video_title(url)
if video_title:
print video_title
for backend in self.iter_enabled_backends():
video = backend.get_video(url)
if video:
print video.url
break