diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index 6204a1e9..48e91aa2 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -994,14 +994,16 @@ class VideoDownloader(Downloader, ABC): new_files = [] for file in files: suffix = file.name[len(video_stem):] - if suffix.endswith('.vtt'): + if suffix.endswith('.vtt') or suffix.endswith('.srt'): _, normal_suffix = split_path_stem_and_suffix(file.name) if suffix != normal_suffix: # Video captions file has extra characters in the suffix from yt-dlp. # Example: .en-uYU-mmqFLq8.vtt -> .en.vtt - lang, _, suffix = VTT_SUFFIX_PARSER.match(suffix.strip()).groups() - suffix = f'.{lang}.{suffix}' - file = file.rename(video_path.with_suffix(suffix)) + match = VTT_SUFFIX_PARSER.match(suffix.strip()) + if match: + lang, _, suffix = match.groups() + suffix = f'.{lang}.{suffix}' + file = file.rename(video_path.with_suffix(suffix)) new_files.append(file) return new_files diff --git a/modules/videos/test/test_downloader.py b/modules/videos/test/test_downloader.py index 44314245..e1c6c989 100644 --- a/modules/videos/test/test_downloader.py +++ b/modules/videos/test/test_downloader.py @@ -653,6 +653,12 @@ def test_normalize_video_file_names(test_directory, video_download_manager): } assert not vtt.exists() + # VTT suffix that does not match expected pattern is left unchanged. + vtt = test_directory / 'video.unknown_format.vtt' + vtt.touch() + assert set(downloader.normalize_video_file_names(mp4, [mp4, vtt, info_json])) == {mp4, vtt, info_json} + assert vtt.exists() + @pytest.mark.asyncio async def test_channel_downloader_sets_collection_id(test_session, channel_factory, mock_video_extract_info,