From 4abc9041bf2cce6005ae115402ce1e16a00b480d Mon Sep 17 00:00:00 2001
From: Pierre Mdawar
Date: Thu, 3 Jan 2019 14:58:49 +0200
Subject: [PATCH] [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