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.

45 lines
1.4 KiB

  1. import os
  2. import subprocess
  3. from .common import FileDownloader
  4. from ..utils import (
  5. check_executable,
  6. encodeFilename,
  7. )
  8. class HlsFD(FileDownloader):
  9. def real_download(self, filename, info_dict):
  10. url = info_dict['url']
  11. self.report_destination(filename)
  12. tmpfilename = self.temp_name(filename)
  13. args = [
  14. '-y', '-i', url, '-f', 'mp4', '-c', 'copy',
  15. '-bsf:a', 'aac_adtstoasc',
  16. encodeFilename(tmpfilename, for_subprocess=True)]
  17. for program in ['avconv', 'ffmpeg']:
  18. if check_executable(program, ['-version']):
  19. break
  20. else:
  21. self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found. Please install one.')
  22. return False
  23. cmd = [program] + args
  24. retval = subprocess.call(cmd)
  25. if retval == 0:
  26. fsize = os.path.getsize(encodeFilename(tmpfilename))
  27. self.to_screen(u'\r[%s] %s bytes' % (cmd[0], fsize))
  28. self.try_rename(tmpfilename, filename)
  29. self._hook_progress({
  30. 'downloaded_bytes': fsize,
  31. 'total_bytes': fsize,
  32. 'filename': filename,
  33. 'status': 'finished',
  34. })
  35. return True
  36. else:
  37. self.to_stderr(u"\n")
  38. self.report_error(u'%s exited with code %d' % (program, retval))
  39. return False