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