From 7e73a3e5c18e24d5c27c851cc69cf961a1690ad4 Mon Sep 17 00:00:00 2001
From: Pierre Mdawar
Date: Thu, 3 Jan 2019 14:57:54 +0200
Subject: [PATCH 1/4] [ffmpeg] convert the video even if in the same downloaded
format if postprocessor args are provided
---
youtube_dl/postprocessor/ffmpeg.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py
index 757b496a1..8acb2872a 100644
--- a/youtube_dl/postprocessor/ffmpeg.py
+++ b/youtube_dl/postprocessor/ffmpeg.py
@@ -325,7 +325,8 @@ class FFmpegVideoConvertorPP(FFmpegPostProcessor):
def run(self, information):
path = information['filepath']
- if information['ext'] == self._preferedformat:
+ # if the ext is the same and there are no additional postprocessor args
+ if information['ext'] == self._preferedformat and not self._configuration_args():
self._downloader.to_screen('[ffmpeg] Not converting video file %s - already is in target format %s' % (path, self._preferedformat))
return [], information
options = []
From 4abc9041bf2cce6005ae115402ce1e16a00b480d Mon Sep 17 00:00:00 2001
From: Pierre Mdawar
Date: Thu, 3 Jan 2019 14:58:49 +0200
Subject: [PATCH 2/4] [YoutubeDL] prevent deleting the processed file if it's
the same file
---
youtube_dl/YoutubeDL.py | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index 4493fd0e1..3821cea2b 100755
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -2050,11 +2050,13 @@ class YoutubeDL(object):
self.report_error(e.msg)
if files_to_delete and not self.params.get('keepvideo', False):
for old_filename in files_to_delete:
- self.to_screen('Deleting original file %s (pass -k to keep)' % old_filename)
- try:
- os.remove(encodeFilename(old_filename))
- except (IOError, OSError):
- self.report_warning('Unable to remove downloaded original file')
+ # don't delete the processed file if it happens to be in the same format
+ if old_filename != info['filepath']:
+ self.to_screen('Deleting original file %s (pass -k to keep)' % old_filename)
+ try:
+ os.remove(encodeFilename(old_filename))
+ except (IOError, OSError):
+ self.report_warning('Unable to remove downloaded original file')
def _make_archive_id(self, info_dict):
# Future-proof against any change in case
From b3152c00d6b319773489dad9aac571bba25fefc0 Mon Sep 17 00:00:00 2001
From: Pierre Mdawar
Date: Thu, 3 Jan 2019 15:48:46 +0200
Subject: [PATCH 3/4] [tests] fix test, the returned path should be the new
path
---
test/test_YoutubeDL.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py
index f0f5a8470..59a6f3dfb 100644
--- a/test/test_YoutubeDL.py
+++ b/test/test_YoutubeDL.py
@@ -605,7 +605,9 @@ class TestYoutubeDL(unittest.TestCase):
def run(self, info):
with open(audiofile, 'wt') as f:
f.write('EXAMPLE')
- return [info['filepath']], info
+ old_file = info['filepath']
+ info['filepath'] = audiofile
+ return [old_file], info
def run_pp(params, PP):
with open(filename, 'wt') as f:
From 61fcc9b7eb6dd2fabd818ac3e6801299a4811926 Mon Sep 17 00:00:00 2001
From: Pierre Mdawar
Date: Thu, 3 Jan 2019 16:16:17 +0200
Subject: [PATCH 4/4] [tests] added test for not deleting the file if the same
file is processed
---
test/test_YoutubeDL.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py
index 59a6f3dfb..c5c81067f 100644
--- a/test/test_YoutubeDL.py
+++ b/test/test_YoutubeDL.py
@@ -627,6 +627,16 @@ class TestYoutubeDL(unittest.TestCase):
self.assertTrue(os.path.exists(audiofile), '%s doesn\'t exist' % audiofile)
os.unlink(audiofile)
+ class SameFilePP(PostProcessor):
+ def run(self, info):
+ with open(info['filepath'], 'wt') as f:
+ f.write('EXAMPLE')
+ return [info['filepath']], info
+
+ run_pp({'keepvideo': False}, SameFilePP)
+ self.assertTrue(os.path.exists(filename), '%s doesn\'t exist' % filename)
+ os.unlink(filename)
+
class ModifierPP(PostProcessor):
def run(self, info):
with open(info['filepath'], 'wt') as f: