[ie/twitter:spaces] Support video spaces (#10789)
[yt-dlp3.git] / yt_dlp / downloader / rtsp.py
blobe89269fed929b6340c386e42f379f0f9f91e1700
1 import os
2 import subprocess
4 from .common import FileDownloader
5 from ..utils import check_executable, encodeFilename
8 class RtspFD(FileDownloader):
9 def real_download(self, filename, info_dict):
10 url = info_dict['url']
11 self.report_destination(filename)
12 tmpfilename = self.temp_name(filename)
14 if check_executable('mplayer', ['-h']):
15 args = [
16 'mplayer', '-really-quiet', '-vo', 'null', '-vc', 'dummy',
17 '-dumpstream', '-dumpfile', tmpfilename, url]
18 elif check_executable('mpv', ['-h']):
19 args = [
20 'mpv', '-really-quiet', '--vo=null', '--stream-dump=' + tmpfilename, url]
21 else:
22 self.report_error('MMS or RTSP download detected but neither "mplayer" nor "mpv" could be run. Please install one')
23 return False
25 self._debug_cmd(args)
27 retval = subprocess.call(args)
28 if retval == 0:
29 fsize = os.path.getsize(encodeFilename(tmpfilename))
30 self.to_screen(f'\r[{args[0]}] {fsize} bytes')
31 self.try_rename(tmpfilename, filename)
32 self._hook_progress({
33 'downloaded_bytes': fsize,
34 'total_bytes': fsize,
35 'filename': filename,
36 'status': 'finished',
37 }, info_dict)
38 return True
39 else:
40 self.to_stderr('\n')
41 self.report_error('%s exited with code %d' % (args[0], retval))
42 return False