X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fdownloader%2Fhls.py;h=aa58b52abb5998ba8879e6eba3a1d974484467e2;hb=121c09c7be1ac2944f3432122104c1952bfd1f04;hp=56cce281130ee4d8374e4f44582cf61cc8e073f5;hpb=c6e90caaa661e8368f099055c609c7c121bbbc2b;p=youtube-dl diff --git a/youtube_dl/downloader/hls.py b/youtube_dl/downloader/hls.py index 56cce2811..aa58b52ab 100644 --- a/youtube_dl/downloader/hls.py +++ b/youtube_dl/downloader/hls.py @@ -4,11 +4,13 @@ import os import re import subprocess +from ..postprocessor.ffmpeg import FFmpegPostProcessor from .common import FileDownloader -from ..utils import ( +from ..compat import ( compat_urlparse, compat_urllib_request, - check_executable, +) +from ..utils import ( encodeFilename, ) @@ -24,18 +26,18 @@ class HlsFD(FileDownloader): '-bsf:a', 'aac_adtstoasc', encodeFilename(tmpfilename, for_subprocess=True)] - for program in ['avconv', 'ffmpeg']: - if check_executable(program, ['-version']): - break - else: - self.report_error(u'm3u8 download detected but ffmpeg or avconv could not be found. Please install one.') + ffpp = FFmpegPostProcessor(downloader=self) + program = ffpp._executable + if program is None: + self.report_error('m3u8 download detected but ffmpeg or avconv could not be found. Please install one.') return False + ffpp.check_version() cmd = [program] + args retval = subprocess.call(cmd) if retval == 0: fsize = os.path.getsize(encodeFilename(tmpfilename)) - self.to_screen(u'\r[%s] %s bytes' % (cmd[0], fsize)) + self.to_screen('\r[%s] %s bytes' % (cmd[0], fsize)) self.try_rename(tmpfilename, filename) self._hook_progress({ 'downloaded_bytes': fsize, @@ -45,8 +47,8 @@ class HlsFD(FileDownloader): }) return True else: - self.to_stderr(u"\n") - self.report_error(u'%s exited with code %d' % (program, retval)) + self.to_stderr('\n') + self.report_error('%s exited with code %d' % (program, retval)) return False @@ -81,16 +83,16 @@ class NativeHlsFD(FileDownloader): '[hlsnative] %s: Downloading segment %d / %d' % (info_dict['id'], i + 1, len(segment_urls))) seg_req = compat_urllib_request.Request(segurl) - if remaining_bytes: + if remaining_bytes is not None: seg_req.add_header('Range', 'bytes=0-%d' % (remaining_bytes - 1)) segment = self.ydl.urlopen(seg_req).read() - if remaining_bytes: + if remaining_bytes is not None: segment = segment[:remaining_bytes] remaining_bytes -= len(segment) outf.write(segment) byte_counter += len(segment) - if remaining_bytes <= 0: + if remaining_bytes is not None and remaining_bytes <= 0: break self._hook_progress({ @@ -101,4 +103,3 @@ class NativeHlsFD(FileDownloader): }) self.try_rename(tmpfilename, filename) return True -