From f0648fc18c91fde0c2db2e52c1cf78fe6bf3bbc4 Mon Sep 17 00:00:00 2001 From: Barbu Paul - Gheorghe Date: Sun, 23 Dec 2012 19:36:48 +0200 Subject: [PATCH 1/4] added the --no-post-overwrites argument --- youtube_dl/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index c7a0bb959..d044797f0 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -343,6 +343,8 @@ def parseOpts(): help='ffmpeg/avconv audio quality specification, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default 5)') postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False, help='keeps the video file on disk after the post-processing; the video is erased by default') + postproc.add_option('--no-post-overwrites', action='store_true', dest='nopostoverwrites', default=False, + help='do not overwrite post-processed files; the post-processed files are overwritten by default') parser.add_option_group(general) @@ -571,7 +573,7 @@ def _real_main(): # PostProcessors if opts.extractaudio: - fd.add_post_processor(FFmpegExtractAudioPP(preferredcodec=opts.audioformat, preferredquality=opts.audioquality, keepvideo=opts.keepvideo)) + fd.add_post_processor(FFmpegExtractAudioPP(preferredcodec=opts.audioformat, preferredquality=opts.audioquality, keepvideo=opts.keepvideo, nopostoverwrites=opts.nopostoverwrites)) # Update version if opts.update_self: From 0c0074328b2b896317bf4e33378fc587f0d3dfe1 Mon Sep 17 00:00:00 2001 From: Barbu Paul - Gheorghe Date: Sun, 23 Dec 2012 19:51:41 +0200 Subject: [PATCH 2/4] modified FFmpegExtractAudioPP to accept whether it should overwrite post-processed files or not --- youtube_dl/PostProcessor.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py index cc7789e3b..e0b071a9c 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 @@ -102,12 +103,16 @@ 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: acodec_opts = ['-acodec', codec] - cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path), '-vn'] + if self._nopostoverwrites: + overwrite_opts = '-n' + else: + overwrite_opts = '-y' + cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], overwrite_opts, '-i', encodeFilename(path), '-vn'] + acodec_opts + more_opts + ['--', encodeFilename(out_path)]) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) From 3e6c3f52a9af9de6c313df542755b93bdc1fd3ab Mon Sep 17 00:00:00 2001 From: Barbu Paul - Gheorghe Date: Sun, 23 Dec 2012 20:20:19 +0200 Subject: [PATCH 3/4] apparently the -n option is available only in ffmpeg --- youtube_dl/PostProcessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py index e0b071a9c..6da24f986 100644 --- a/youtube_dl/PostProcessor.py +++ b/youtube_dl/PostProcessor.py @@ -108,7 +108,7 @@ class FFmpegExtractAudioPP(PostProcessor): acodec_opts = [] else: acodec_opts = ['-acodec', codec] - if self._nopostoverwrites: + if self._nopostoverwrites and self._exes['ffmpeg']: overwrite_opts = '-n' else: overwrite_opts = '-y' From b7298b6e2a41238c3ad1062e1133429c7747cc4c Mon Sep 17 00:00:00 2001 From: Barbu Paul - Gheorghe Date: Mon, 24 Dec 2012 12:18:20 +0200 Subject: [PATCH 4/4] not relying on ffmpeg to do the post-processed file checking, instead doing it directly in youtube-dl --- youtube_dl/PostProcessor.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py index 6da24f986..a04828518 100644 --- a/youtube_dl/PostProcessor.py +++ b/youtube_dl/PostProcessor.py @@ -108,11 +108,7 @@ class FFmpegExtractAudioPP(PostProcessor): acodec_opts = [] else: acodec_opts = ['-acodec', codec] - if self._nopostoverwrites and self._exes['ffmpeg']: - overwrite_opts = '-n' - else: - overwrite_opts = '-y' - cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], overwrite_opts, '-i', encodeFilename(path), '-vn'] + cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path), '-vn'] + acodec_opts + more_opts + ['--', encodeFilename(out_path)]) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -176,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):