From a9f6ec93aa0646494d02efb4e858fe47e360370a Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Fri, 15 Oct 2010 18:29:10 +0200 Subject: [PATCH] renamed VideoPlayer to MediaPlayer --- weboob/applications/videoob/videoob.py | 13 ++---- .../{video_player.py => media_player.py} | 46 +++++++++---------- 2 files changed, 28 insertions(+), 31 deletions(-) rename weboob/tools/application/{video_player.py => media_player.py} (71%) diff --git a/weboob/applications/videoob/videoob.py b/weboob/applications/videoob/videoob.py index 07a6669e..dacc8248 100644 --- a/weboob/applications/videoob/videoob.py +++ b/weboob/applications/videoob/videoob.py @@ -19,7 +19,7 @@ from weboob.capabilities.video import ICapVideo from weboob.capabilities.base import NotLoaded from weboob.tools.application.repl import ReplApplication -from weboob.tools.application.video_player import VideoPlayer +from weboob.tools.application.media_player import MediaPlayer from weboob.tools.application.formatters.iformatter import IFormatter @@ -40,9 +40,9 @@ class VideoListFormatter(IFormatter): self.count += 1 if self.interactive: backend = item['id'].split('@', 1)[1] - result = u'%s(%d) %s (%s)%s\n' % (ReplApplication.BOLD, self.count, item['title'], backend, ReplApplication.NC) + result = u'%s* (%d) %s (%s)%s\n' % (ReplApplication.BOLD, self.count, item['title'], backend, ReplApplication.NC) else: - result = u'%s(%s) %s%s\n' % (ReplApplication.BOLD, item['id'], item['title'], ReplApplication.NC) + result = u'%s* (%s) %s%s\n' % (ReplApplication.BOLD, item['id'], item['title'], ReplApplication.NC) result += ' %s' % item['duration'] if item['author'] is not NotLoaded: result += ' - %s' % item['author'] @@ -68,7 +68,7 @@ class Videoob(ReplApplication): def __init__(self, *args, **kwargs): ReplApplication.__init__(self, *args, **kwargs) try: - self.player = VideoPlayer() + self.player = MediaPlayer() except OSError: self.player = None @@ -103,7 +103,7 @@ class Videoob(ReplApplication): Play a video with a found player. """ if not _id: - print 'This command takes an argument: %s' % self.get_command_help('info', short=True) + print 'This command takes an argument: %s' % self.get_command_help('play', short=True) return video = self._get_video(_id, ['url']) @@ -111,9 +111,6 @@ class Videoob(ReplApplication): print 'Video not found: ', _id return - backend = self.weboob.get_backend(video.backend) - backend.fillobj(video, ['url']) - if self.player: self.player.play(video) else: diff --git a/weboob/tools/application/video_player.py b/weboob/tools/application/media_player.py similarity index 71% rename from weboob/tools/application/video_player.py rename to weboob/tools/application/media_player.py index b7b510c5..d095b3c2 100644 --- a/weboob/tools/application/video_player.py +++ b/weboob/tools/application/media_player.py @@ -22,15 +22,15 @@ import os from subprocess import Popen, PIPE -__all__ = ['VideoPlayer'] +__all__ = ['MediaPlayer'] -class VideoPlayer(): +class MediaPlayer(): """ - Black magic invoking a video player to this world. + Black magic invoking a media player to this world. Presently, due to strong disturbances in the holidays of the ether - world, the video player used is chosen from a static list of + world, the media player used is chosen from a static list of programs. See PLAYERS for more information. """ @@ -48,49 +48,49 @@ class VideoPlayer(): if self._find_in_path(os.environ['PATH'], player_name): return player_name - def play(self, video): + def play(self, media): """ - Play a video object, using programs from the PLAYERS list. + Play a media object, using programs from the PLAYERS list. This function dispatch calls to either _play_default or _play_rtmp for special rtmp streams using SWF verification. """ - if video.url.find('rtmp') == 0: - self._play_rtmp(video) + if media.url.find('rtmp') == 0: + self._play_rtmp(media) else: - self._play_default(video) + self._play_default(media) - def _play_default(self, video): + def _play_default(self, media): """ - Play video.url with the video player. + Play media.url with the media player. """ player_name = self.get_player_name() - print 'Invoking "%s %s".' % (player_name, video.url) - os.spawnlp(os.P_NOWAIT, player_name, player_name, video.url) + print 'Invoking "%s %s".' % (player_name, media.url) + os.spawnlp(os.P_NOWAIT, player_name, player_name, media.url) - def _play_rtmp(self, video): + def _play_rtmp(self, media): """ - Download data with rtmpdump and pipe them to a video player. + Download data with rtmpdump and pipe them to a media player. You need a working version of rtmpdump installed and the SWF object url in order to comply with SWF verification requests from the server. The last one is retrieved from the non-standard - non-API compliant 'swf_player' attribute of the 'video' object. + non-API compliant 'swf_player' attribute of the 'media' object. """ if not self._find_in_path(os.environ['PATH'], 'rtmpdump'): raise OSError(errno.ENOENT, '"rtmpdump" binary not found') - video_url = video.url + media_url = media.url try: - player_url = video.swf_player - rtmp = 'rtmpdump -r %s --swfVfy %s' % (video_url, player_url) + player_url = media.swf_player + rtmp = 'rtmpdump -r %s --swfVfy %s' % (media_url, player_url) except AttributeError: - logging.warning('Your video object does not have a "swf_player" attribute. SWF verification will be ' - 'disabled and may prevent correct video playback.') + logging.warning('Your media object does not have a "swf_player" attribute. SWF verification will be ' + 'disabled and may prevent correct media playback.') - rtmp = 'rtmpdump -r %s' % video_url + rtmp = 'rtmpdump -r %s' % media_url rtmp += ' --quiet' @@ -101,7 +101,7 @@ class VideoPlayer(): args = stdin_args assert args is not None - print ':: Streaming from %s' % video_url + print ':: Streaming from %s' % media_url print ':: to %s %s' % (player_name, args) p1 = Popen(rtmp.split(), stdout=PIPE) Popen([player_name, args], stdin=p1.stdout, stderr=PIPE)