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.

46 lines
1.5 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 = [
  13. '-y', '-i', url, '-f', 'mp4', '-c', 'copy',
  14. '-bsf:a', 'aac_adtstoasc',
  15. encodeFilename(tmpfilename, for_subprocess=True)]
  16. for program in ['avconv', 'ffmpeg']:
  17. try:
  18. subprocess.call([program, '-version'], stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
  19. break
  20. except (OSError, IOError):
  21. pass
  22. else:
  23. self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found')
  24. cmd = [program] + args
  25. retval = subprocess.call(cmd)
  26. if retval == 0:
  27. fsize = os.path.getsize(encodeFilename(tmpfilename))
  28. self.to_screen(u'\r[%s] %s bytes' % (cmd[0], fsize))
  29. self.try_rename(tmpfilename, filename)
  30. self._hook_progress({
  31. 'downloaded_bytes': fsize,
  32. 'total_bytes': fsize,
  33. 'filename': filename,
  34. 'status': 'finished',
  35. })
  36. return True
  37. else:
  38. self.to_stderr(u"\n")
  39. self.report_error(u'ffmpeg exited with code %d' % retval)
  40. return False