load only selected backends instead of store a list and iter on

This commit is contained in:
Romain Bignon 2010-04-20 09:23:35 +02:00
commit 84f4b18068

View file

@ -29,21 +29,16 @@ class Videoob(ConsoleApplication):
parser.add_option('-b', '--backends', help='what backend(s) to enable (comma separated)') parser.add_option('-b', '--backends', help='what backend(s) to enable (comma separated)')
def main(self, argv): def main(self, argv):
self.weboob.load_modules(ICapVideoProvider) names = None
self.enabled_backends = None
if self.options.backends: if self.options.backends:
self.enabled_backends = self.options.backends.split(',') names = self.options.backends.split(',')
return self.process_command(*argv[1:])
def iter_enabled_backends(self): self.weboob.load_modules(ICapVideoProvider, names=names)
for backend in self.weboob.iter_backends(ICapVideoProvider): return self.process_command(*argv[1:])
if self.enabled_backends is not None and backend.NAME not in self.enabled_backends:
continue
yield backend
@ConsoleApplication.command('Get video information') @ConsoleApplication.command('Get video information')
def command_info(self, _id): def command_info(self, _id):
for backend in self.iter_enabled_backends(): for backend in self.weboob.iter_backends():
video = backend.get_video(_id) video = backend.get_video(_id)
if video is None: if video is None:
continue continue
@ -68,19 +63,19 @@ class Videoob(ConsoleApplication):
else: else:
print u'| %-76s |' % 'Last videos' print u'| %-76s |' % 'Last videos'
print u"+------------.-----------------------------------------------------------------'" print u"+------------.-----------------------------------------------------------------'"
for backend in self.iter_enabled_backends(): for backend in self.weboob.iter_backends():
try: try:
iterator = backend.iter_search_results(pattern) iterator = backend.iter_search_results(pattern)
except NotImplementedError: except NotImplementedError:
continue continue
else: else:
for video in iterator: for video in iterator:
print u"| %10d | %-63s |" % (video.id, video.title) print u"| %10s | %-63s |" % (video.id, video.title)
print u"'--------------'---------------------------------------------------------------'" print u"'--------------'---------------------------------------------------------------'"
@ConsoleApplication.command('Get video file URL from page URL') @ConsoleApplication.command('Get video file URL from page URL')
def command_file_url(self, url): def command_file_url(self, url):
for backend in self.iter_enabled_backends(): for backend in self.weboob.iter_backends():
video = backend.get_video(url) video = backend.get_video(url)
if video: if video:
print video.url print video.url