diff --git a/src/ytdl_sub/plugins/subtitles.py b/src/ytdl_sub/plugins/subtitles.py index de98f888..0ea85244 100644 --- a/src/ytdl_sub/plugins/subtitles.py +++ b/src/ytdl_sub/plugins/subtitles.py @@ -1,3 +1,4 @@ +from pathlib import Path from typing import Dict from typing import List from typing import Optional @@ -7,6 +8,7 @@ from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder from ytdl_sub.entries.entry import Entry from ytdl_sub.plugins.plugin import Plugin from ytdl_sub.plugins.plugin import PluginOptions +from ytdl_sub.utils.file_handler import FileHandler from ytdl_sub.utils.file_handler import FileMetadata from ytdl_sub.utils.logger import Logger from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator @@ -206,4 +208,11 @@ class SubtitlesPlugin(Plugin[SubtitleOptions]): entry=entry, ) + # Delete any possible original subtitle files before conversion + for possible_ext in SUBTITLE_EXTENSIONS: + possible_subs_file = ( + Path(self.working_directory) / f"{entry.uid}.{lang}.{possible_ext}" + ) + FileHandler.delete(possible_subs_file) + return file_metadata diff --git a/src/ytdl_sub/utils/file_handler.py b/src/ytdl_sub/utils/file_handler.py index 2b8f1ced..ddabadd4 100644 --- a/src/ytdl_sub/utils/file_handler.py +++ b/src/ytdl_sub/utils/file_handler.py @@ -414,6 +414,9 @@ class FileHandler: self.copy(src_file_path=source_file_path, dst_file_path=output_file_path) else: self.move(src_file_path=source_file_path, dst_file_path=output_file_path) + # Simulate the file being moved during dry run by deleting it + elif self.dry_run and not copy_file: + FileHandler.delete(source_file_path) def delete_file_from_output_directory(self, file_name: str): """ diff --git a/src/ytdl_sub/utils/thumbnail.py b/src/ytdl_sub/utils/thumbnail.py index 25a4b9f5..2b3ee102 100644 --- a/src/ytdl_sub/utils/thumbnail.py +++ b/src/ytdl_sub/utils/thumbnail.py @@ -5,6 +5,7 @@ from urllib.request import urlopen from ytdl_sub.entries.entry import Entry from ytdl_sub.utils.ffmpeg import FFMPEG +from ytdl_sub.utils.file_handler import FileHandler from ytdl_sub.utils.retry import retry @@ -42,6 +43,7 @@ def convert_download_thumbnail(entry: Entry, error_if_not_found: bool = True) -> if not download_thumbnail_path == download_thumbnail_path_as_jpg: FFMPEG.run(["-bitexact", "-i", download_thumbnail_path, download_thumbnail_path_as_jpg]) + FileHandler.delete(download_thumbnail_path) @retry(times=5, exceptions=(Exception,))