diff --git a/src/ytdl_sub/entries/entry.py b/src/ytdl_sub/entries/entry.py index 5a90b8b2..08d2285d 100644 --- a/src/ytdl_sub/entries/entry.py +++ b/src/ytdl_sub/entries/entry.py @@ -23,9 +23,11 @@ class Entry(EntryVariables, BaseEntry): This is not reflected in the entry. See if the mkv file exists and return "mkv" if so, otherwise, return the original extension. """ - mkv_file_path = str(Path(self.working_directory()) / f"{self.uid}.mkv") - if os.path.isfile(mkv_file_path): - return "mkv" + for possible_ext in [super().ext, "mkv"]: + file_path = str(Path(self.working_directory()) / f"{self.uid}.{possible_ext}") + if os.path.isfile(file_path): + return possible_ext + return super().ext def get_download_file_name(self) -> str: diff --git a/src/ytdl_sub/plugins/file_convert.py b/src/ytdl_sub/plugins/file_convert.py index e7dfd067..ba08f620 100644 --- a/src/ytdl_sub/plugins/file_convert.py +++ b/src/ytdl_sub/plugins/file_convert.py @@ -116,15 +116,17 @@ class FileConvertPlugin(Plugin[FileConvertOptions]): ------- ffmpeg video remuxing post processing dict """ - return { - "postprocessors": [ - { - "key": "FFmpegVideoRemuxer", - "when": "post_process", - "preferedformat": self.plugin_options.convert_to, - } - ] - } + if self.plugin_options.convert_with == "yt-dlp": + return { + "postprocessors": [ + { + "key": "FFmpegVideoRemuxer", + "when": "post_process", + "preferedformat": self.plugin_options.convert_to, + } + ] + } + return None def modify_entry(self, entry: Entry) -> Optional[Entry]: """ @@ -144,7 +146,10 @@ class FileConvertPlugin(Plugin[FileConvertOptions]): ValidationException User ffmpeg arguments errored """ + # Get original_ext here since there is mkv/yt-dlp shenanigans + original_ext = entry.ext new_ext = self.plugin_options.convert_to + input_video_file_path = entry.get_download_file_path() converted_video_file_path = entry.get_download_file_path().removesuffix(entry.ext) + new_ext @@ -157,9 +162,7 @@ class FileConvertPlugin(Plugin[FileConvertOptions]): raise FileNotDownloadedException("Failed to find the input file") if self.plugin_options.ffmpeg_post_process_args: - tmp_output_file = ( - converted_video_file_path.removesuffix(new_ext) + f".tmp.{new_ext}" - ) + tmp_output_file = converted_video_file_path.removesuffix(new_ext) + f"tmp.{new_ext}" ffmpeg_args_list = self.overrides.apply_formatter( self.plugin_options.ffmpeg_post_process_args ).split() @@ -177,11 +180,13 @@ class FileConvertPlugin(Plugin[FileConvertOptions]): ) FileHandler.move(tmp_output_file, converted_video_file_path) + FileHandler.delete(tmp_output_file) + FileHandler.delete(input_video_file_path) - if entry.ext != new_ext: + if original_ext != new_ext: entry.add_kwargs( { - "__converted_from": entry.ext, + "__converted_from": original_ext, } ) diff --git a/tests/e2e/plugins/test_file_convert.py b/tests/e2e/plugins/test_file_convert.py index f5558ca8..d084b8ce 100644 --- a/tests/e2e/plugins/test_file_convert.py +++ b/tests/e2e/plugins/test_file_convert.py @@ -61,7 +61,7 @@ class TestFileConvert: "file_convert": { "convert_to": "mkv", "convert_with": "ffmpeg", - "ffmpeg_post_process_args": "-vcodec copy -acodec copy -scodec mov_text", + "ffmpeg_post_process_args": "-bitexact -vcodec copy -acodec copy -scodec mov_text", } }, ) diff --git a/tests/expected_transaction_log.py b/tests/expected_transaction_log.py index 0f274970..e214ce14 100644 --- a/tests/expected_transaction_log.py +++ b/tests/expected_transaction_log.py @@ -47,6 +47,8 @@ def assert_transaction_log_matches( # Split, ensure there are the same number of new lines summary_lines: List[str] = summary.split("\n") expected_summary_lines: List[str] = expected_summary.split("\n") + print(summary_lines) + print(expected_summary_lines) assert len(summary_lines) == len( expected_summary_lines ), f"Summary number of lines differ: {len(summary_lines) != len(expected_summary_lines)}" diff --git a/tests/resources/expected_downloads_summaries/plugins/file_convert/output_custom_ffmpeg.json b/tests/resources/expected_downloads_summaries/plugins/file_convert/output_custom_ffmpeg.json index db055d59..0aaca2c2 100644 --- a/tests/resources/expected_downloads_summaries/plugins/file_convert/output_custom_ffmpeg.json +++ b/tests/resources/expected_downloads_summaries/plugins/file_convert/output_custom_ffmpeg.json @@ -1,7 +1,7 @@ { ".ytdl-sub-file_convert_test-download-archive.json": "74813dccf4e9732e49f5dc3c2d66f3be", "Beyond The Guitar/Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3-thumb.jpg": "662fcaadf6e80d63591bac19a5fdffb0", - "Beyond The Guitar/Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.info.json": "29118ff7fad058437325513f60649dc8", - "Beyond The Guitar/Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.mkv": "91b167c199a33cb6b6746506f135741f", + "Beyond The Guitar/Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.info.json": "3022131504a9df5d2fce266fada1ee3b", + "Beyond The Guitar/Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.mkv": "b5f248b560f89f3f2a83fcdcd197d486", "Beyond The Guitar/Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.nfo": "cacf09ab38f9b3085da9c5af516cf22a" } \ No newline at end of file diff --git a/tests/resources/transaction_log_summaries/plugins/file_convert/output_custom_ffmpeg.txt b/tests/resources/transaction_log_summaries/plugins/file_convert/output_custom_ffmpeg.txt index 78664c61..a8f570fb 100644 --- a/tests/resources/transaction_log_summaries/plugins/file_convert/output_custom_ffmpeg.txt +++ b/tests/resources/transaction_log_summaries/plugins/file_convert/output_custom_ffmpeg.txt @@ -6,6 +6,7 @@ Files created: Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3-thumb.jpg Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.info.json Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.mkv + Converted from webm Beyond The Guitar - When you hear Hugh Jackman is returning as Wolverine in Deadpool 3.nfo NFO tags: musicvideo: