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.

45 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. retval = subprocess.call(args)
  25. if retval == 0:
  26. fsize = os.path.getsize(encodeFilename(tmpfilename))
  27. self.to_screen('\r[%s] %s bytes' % (args[0], fsize))
  28. self.try_rename(tmpfilename, filename)
  29. self._hook_progress({
  30. 'downloaded_bytes': fsize,
  31. 'total_bytes': fsize,
  32. 'filename': filename,
  33. 'status': 'finished',
  34. })
  35. return True
  36. else:
  37. self.to_stderr('\n')
  38. self.report_error('%s exited with code %d' % (args[0], retval))
  39. return False