You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

  1. from __future__ import unicode_literals
  2. import os
  3. import subprocess
  4. from .common import FileDownloader
  5. from ..utils import (
  6. check_executable,
  7. encodeFilename,
  8. )
  9. class RtspFD(FileDownloader):
  10. def real_download(self, filename, info_dict):
  11. url = info_dict['url']
  12. self.report_destination(filename)
  13. 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 any.')
  23. return False
  24. self._debug_cmd(args)
  25. retval = subprocess.call(args)
  26. if retval == 0:
  27. fsize = os.path.getsize(encodeFilename(tmpfilename))
  28. self.to_screen('\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('\n')
  39. self.report_error('%s exited with code %d' % (args[0], retval))
  40. return False