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.

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