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.entries.entry import Entry
|
||||||
from ytdl_sub.plugins.plugin import Plugin
|
from ytdl_sub.plugins.plugin import Plugin
|
||||||
from ytdl_sub.plugins.plugin import PluginOptions
|
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_formatter_validators import StringFormatterValidator
|
||||||
from ytdl_sub.validators.string_select_validator import StringSelectValidator
|
from ytdl_sub.validators.string_select_validator import StringSelectValidator
|
||||||
from ytdl_sub.validators.validators import BoolValidator
|
from ytdl_sub.validators.validators import BoolValidator
|
||||||
|
|
@ -173,7 +174,7 @@ class SubtitlesPlugin(Plugin[SubtitleOptions]):
|
||||||
|
|
||||||
return entry
|
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
|
Creates an entry's NFO file using values defined in the metadata options
|
||||||
|
|
||||||
|
|
@ -182,20 +183,25 @@ class SubtitlesPlugin(Plugin[SubtitleOptions]):
|
||||||
entry:
|
entry:
|
||||||
Entry to create subtitles for
|
Entry to create subtitles for
|
||||||
"""
|
"""
|
||||||
if not self.plugin_options.subtitles_name:
|
|
||||||
return
|
|
||||||
|
|
||||||
requested_subtitles = entry.kwargs("requested_subtitles")
|
requested_subtitles = entry.kwargs("requested_subtitles")
|
||||||
for lang in requested_subtitles.keys():
|
file_metadata: Optional[FileMetadata] = None
|
||||||
subtitle_file_name = f"{entry.uid}.{lang}.{self.plugin_options.subtitles_type}"
|
langs = list(requested_subtitles.keys())
|
||||||
output_subtitle_file_name = self.overrides.apply_formatter(
|
|
||||||
formatter=self.plugin_options.subtitles_name,
|
|
||||||
entry=entry,
|
|
||||||
function_overrides={"lang": lang},
|
|
||||||
)
|
|
||||||
|
|
||||||
self.save_file(
|
if self.plugin_options.embed_subtitles:
|
||||||
file_name=subtitle_file_name,
|
file_metadata = FileMetadata(f"Embedded subtitles with lang(s) {', '.join(langs)}")
|
||||||
output_file_name=output_subtitle_file_name,
|
if self.plugin_options.subtitles_name:
|
||||||
entry=entry,
|
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
|
# TODO: warn here
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
builder = YTDLOptionsBuilder()
|
builder = YTDLOptionsBuilder().add({"writesubtitles": True})
|
||||||
subtitle_options: SubtitleOptions = subtitle_plugin.plugin_options
|
subtitle_options: SubtitleOptions = subtitle_plugin.plugin_options
|
||||||
|
|
||||||
write_subtitle_file: bool = subtitle_options.subtitles_name is not None
|
if subtitle_options.embed_subtitles:
|
||||||
if write_subtitle_file:
|
builder.add(
|
||||||
|
{
|
||||||
|
"postprocessors": [
|
||||||
|
{"key": "FFmpegEmbedSubtitle", "already_have_subtitle": True}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if subtitle_options.subtitles_name:
|
||||||
builder.add(
|
builder.add(
|
||||||
{
|
{
|
||||||
"writesubtitles": True,
|
|
||||||
"postprocessors": [
|
"postprocessors": [
|
||||||
{
|
{
|
||||||
"key": "FFmpegSubtitlesConvertor",
|
"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 neither subtitles_name or embed_subtitles is set, do not set any other flags
|
||||||
if not builder.to_dict():
|
if not builder.to_dict():
|
||||||
return {}
|
return {}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,13 @@ from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def single_video_subs_preset_dict(output_directory):
|
def single_video_subs_embed_preset_dict(output_directory):
|
||||||
return {
|
return {
|
||||||
"preset": "yt_music_video",
|
"preset": "yt_music_video",
|
||||||
"youtube": {"video_url": "https://www.youtube.com/watch?v=2lAe1cqCOXo"},
|
"youtube": {"video_url": "https://www.youtube.com/watch?v=2lAe1cqCOXo"},
|
||||||
# override the output directory with our fixture-generated dir
|
# override the output directory with our fixture-generated dir
|
||||||
"output_options": {"output_directory": output_directory},
|
"output_options": {"output_directory": output_directory},
|
||||||
"subtitles": {
|
"subtitles": {
|
||||||
"subtitles_name": "{music_video_name}.{lang}.{subtitles_ext}",
|
|
||||||
"embed_subtitles": True,
|
"embed_subtitles": True,
|
||||||
"languages": ["en", "de"],
|
"languages": ["en", "de"],
|
||||||
"allow_auto_generated_subtitles": True,
|
"allow_auto_generated_subtitles": True,
|
||||||
|
|
@ -25,30 +24,63 @@ def single_video_subs_preset_dict(output_directory):
|
||||||
"overrides": {"artist": "JMC"},
|
"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:
|
class TestSubtitles:
|
||||||
@pytest.mark.parametrize("dry_run", [True, False])
|
@pytest.mark.parametrize("dry_run", [True, False])
|
||||||
def test_single_video_download_with_subtitles(
|
def test_subtitles_embedded(
|
||||||
self,
|
self,
|
||||||
music_video_config,
|
music_video_config,
|
||||||
single_video_subs_preset_dict,
|
single_video_subs_embed_preset_dict,
|
||||||
output_directory,
|
output_directory,
|
||||||
dry_run,
|
dry_run,
|
||||||
):
|
):
|
||||||
subscription = Subscription.from_dict(
|
subscription = Subscription.from_dict(
|
||||||
config=music_video_config,
|
config=music_video_config,
|
||||||
preset_name="subtitles_video_test",
|
preset_name="subtitles_embedded_test",
|
||||||
preset_dict=single_video_subs_preset_dict,
|
preset_dict=single_video_subs_embed_preset_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
transaction_log = subscription.download(dry_run=dry_run)
|
transaction_log = subscription.download(dry_run=dry_run)
|
||||||
assert_transaction_log_matches(
|
assert_transaction_log_matches(
|
||||||
output_directory=output_directory,
|
output_directory=output_directory,
|
||||||
transaction_log=transaction_log,
|
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(
|
assert_expected_downloads(
|
||||||
output_directory=output_directory,
|
output_directory=output_directory,
|
||||||
dry_run=dry_run,
|
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-thumb.jpg": "704246dd78074e8a0ec001dd8d03fd60",
|
||||||
"JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.de.srt": "b343c3bb9257b7ee7ba38f570a115b37",
|
"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.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"
|
"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.de.srt
|
||||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.en.srt
|
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.en.srt
|
||||||
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4
|
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
|
JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo
|
||||||
NFO tags:
|
NFO tags:
|
||||||
musicvideo:
|
musicvideo:
|
||||||
Loading…
Reference in a new issue