X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=youtube_dl%2FPostProcessor.py;h=a04828518b1cd141008f4dbc228ac59cc22cd780;hb=8e241d1a1acd58319178af1cbf7ac6c46edeb04c;hp=af00f80eed35ecb6b6826d01fc22bb58e4ce188f;hpb=9e8056d5a7b6b366874088cd30d23ba4a52d3861;p=youtube-dl.git diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py index af00f80ee..a04828518 100644 --- a/youtube_dl/PostProcessor.py +++ b/youtube_dl/PostProcessor.py @@ -62,13 +62,14 @@ class AudioConversionError(BaseException): self.message = message class FFmpegExtractAudioPP(PostProcessor): - def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, keepvideo=False): + def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, keepvideo=False, nopostoverwrites=False): PostProcessor.__init__(self, downloader) if preferredcodec is None: preferredcodec = 'best' self._preferredcodec = preferredcodec self._preferredquality = preferredquality self._keepvideo = keepvideo + self._nopostoverwrites = nopostoverwrites self._exes = self.detect_executables() @staticmethod @@ -86,14 +87,14 @@ class FFmpegExtractAudioPP(PostProcessor): if not self._exes['ffprobe'] and not self._exes['avprobe']: return None try: cmd = [self._exes['avprobe'] or self._exes['ffprobe'], '-show_streams', '--', encodeFilename(path)] - handle = subprocess.Popen(cmd, stderr=file(os.path.devnull, 'w'), stdout=subprocess.PIPE) + handle = subprocess.Popen(cmd, stderr=compat_subprocess_get_DEVNULL(), stdout=subprocess.PIPE) output = handle.communicate()[0] if handle.wait() != 0: return None except (IOError, OSError): return None audio_codec = None - for line in output.split('\n'): + for line in output.decode('ascii', 'ignore').split('\n'): if line.startswith('codec_name='): audio_codec = line.split('=')[1].strip() elif line.strip() == 'codec_type=audio' and audio_codec is not None: @@ -102,7 +103,7 @@ class FFmpegExtractAudioPP(PostProcessor): def run_ffmpeg(self, path, out_path, codec, more_opts): if not self._exes['ffmpeg'] and not self._exes['avconv']: - raise AudioConversionError('ffmpeg or avconv not found. Please install one.') + raise AudioConversionError('ffmpeg or avconv not found. Please install one.') if codec is None: acodec_opts = [] else: @@ -171,9 +172,12 @@ class FFmpegExtractAudioPP(PostProcessor): prefix, sep, ext = path.rpartition(u'.') # not os.path.splitext, since the latter does not work on unicode in all setups new_path = prefix + sep + extension - self._downloader.to_screen(u'[' + (self._exes['avconv'] and 'avconv' or 'ffmpeg') + '] Destination: ' + new_path) try: - self.run_ffmpeg(path, new_path, acodec, more_opts) + if self._nopostoverwrites and os.path.exists(encodeFilename(new_path)): + self._downloader.to_screen(u'[youtube] Post-process file %s exists, skipping' % new_path) + else: + self._downloader.to_screen(u'[' + (self._exes['avconv'] and 'avconv' or 'ffmpeg') + '] Destination: ' + new_path) + self.run_ffmpeg(path, new_path, acodec, more_opts) except: etype,e,tb = sys.exc_info() if isinstance(e, AudioConversionError):