ytdl-sub/tests/e2e/plugins/test_subtitles.py
Jesse Bannon a48efdc84c
[FEATURE] format plugin to set yt-dlp format easier (#714)
Makes setting yt-dlp's `format` field easier by giving it its own documented plugin.

Old:
```
my_format_preset:
  ytdl_options:
    format: "best"
```

New:
```
my_format_preset:
  format: "best"
```

The old method will still work, so do not worry about updating configs ASAP. However, the option is available to save a few lines 😉
2023-09-13 00:02:19 -07:00

97 lines
3.6 KiB
Python

import pytest
from expected_download import assert_expected_downloads
from expected_transaction_log import assert_transaction_log_matches
from ytdl_sub.config.config_file import ConfigFile
from ytdl_sub.subscriptions.subscription import Subscription
@pytest.fixture
def single_video_subs_embed_preset_dict(output_directory):
return {
"preset": "music_video",
"download": "https://www.youtube.com/watch?v=2lAe1cqCOXo",
# override the output directory with our fixture-generated dir
"output_options": {"output_directory": output_directory},
"subtitles": {
"embed_subtitles": True,
"languages": ["en", "de"],
"allow_auto_generated_subtitles": True,
},
"format": "worst[ext=mp4]", # download the worst format so it is fast
"overrides": {"artist": "JMC"},
}
@pytest.fixture
def test_single_video_subs_embed_and_file_preset_dict(single_video_subs_embed_preset_dict):
single_video_subs_embed_preset_dict["subtitles"][
"subtitles_name"
] = "{music_video_name}.{lang}.{subtitles_ext}"
return single_video_subs_embed_preset_dict
class TestSubtitles:
def test_subtitle_lang_variable_partial_validates(self, music_video_config):
music_video_config_dict = music_video_config.as_dict()
music_video_config_dict["presets"]["music_video"]["subtitles"] = {
"embed_subtitles": False,
"languages": ["en", "de"],
"allow_auto_generated_subtitles": True,
"subtitles_name": "{episode_file_path}.{lang}.{subtitles_ext}",
"subtitles_type": "srt",
}
_ = ConfigFile.from_dict(music_video_config_dict)
@pytest.mark.parametrize("dry_run", [True, False])
def test_subtitles_embedded(
self,
music_video_config,
single_video_subs_embed_preset_dict,
output_directory,
dry_run,
):
subscription = Subscription.from_dict(
config=music_video_config,
preset_name="subtitles_embedded_test",
preset_dict=single_video_subs_embed_preset_dict,
)
transaction_log = subscription.download(dry_run=dry_run)
assert_transaction_log_matches(
output_directory=output_directory,
transaction_log=transaction_log,
transaction_log_summary_file_name="plugins/test_subtitles_embedded.txt",
)
assert_expected_downloads(
output_directory=output_directory,
dry_run=dry_run,
expected_download_summary_file_name="plugins/test_subtitles_embedded.json",
)
@pytest.mark.parametrize("dry_run", [True, False])
def test_subtitles_embedded_and_file(
self,
music_video_config,
test_single_video_subs_embed_and_file_preset_dict,
output_directory,
dry_run,
):
subscription = Subscription.from_dict(
config=music_video_config,
preset_name="subtitles_embedded_and_file_test",
preset_dict=test_single_video_subs_embed_and_file_preset_dict,
)
transaction_log = subscription.download(dry_run=dry_run)
assert_transaction_log_matches(
output_directory=output_directory,
transaction_log=transaction_log,
transaction_log_summary_file_name="plugins/test_subtitles_embedded_and_file.txt",
)
assert_expected_downloads(
output_directory=output_directory,
dry_run=dry_run,
expected_download_summary_file_name="plugins/test_subtitles_embedded_and_file.json",
)