renamed VideoPlayer to MediaPlayer
This commit is contained in:
parent
f51bd5b7d4
commit
a9f6ec93aa
2 changed files with 28 additions and 31 deletions
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue