]>
Commit | Line | Data |
---|---|---|
80310134 PH |
1 | from __future__ import unicode_literals |
2 | ||
3bc2ddcc JMF |
3 | import os |
4 | import subprocess | |
5 | ||
6 | from .common import FileDownloader | |
7 | from ..utils import ( | |
d26b1317 | 8 | check_executable, |
3bc2ddcc JMF |
9 | encodeFilename, |
10 | ) | |
11 | ||
12 | ||
13 | class MplayerFD(FileDownloader): | |
14 | def real_download(self, filename, info_dict): | |
c25c9918 | 15 | url = info_dict['url'] |
3bc2ddcc JMF |
16 | self.report_destination(filename) |
17 | tmpfilename = self.temp_name(filename) | |
18 | ||
80310134 PH |
19 | args = [ |
20 | 'mplayer', '-really-quiet', '-vo', 'null', '-vc', 'dummy', | |
21 | '-dumpstream', '-dumpfile', tmpfilename, url] | |
3bc2ddcc | 22 | # Check for mplayer first |
d26b1317 | 23 | if not check_executable('mplayer', ['-h']): |
80310134 | 24 | self.report_error('MMS or RTSP download detected but "%s" could not be run' % args[0]) |
3bc2ddcc JMF |
25 | return False |
26 | ||
f89197d7 | 27 | # Download using mplayer. |
3bc2ddcc JMF |
28 | retval = subprocess.call(args) |
29 | if retval == 0: | |
30 | fsize = os.path.getsize(encodeFilename(tmpfilename)) | |
80310134 | 31 | self.to_screen('\r[%s] %s bytes' % (args[0], fsize)) |
3bc2ddcc JMF |
32 | self.try_rename(tmpfilename, filename) |
33 | self._hook_progress({ | |
34 | 'downloaded_bytes': fsize, | |
35 | 'total_bytes': fsize, | |
36 | 'filename': filename, | |
37 | 'status': 'finished', | |
38 | }) | |
39 | return True | |
40 | else: | |
80310134 PH |
41 | self.to_stderr('\n') |
42 | self.report_error('mplayer exited with code %d' % retval) | |
3bc2ddcc | 43 | return False |