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.

44 lines
1.4 KiB

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