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. import os
  2. import subprocess
  3. from .common import FileDownloader
  4. from ..utils import (
  5. encodeFilename,
  6. )
  7. class HlsFD(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 = ['-y', '-i', url, '-f', 'mp4', '-c', 'copy',
  13. '-bsf:a', 'aac_adtstoasc', tmpfilename]
  14. for program in ['avconv', 'ffmpeg']:
  15. try:
  16. subprocess.call([program, '-version'], stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
  17. break
  18. except (OSError, IOError):
  19. pass
  20. else:
  21. self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found')
  22. cmd = [program] + args
  23. retval = subprocess.call(cmd)
  24. if retval == 0:
  25. fsize = os.path.getsize(encodeFilename(tmpfilename))
  26. self.to_screen(u'\r[%s] %s bytes' % (cmd[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(u"\n")
  37. self.report_error(u'ffmpeg exited with code %d' % retval)
  38. return False