diff options
Diffstat (limited to 'yt_dlp/postprocessor')
-rw-r--r-- | yt_dlp/postprocessor/embedthumbnail.py | 7 | ||||
-rw-r--r-- | yt_dlp/postprocessor/ffmpeg.py | 17 | ||||
-rw-r--r-- | yt_dlp/postprocessor/movefilesafterdownload.py | 9 |
3 files changed, 18 insertions, 15 deletions
diff --git a/yt_dlp/postprocessor/embedthumbnail.py b/yt_dlp/postprocessor/embedthumbnail.py index 82e7e2004..7f759cc30 100644 --- a/yt_dlp/postprocessor/embedthumbnail.py +++ b/yt_dlp/postprocessor/embedthumbnail.py @@ -47,7 +47,7 @@ class EmbedThumbnailPP(FFmpegPostProcessor): self.to_screen('There aren\'t any thumbnails to embed') return [], info - original_thumbnail = thumbnail_filename = info['thumbnails'][-1]['filename'] + initial_thumbnail = original_thumbnail = thumbnail_filename = info['thumbnails'][-1]['filepath'] if not os.path.exists(encodeFilename(thumbnail_filename)): self.report_warning('Skipping embedding the thumbnail because the file is missing.') @@ -65,6 +65,8 @@ class EmbedThumbnailPP(FFmpegPostProcessor): if thumbnail_ext != 'webp' and is_webp(thumbnail_filename): self.to_screen('Correcting extension to webp and escaping path for thumbnail "%s"' % thumbnail_filename) thumbnail_webp_filename = replace_extension(thumbnail_filename, 'webp') + if os.path.exists(thumbnail_webp_filename): + os.remove(thumbnail_webp_filename) os.rename(encodeFilename(thumbnail_filename), encodeFilename(thumbnail_webp_filename)) original_thumbnail = thumbnail_filename = thumbnail_webp_filename thumbnail_ext = 'webp' @@ -194,7 +196,8 @@ class EmbedThumbnailPP(FFmpegPostProcessor): files_to_delete = [thumbnail_filename] if self._already_have_thumbnail: info['__files_to_move'][original_thumbnail] = replace_extension( - info['__thumbnail_filename'], os.path.splitext(original_thumbnail)[1][1:]) + info['__files_to_move'][initial_thumbnail], + os.path.splitext(original_thumbnail)[1][1:]) if original_thumbnail == thumbnail_filename: files_to_delete = [] elif original_thumbnail != thumbnail_filename: diff --git a/yt_dlp/postprocessor/ffmpeg.py b/yt_dlp/postprocessor/ffmpeg.py index 7d0452dbc..dd07e7c18 100644 --- a/yt_dlp/postprocessor/ffmpeg.py +++ b/yt_dlp/postprocessor/ffmpeg.py @@ -486,7 +486,7 @@ class FFmpegEmbedSubtitlePP(FFmpegPostProcessor): self.report_warning('JSON subtitles cannot be embedded') elif ext != 'webm' or ext == 'webm' and sub_ext == 'vtt': sub_langs.append(lang) - sub_filenames.append(subtitles_filename(filename, lang, sub_ext, ext)) + sub_filenames.append(sub_info['filepath']) else: if not webm_vtt_warn and ext == 'webm' and sub_ext != 'vtt': webm_vtt_warn = True @@ -732,9 +732,9 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor): 'You have requested to convert json subtitles into another format, ' 'which is currently not possible') continue - old_file = subtitles_filename(filename, lang, ext, info.get('ext')) + old_file = sub['filepath'] sub_filenames.append(old_file) - new_file = subtitles_filename(filename, lang, new_ext, info.get('ext')) + new_file = replace_extension(old_file, new_ext) if ext in ('dfxp', 'ttml', 'tt'): self.report_warning( @@ -742,7 +742,7 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor): 'which results in style information loss') dfxp_file = old_file - srt_file = subtitles_filename(filename, lang, 'srt', info.get('ext')) + srt_file = replace_extension(old_file, 'srt') with open(dfxp_file, 'rb') as f: srt_data = dfxp2srt(f.read()) @@ -753,7 +753,8 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor): subs[lang] = { 'ext': 'srt', - 'data': srt_data + 'data': srt_data, + 'filepath': srt_file, } if new_ext == 'srt': @@ -767,8 +768,12 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor): subs[lang] = { 'ext': new_ext, 'data': f.read(), + 'filepath': new_file, } + info['__files_to_move'][new_file] = replace_extension( + info['__files_to_move'][old_file], new_ext) + return sub_filenames, info @@ -789,7 +794,7 @@ class FFmpegSplitChaptersPP(FFmpegPostProcessor): if not self._downloader._ensure_dir_exists(encodeFilename(destination)): return - chapter['_filename'] = destination + chapter['filepath'] = destination self.to_screen('Chapter %03d; Destination: %s' % (number, destination)) return ( destination, diff --git a/yt_dlp/postprocessor/movefilesafterdownload.py b/yt_dlp/postprocessor/movefilesafterdownload.py index fa61317ed..0ab7744ca 100644 --- a/yt_dlp/postprocessor/movefilesafterdownload.py +++ b/yt_dlp/postprocessor/movefilesafterdownload.py @@ -13,10 +13,6 @@ from ..utils import ( class MoveFilesAfterDownloadPP(PostProcessor): - def __init__(self, downloader, files_to_move): - PostProcessor.__init__(self, downloader) - self.files_to_move = files_to_move - @classmethod def pp_key(cls): return 'MoveFiles' @@ -25,11 +21,10 @@ class MoveFilesAfterDownloadPP(PostProcessor): dl_path, dl_name = os.path.split(encodeFilename(info['filepath'])) finaldir = info.get('__finaldir', dl_path) finalpath = os.path.join(finaldir, dl_name) - self.files_to_move.update(info['__files_to_move']) - self.files_to_move[info['filepath']] = decodeFilename(finalpath) + info['__files_to_move'][info['filepath']] = decodeFilename(finalpath) make_newfilename = lambda old: decodeFilename(os.path.join(finaldir, os.path.basename(encodeFilename(old)))) - for oldfile, newfile in self.files_to_move.items(): + for oldfile, newfile in info['__files_to_move'].items(): if not newfile: newfile = make_newfilename(oldfile) if os.path.abspath(encodeFilename(oldfile)) == os.path.abspath(encodeFilename(newfile)): |