rtsp.py 1.5 KB

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