Use class attributes as much as possible for application output

refs #803
This commit is contained in:
Laurent Bachelier 2014-09-03 01:22:18 +02:00
commit c07e23cafc
35 changed files with 228 additions and 260 deletions

View file

@ -20,7 +20,6 @@
import requests
import subprocess
import sys
import os
from weboob.capabilities.video import CapVideo, BaseVideo
@ -77,14 +76,14 @@ class Videoob(ReplApplication):
def download(self, video, dest, default=None):
if not video.url:
print >>sys.stderr, 'Error: the direct URL is not available.'
print >>self.stderr, 'Error: the direct URL is not available.'
return 4
def check_exec(executable):
with open('/dev/null', 'w') as devnull:
process = subprocess.Popen(['which', executable], stdout=devnull)
if process.wait() != 0:
print >>sys.stderr, 'Please install "%s"' % executable
print >>self.stderr, 'Please install "%s"' % executable
return False
return True
@ -147,7 +146,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 >>self.stderr, 'Video not found: %s' % _id
return 3
return self.download(video, dest)
@ -164,7 +163,7 @@ class Videoob(ReplApplication):
Play a video with a found player.
"""
if not line:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('play', short=True)
print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('play', short=True)
return 2
ret = 0
@ -178,10 +177,10 @@ class Videoob(ReplApplication):
def play(self, video, _id):
if not video:
print >>sys.stderr, 'Video not found: %s' % _id
print >>self.stderr, 'Video not found: %s' % _id
return 3
if not video.url:
print >>sys.stderr, 'Error: the direct URL is not available.'
print >>self.stderr, 'Error: the direct URL is not available.'
return 4
try:
player_name = self.config.get('media_player')
@ -205,14 +204,14 @@ class Videoob(ReplApplication):
Get information about a video.
"""
if not line:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True)
print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True)
return 2
self.start_format()
for _id in line.split(' '):
video = self.get_object(_id, 'get_video')
if not video:
print >>sys.stderr, 'Video not found: %s' % _id
print >>self.stderr, 'Video not found: %s' % _id
return 3
self.format(video)
@ -240,11 +239,11 @@ class Videoob(ReplApplication):
"""
if not self.interactive:
print >>sys.stderr, 'This command can be used only in interactive mode.'
print >>self.stderr, 'This command can be used only in interactive mode.'
return 1
if not line:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('playlist')
print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('playlist')
return 2
cmd, args = self.parse_command_args(line, 2, req_n=1)
@ -254,11 +253,11 @@ class Videoob(ReplApplication):
video = self.get_object(_id, 'get_video')
if not video:
print >>sys.stderr, 'Video not found: %s' % _id
print >>self.stderr, 'Video not found: %s' % _id
return 3
if not video.url:
print >>sys.stderr, 'Error: the direct URL is not available.'
print >>self.stderr, 'Error: the direct URL is not available.'
return 4
self.PLAYLIST.append(video)
@ -268,11 +267,11 @@ class Videoob(ReplApplication):
video_to_remove = self.get_object(_id, 'get_video')
if not video_to_remove:
print >>sys.stderr, 'Video not found: %s' % _id
print >>self.stderr, 'Video not found: %s' % _id
return 3
if not video_to_remove.url:
print >>sys.stderr, 'Error: the direct URL is not available.'
print >>self.stderr, 'Error: the direct URL is not available.'
return 4
for video in self.PLAYLIST:
@ -298,7 +297,7 @@ class Videoob(ReplApplication):
for video in self.PLAYLIST:
self.play(video, video.id)
else:
print >>sys.stderr, 'Playlist command only support "add", "remove", "display", "download" and "export" arguments.'
print >>self.stderr, 'Playlist command only support "add", "remove", "display", "download" and "export" arguments.'
return 2
def complete_nsfw(self, text, line, begidx, endidx):
@ -332,7 +331,7 @@ class Videoob(ReplApplication):
Search for videos matching a PATTERN.
"""
if not pattern:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('search', short=True)
print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('search', short=True)
return 2
self.change_path([u'search'])