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.

39 lines
1.3 KiB

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