mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 02:48:38 -04:00
Renaming VTT files on video download if there are extra characters in the name.
This commit is contained in:
parent
ef32e8b42d
commit
1cf402821c
2 changed files with 12 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue