2013-09-23 11:59:27 -04:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from .common import FileDownloader
|
|
|
|
from ..utils import (
|
2014-08-27 09:49:07 -04:00
|
|
|
check_executable,
|
2013-09-23 11:59:27 -04:00
|
|
|
encodeFilename,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class HlsFD(FileDownloader):
|
|
|
|
def real_download(self, filename, info_dict):
|
|
|
|
url = info_dict['url']
|
|
|
|
self.report_destination(filename)
|
|
|
|
tmpfilename = self.temp_name(filename)
|
|
|
|
|
2014-03-24 16:23:05 -04:00
|
|
|
args = [
|
|
|
|
'-y', '-i', url, '-f', 'mp4', '-c', 'copy',
|
|
|
|
'-bsf:a', 'aac_adtstoasc',
|
|
|
|
encodeFilename(tmpfilename, for_subprocess=True)]
|
2013-09-23 11:59:27 -04:00
|
|
|
|
|
|
|
for program in ['avconv', 'ffmpeg']:
|
2014-08-27 09:49:07 -04:00
|
|
|
if check_executable(program, ['-version']):
|
2013-09-23 11:59:27 -04:00
|
|
|
break
|
|
|
|
else:
|
2014-06-09 14:23:20 -04:00
|
|
|
self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found. Please install one.')
|
2014-08-27 09:50:03 -04:00
|
|
|
return False
|
2013-09-23 11:59:27 -04:00
|
|
|
cmd = [program] + args
|
|
|
|
|
|
|
|
retval = subprocess.call(cmd)
|
|
|
|
if retval == 0:
|
|
|
|
fsize = os.path.getsize(encodeFilename(tmpfilename))
|
2014-01-08 10:15:20 -05:00
|
|
|
self.to_screen(u'\r[%s] %s bytes' % (cmd[0], fsize))
|
2013-09-23 11:59:27 -04:00
|
|
|
self.try_rename(tmpfilename, filename)
|
|
|
|
self._hook_progress({
|
|
|
|
'downloaded_bytes': fsize,
|
|
|
|
'total_bytes': fsize,
|
|
|
|
'filename': filename,
|
|
|
|
'status': 'finished',
|
|
|
|
})
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
self.to_stderr(u"\n")
|
2014-08-27 09:39:16 -04:00
|
|
|
self.report_error(u'%s exited with code %d' % (program, retval))
|
2013-09-23 11:59:27 -04:00
|
|
|
return False
|