Renaming VTT files on video download if there are extra characters in the name.
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

This commit is contained in:
Roland 2026-03-09 15:00:24 -06:00
parent ef32e8b42d
commit 1cf402821c
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 12 additions and 4 deletions

View file

@ -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

View file

@ -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,