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.

50 lines
1.6 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 MplayerFD(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. args = []
  15. # Check for mplayer first
  16. if check_executable('mplayer', ['-h']):
  17. args = [
  18. 'mplayer', '-really-quiet', '-vo', 'null', '-vc', 'dummy',
  19. '-dumpstream', '-dumpfile', tmpfilename, url]
  20. # Check for mpv
  21. elif check_executable('mpv', ['-h']):
  22. args = [
  23. 'mpv', '-really-quiet', '--vo=null', '--stream-dump=' + tmpfilename, url]
  24. else:
  25. self.report_error('MMS or RTSP download detected but neither "mplayer" nor "mpv" could be run')
  26. return False
  27. # Download using mplayer.
  28. retval = subprocess.call(args)
  29. if retval == 0:
  30. fsize = os.path.getsize(encodeFilename(tmpfilename))
  31. self.to_screen('\r[%s] %s bytes' % (args[0], fsize))
  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:
  41. self.to_stderr('\n')
  42. self.report_error('mplayer exited with code %d' % retval)
  43. return False