new ReplApplication base class

This commit is contained in:
Christophe Benz 2010-08-18 20:30:51 +02:00 committed by Romain Bignon
commit ab4a427586
8 changed files with 978 additions and 41 deletions

View file

@ -17,39 +17,54 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import logging
from weboob.capabilities.video import ICapVideo
from weboob.tools.application.console import ConsoleApplication
from weboob.tools.application.repl import ReplApplication
__all__ = ['Videoob']
class Videoob(ConsoleApplication):
class Videoob(ReplApplication):
APPNAME = 'videoob'
VERSION = '0.1'
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz, Romain Bignon'
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz, Romain Bignon, John Obbele'
def load_default_backends(self):
self.load_backends(caps=ICapVideo)
def add_application_options(self, group):
group.add_option('--nsfw', action='store_true', help='enable non-suitable for work videos')
def main(self, argv):
def handle_application_options(self):
if self.options.backends:
self.options.nsfw = True
return self.process_command(*argv[1:])
@ConsoleApplication.command('Get information about a video (accepts ID or URL)')
def command_info(self, _id):
def do_info(self, _id):
"""
info ID
Get information about a video.
"""
if not _id:
logging.error(u'This command takes an argument: %s' % self.get_command_help('info', short=True))
return
_id, backend_name = self.parse_id(_id)
names = (backend_name,) if backend_name is not None else None
self.load_backends(ICapVideo, names=names)
for backend, video in self.do('get_video', _id):
if video is None:
continue
self.format(video)
def do_search(self, pattern=None):
"""
search [PATTERN]
@ConsoleApplication.command('Search for videos')
def command_search(self, pattern=None):
self.load_backends(ICapVideo)
Search for videos matching a PATTERN.
If PATTERN is not given, this command will search for the latest videos.
"""
self.set_formatter_header(u'Search pattern: %s' % pattern if pattern else u'Latest videos')
for backend, video in self.do('iter_search_results', pattern=pattern, nsfw=self.options.nsfw,
max_results=self.options.count):