updated tests and file metadata
This commit is contained in:
parent
ab953c7157
commit
4045549eb6
7 changed files with 92 additions and 39 deletions
|
|
@ -8,6 +8,7 @@ from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder
|
|||
from ytdl_sub.entries.entry import Entry
|
||||
from ytdl_sub.plugins.plugin import Plugin
|
||||
from ytdl_sub.plugins.plugin import PluginOptions
|
||||
from ytdl_sub.utils.file_handler import FileMetadata
|
||||
from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator
|
||||
from ytdl_sub.validators.string_select_validator import StringSelectValidator
|
||||
from ytdl_sub.validators.validators import BoolValidator
|
||||
|
|
@ -173,7 +174,7 @@ class SubtitlesPlugin(Plugin[SubtitleOptions]):
|
|||
|
||||
return entry
|
||||
|
||||
def post_process_entry(self, entry: Entry) -> None:
|
||||
def post_process_entry(self, entry: Entry) -> Optional[FileMetadata]:
|
||||
"""
|
||||
Creates an entry's NFO file using values defined in the metadata options
|
||||
|
||||
|
|
@ -182,20 +183,25 @@ class SubtitlesPlugin(Plugin[SubtitleOptions]):
|
|||
entry:
|
||||
Entry to create subtitles for
|
||||
"""
|
||||
if not self.plugin_options.subtitles_name:
|
||||
return
|
||||
|
||||
requested_subtitles = entry.kwargs("requested_subtitles")
|
||||
for lang in requested_subtitles.keys():
|
||||
subtitle_file_name = f"{entry.uid}.{lang}.{self.plugin_options.subtitles_type}"
|
||||
output_subtitle_file_name = self.overrides.apply_formatter(
|
||||
formatter=self.plugin_options.subtitles_name,
|
||||
entry=entry,
|
||||
function_overrides={"lang": lang},
|
||||
)
|
||||
file_metadata: Optional[FileMetadata] = None
|
||||
langs = list(requested_subtitles.keys())
|
||||
|
||||
self.save_file(
|
||||
file_name=subtitle_file_name,
|
||||
output_file_name=output_subtitle_file_name,
|
||||
entry=entry,
|
||||
)
|
||||
if self.plugin_options.embed_subtitles:
|
||||
file_metadata = FileMetadata(f"Embedded subtitles with lang(s) {', '.join(langs)}")
|
||||
if self.plugin_options.subtitles_name:
|
||||
for lang in langs:
|
||||
subtitle_file_name = f"{entry.uid}.{lang}.{self.plugin_options.subtitles_type}"
|
||||
output_subtitle_file_name = self.overrides.apply_formatter(
|
||||
formatter=self.plugin_options.subtitles_name,
|
||||
entry=entry,
|
||||
function_overrides={"lang": lang},
|
||||
)
|
||||
|
||||
self.save_file(
|
||||
file_name=subtitle_file_name,
|
||||
output_file_name=output_subtitle_file_name,
|
||||
entry=entry,
|
||||
)
|
||||
|
||||
return file_metadata
|
||||
|
|
|
|||
|
|
@ -90,14 +90,21 @@ class SubscriptionYTDLOptions:
|
|||
# TODO: warn here
|
||||
return {}
|
||||
|
||||
builder = YTDLOptionsBuilder()
|
||||
builder = YTDLOptionsBuilder().add({"writesubtitles": True})
|
||||
subtitle_options: SubtitleOptions = subtitle_plugin.plugin_options
|
||||
|
||||
write_subtitle_file: bool = subtitle_options.subtitles_name is not None
|
||||
if write_subtitle_file:
|
||||
if subtitle_options.embed_subtitles:
|
||||
builder.add(
|
||||
{
|
||||
"postprocessors": [
|
||||
{"key": "FFmpegEmbedSubtitle", "already_have_subtitle": True}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
if subtitle_options.subtitles_name:
|
||||
builder.add(
|
||||
{
|
||||
"writesubtitles": True,
|
||||
"postprocessors": [
|
||||
{
|
||||
"key": "FFmpegSubtitlesConvertor",
|
||||
|
|
@ -107,16 +114,6 @@ class SubscriptionYTDLOptions:
|
|||
}
|
||||
)
|
||||
|
||||
if subtitle_options.embed_subtitles:
|
||||
builder.add(
|
||||
{
|
||||
"postprocessors": [
|
||||
# already_have_subtitle=True means we downloaded the subtitle files.
|
||||
{"key": "FFmpegEmbedSubtitle", "already_have_subtitle": write_subtitle_file}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
# If neither subtitles_name or embed_subtitles is set, do not set any other flags
|
||||
if not builder.to_dict():
|
||||
return {}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,13 @@ from ytdl_sub.subscriptions.subscription import Subscription
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def single_video_subs_preset_dict(output_directory):
|
||||
def single_video_subs_embed_preset_dict(output_directory):
|
||||
return {
|
||||
"preset": "yt_music_video",
|
||||
"youtube": {"video_url": "https://www.youtube.com/watch?v=2lAe1cqCOXo"},
|
||||
# override the output directory with our fixture-generated dir
|
||||
"output_options": {"output_directory": output_directory},
|
||||
"subtitles": {
|
||||
"subtitles_name": "{music_video_name}.{lang}.{subtitles_ext}",
|
||||
"embed_subtitles": True,
|
||||
"languages": ["en", "de"],
|
||||
"allow_auto_generated_subtitles": True,
|
||||
|
|
@ -25,30 +24,63 @@ def single_video_subs_preset_dict(output_directory):
|
|||
"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:
|
||||
@pytest.mark.parametrize("dry_run", [True, False])
|
||||
def test_single_video_download_with_subtitles(
|
||||
def test_subtitles_embedded(
|
||||
self,
|
||||
music_video_config,
|
||||
single_video_subs_preset_dict,
|
||||
single_video_subs_embed_preset_dict,
|
||||
output_directory,
|
||||
dry_run,
|
||||
):
|
||||
subscription = Subscription.from_dict(
|
||||
config=music_video_config,
|
||||
preset_name="subtitles_video_test",
|
||||
preset_dict=single_video_subs_preset_dict,
|
||||
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_video.txt",
|
||||
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_video.json",
|
||||
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",
|
||||
)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind-thumb.jpg": "704246dd78074e8a0ec001dd8d03fd60",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4": "90ae944811ca3312fcb3175ea32a0aa5",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo": "ffa10f1cbc098ace7b1c7a8fbe3097a8"
|
||||
}
|
||||
|
|
@ -2,6 +2,6 @@
|
|||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind-thumb.jpg": "704246dd78074e8a0ec001dd8d03fd60",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.de.srt": "b343c3bb9257b7ee7ba38f570a115b37",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.en.srt": "fe8c6ee92cae6e059fd80fd61691adbe",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4": "383213d2809cdc2e86e3a2c4c8deb685",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4": "90ae944811ca3312fcb3175ea32a0aa5",
|
||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo": "ffa10f1cbc098ace7b1c7a8fbe3097a8"
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Files created in '{output_directory}'
|
||||
----------------------------------------
|
||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind-thumb.jpg
|
||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4
|
||||
Embedded subtitles with lang(s) en, de
|
||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo
|
||||
NFO tags:
|
||||
musicvideo:
|
||||
album: Music Videos
|
||||
artist: JMC
|
||||
title: YouTube Rewind 2019: For the Record | #YouTubeRewind
|
||||
year: 2019
|
||||
|
|
@ -4,6 +4,7 @@ JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind-thumb.jpg
|
|||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.de.srt
|
||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.en.srt
|
||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4
|
||||
Embedded subtitles with lang(s) en, de
|
||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo
|
||||
NFO tags:
|
||||
musicvideo:
|
||||
Loading…
Reference in a new issue