]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/downloader/hls.py
debian/watch: Make use of the signing key from upstream.
[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 = [
17 '-y', '-i', url, '-f', 'mp4', '-c', 'copy',
18 '-bsf:a', 'aac_adtstoasc',
19 encodeFilename(tmpfilename, for_subprocess=True)]
20
21 for program in ['avconv', 'ffmpeg']:
22 try:
23 subprocess.call([program, '-version'], stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
24 break
25 except (OSError, IOError):
26 pass
27 else:
28 self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found')
29 cmd = [program] + args
30
31 retval = subprocess.call(cmd)
32 if retval == 0:
33 fsize = os.path.getsize(encodeFilename(tmpfilename))
34 self.to_screen(u'\r[%s] %s bytes' % (cmd[0], fsize))
35 self.try_rename(tmpfilename, filename)
36 self._hook_progress({
37 'downloaded_bytes': fsize,
38 'total_bytes': fsize,
39 'filename': filename,
40 'status': 'finished',
41 })
42 return True
43 else:
44 self.to_stderr(u"\n")
45 self.report_error(u'ffmpeg exited with code %d' % retval)
46 return False