]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/downloader/hls.py
Update changelog.
[youtubedl] / youtube_dl / downloader / hls.py
1 import os
2 import subprocess
3
4 from .common import FileDownloader
5 from ..utils import (
6 encodeFilename,
7 )
8
9
10 class HlsFD(FileDownloader):
11 def real_download(self, filename, info_dict):
12 url = info_dict['url']
13 self.report_destination(filename)
14 tmpfilename = self.temp_name(filename)
15
16 args = ['-y', '-i', url, '-f', 'mp4', '-c', 'copy',
17 '-bsf:a', 'aac_adtstoasc', tmpfilename]
18
19 for program in ['avconv', 'ffmpeg']:
20 try:
21 subprocess.call([program, '-version'], stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
22 break
23 except (OSError, IOError):
24 pass
25 else:
26 self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found')
27 cmd = [program] + args
28
29 retval = subprocess.call(cmd)
30 if retval == 0:
31 fsize = os.path.getsize(encodeFilename(tmpfilename))
32 self.to_screen(u'\r[%s] %s bytes' % (cmd[0], fsize))
33 self.try_rename(tmpfilename, filename)
34 self._hook_progress({
35 'downloaded_bytes': fsize,
36 'total_bytes': fsize,
37 'filename': filename,
38 'status': 'finished',
39 })
40 return True
41 else:
42 self.to_stderr(u"\n")
43 self.report_error(u'ffmpeg exited with code %d' % retval)
44 return False