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 ..compat import compat_subprocess_get_DEVNULL
  6. from ..utils import (
  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. 'mplayer', '-really-quiet', '-vo', 'null', '-vc', 'dummy',
  16. '-dumpstream', '-dumpfile', tmpfilename, url]
  17. # Check for mplayer first
  18. try:
  19. subprocess.call(
  20. ['mplayer', '-h'],
  21. stdout=compat_subprocess_get_DEVNULL(), stderr=subprocess.STDOUT)
  22. except (OSError, IOError):
  23. self.report_error('MMS or RTSP download detected but "%s" could not be run' % args[0])
  24. return False
  25. # Download using mplayer.
  26. retval = subprocess.call(args)
  27. if retval == 0:
  28. fsize = os.path.getsize(encodeFilename(tmpfilename))
  29. self.to_screen('\r[%s] %s bytes' % (args[0], fsize))
  30. self.try_rename(tmpfilename, filename)
  31. self._hook_progress({
  32. 'downloaded_bytes': fsize,
  33. 'total_bytes': fsize,
  34. 'filename': filename,
  35. 'status': 'finished',
  36. })
  37. return True
  38. else:
  39. self.to_stderr('\n')
  40. self.report_error('mplayer exited with code %d' % retval)
  41. return False