]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/downloader/mplayer.py
debian/watch: Make use of the signing key from upstream.
[youtubedl] / youtube_dl / downloader / mplayer.py
1 import os
2 import subprocess
3
4 from .common import FileDownloader
5 from ..utils import (
6 encodeFilename,
7 )
8
9
10 class MplayerFD(FileDownloader):
11 def real_download(self, filename, info_dict):
12 url = info_dict['url']
13 self.report_destination(filename)
14 tmpfilename = self.temp_name(filename)
15
16 args = ['mplayer', '-really-quiet', '-vo', 'null', '-vc', 'dummy', '-dumpstream', '-dumpfile', tmpfilename, url]
17 # Check for mplayer first
18 try:
19 subprocess.call(['mplayer', '-h'], stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
20 except (OSError, IOError):
21 self.report_error(u'MMS or RTSP download detected but "%s" could not be run' % args[0])
22 return False
23
24 # Download using mplayer.
25 retval = subprocess.call(args)
26 if retval == 0:
27 fsize = os.path.getsize(encodeFilename(tmpfilename))
28 self.to_screen(u'\r[%s] %s bytes' % (args[0], fsize))
29 self.try_rename(tmpfilename, filename)
30 self._hook_progress({
31 'downloaded_bytes': fsize,
32 'total_bytes': fsize,
33 'filename': filename,
34 'status': 'finished',
35 })
36 return True
37 else:
38 self.to_stderr(u"\n")
39 self.report_error(u'mplayer exited with code %d' % retval)
40 return False