mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-24 13:46:53 +01:00
YoutubeDL: Make the decision about removing the original file after each postprocessor is run (fixes #2261)
If one of the processors said the file should be kept, it wouldn't pay attention to the response from the following processors. This was wrong if the 'keep_video' option was False, if the first extractor modifies the original file and then we extract its audio we don't want to keep the original video file.
This commit is contained in:
parent
aa24de39aa
commit
f3ff1a3696
@ -1235,14 +1235,15 @@ def post_process(self, filename, ie_info):
|
|||||||
"""Run all the postprocessors on the given file."""
|
"""Run all the postprocessors on the given file."""
|
||||||
info = dict(ie_info)
|
info = dict(ie_info)
|
||||||
info['filepath'] = filename
|
info['filepath'] = filename
|
||||||
keep_video = None
|
|
||||||
pps_chain = []
|
pps_chain = []
|
||||||
if ie_info.get('__postprocessors') is not None:
|
if ie_info.get('__postprocessors') is not None:
|
||||||
pps_chain.extend(ie_info['__postprocessors'])
|
pps_chain.extend(ie_info['__postprocessors'])
|
||||||
pps_chain.extend(self._pps)
|
pps_chain.extend(self._pps)
|
||||||
for pp in pps_chain:
|
for pp in pps_chain:
|
||||||
|
keep_video = None
|
||||||
|
old_filename = info['filepath']
|
||||||
try:
|
try:
|
||||||
keep_video_wish, new_info = pp.run(info)
|
keep_video_wish, info = pp.run(info)
|
||||||
if keep_video_wish is not None:
|
if keep_video_wish is not None:
|
||||||
if keep_video_wish:
|
if keep_video_wish:
|
||||||
keep_video = keep_video_wish
|
keep_video = keep_video_wish
|
||||||
@ -1253,8 +1254,8 @@ def post_process(self, filename, ie_info):
|
|||||||
self.report_error(e.msg)
|
self.report_error(e.msg)
|
||||||
if keep_video is False and not self.params.get('keepvideo', False):
|
if keep_video is False and not self.params.get('keepvideo', False):
|
||||||
try:
|
try:
|
||||||
self.to_screen('Deleting original file %s (pass -k to keep)' % filename)
|
self.to_screen('Deleting original file %s (pass -k to keep)' % old_filename)
|
||||||
os.remove(encodeFilename(filename))
|
os.remove(encodeFilename(old_filename))
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
self.report_warning('Unable to remove downloaded video file')
|
self.report_warning('Unable to remove downloaded video file')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user