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.

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