tests complete!

This commit is contained in:
jbannon 2022-08-18 21:51:47 +00:00
parent 7592ccbab6
commit 7450f0e727
9 changed files with 86 additions and 11 deletions

View file

@ -30,13 +30,13 @@ SPONSORBLOCK_CATEGORIES: Set[str] = SPONSORBLOCK_HIGHLIGHT_CATEGORIES | {
def _chapters(entry: Entry) -> List[Dict]: def _chapters(entry: Entry) -> List[Dict]:
if entry.kwargs_contains("chapters"): if entry.kwargs_contains("chapters"):
return entry.kwargs("chapters") return entry.kwargs("chapters") or []
return [] return []
def _sponsorblock_chapters(entry: Entry) -> List[Dict]: def _sponsorblock_chapters(entry: Entry) -> List[Dict]:
if entry.kwargs_contains("sponsorblock_chapters"): if entry.kwargs_contains("sponsorblock_chapters"):
return entry.kwargs("sponsorblock_chapters") return entry.kwargs("sponsorblock_chapters") or []
return [] return []

View file

@ -10,6 +10,7 @@ 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.chapters import Chapters from ytdl_sub.utils.chapters import Chapters
from ytdl_sub.utils.chapters import Timestamp from ytdl_sub.utils.chapters import Timestamp
from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.ffmpeg import FFMPEG from ytdl_sub.utils.ffmpeg import FFMPEG
from ytdl_sub.utils.file_handler import FileHandler from ytdl_sub.utils.file_handler import FileHandler
from ytdl_sub.utils.file_handler import FileMetadata from ytdl_sub.utils.file_handler import FileMetadata
@ -147,6 +148,7 @@ class SplitByChaptersPlugin(Plugin[SplitByChaptersOptions]):
# If no chapters, do not split anything # If no chapters, do not split anything
if not chapters.contains_any_chapters(): if not chapters.contains_any_chapters():
if self.plugin_options.when_no_chapters == "pass":
entry.add_variables( entry.add_variables(
{ {
"chapter_title": entry.title, "chapter_title": entry.title,
@ -156,9 +158,16 @@ class SplitByChaptersPlugin(Plugin[SplitByChaptersOptions]):
} }
) )
return [(entry, FileMetadata())] return [(entry, FileMetadata())]
if self.plugin_options.when_no_chapters == "drop":
return []
raise ValidationException(
f"Tried to split '{entry.title}' by chapters but it has no chapters"
)
# convert the entry thumbnail early so we do not have to guess the thumbnail extension # convert the entry thumbnail early so we do not have to guess the thumbnail extension
# when copying it. Do not error if it's not found, in case thumbnail_name is not set # when copying it. Do not error if it's not found, in case thumbnail_name is not set
if not self.is_dry_run:
convert_download_thumbnail(entry=entry, error_if_not_found=False) convert_download_thumbnail(entry=entry, error_if_not_found=False)
for idx, title in enumerate(chapters.titles): for idx, title in enumerate(chapters.titles):

View file

@ -254,7 +254,7 @@ class Chapters:
chapters = {} chapters = {}
if entry.kwargs_contains("chapters"): if entry.kwargs_contains("chapters"):
chapters = entry.kwargs("chapters") chapters = entry.kwargs("chapters") or []
for chapter in chapters: for chapter in chapters:
timestamps.append(Timestamp.from_seconds(int(float(chapter["start_time"])))) timestamps.append(Timestamp.from_seconds(int(float(chapter["start_time"]))))

View file

@ -1,9 +1,12 @@
import re
import mergedeep import mergedeep
import pytest import pytest
from e2e.expected_download import assert_expected_downloads from e2e.expected_download import assert_expected_downloads
from e2e.expected_transaction_log import assert_transaction_log_matches from e2e.expected_transaction_log import assert_transaction_log_matches
from ytdl_sub.subscriptions.subscription import Subscription from ytdl_sub.subscriptions.subscription import Subscription
from ytdl_sub.utils.exceptions import ValidationException
@pytest.fixture @pytest.fixture
@ -79,13 +82,11 @@ class TestSplitByChapters:
output_directory=output_directory, output_directory=output_directory,
transaction_log=transaction_log, transaction_log=transaction_log,
transaction_log_summary_file_name=f"plugins/split_by_chapters_video{'-dry-run' if dry_run else ''}.txt", transaction_log_summary_file_name=f"plugins/split_by_chapters_video{'-dry-run' if dry_run else ''}.txt",
regenerate_transaction_log=True,
) )
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/split_by_chapters_video.json", expected_download_summary_file_name="plugins/split_by_chapters_video.json",
regenerate_expected_download_summary=True,
) )
@pytest.mark.parametrize("dry_run", [True, False]) @pytest.mark.parametrize("dry_run", [True, False])
@ -107,11 +108,55 @@ class TestSplitByChapters:
output_directory=output_directory, output_directory=output_directory,
transaction_log=transaction_log, transaction_log=transaction_log,
transaction_log_summary_file_name=f"plugins/split_by_chapters_with_regex_video{'-dry-run' if dry_run else ''}.txt", transaction_log_summary_file_name=f"plugins/split_by_chapters_with_regex_video{'-dry-run' if dry_run else ''}.txt",
regenerate_transaction_log=True,
) )
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/split_by_chapters_with_regex_video.json", expected_download_summary_file_name="plugins/split_by_chapters_with_regex_video.json",
regenerate_expected_download_summary=True, )
@pytest.mark.parametrize("dry_run", [True, False])
@pytest.mark.parametrize("when_no_chapters", ["pass", "drop", "error"])
def test_video_with_no_chapters_and_regex(
self,
youtube_audio_config,
yt_album_as_chapters_with_regex_preset_dict,
output_directory,
dry_run,
when_no_chapters,
):
mergedeep.merge(
yt_album_as_chapters_with_regex_preset_dict,
{
"youtube": {"video_url": "https://youtube.com/watch?v=HKTNxEqsN3Q"},
"split_by_chapters": {"when_no_chapters": when_no_chapters},
},
)
subscription = Subscription.from_dict(
config=youtube_audio_config,
preset_name="split_by_chapters_with_regex_video",
preset_dict=yt_album_as_chapters_with_regex_preset_dict,
)
if when_no_chapters == "error":
with pytest.raises(
ValidationException,
match=re.escape(
"Tried to split 'Oblivion Mod \"Falcor\" p.1' by chapters but it has no chapters"
),
):
_ = subscription.download(dry_run=dry_run)
return
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=f"plugins/split_by_chapters_with_regex_no_chapters_video_{when_no_chapters}.txt",
)
assert_expected_downloads(
output_directory=output_directory,
dry_run=dry_run,
expected_download_summary_file_name=f"plugins/split_by_chapters_with_regex_no_chapters_video_{when_no_chapters}.txt",
) )

View file

@ -0,0 +1,4 @@
{
"Oblivion Mod \"Falcor\" p.1/01 - Oblivion Mod \"Falcor\" p.1.mp3": "703ffb93964ac025ee66221b98ee4d49",
"Oblivion Mod \"Falcor\" p.1/folder.jpg": "fb95b510681676e81c321171fc23143e"
}

View file

@ -0,0 +1,4 @@
{
"Oblivion Mod \"Falcor\" p.1/01 - Oblivion Mod \"Falcor\" p.1.mp3": "703ffb93964ac025ee66221b98ee4d49",
"Oblivion Mod \"Falcor\" p.1/folder.jpg": "fb95b510681676e81c321171fc23143e"
}

View file

@ -0,0 +1,12 @@
Files created in '{output_directory}'
----------------------------------------
Oblivion Mod "Falcor" p.1/01 - Oblivion Mod "Falcor" p.1.mp3
Music Tags:
album: Oblivion Mod "Falcor" p.1
albumartist: Project Zombie
artist: Project Zombie
genre: Unset
title: Oblivion Mod "Falcor" p.1
track: 1
year: 2010
Oblivion Mod "Falcor" p.1/folder.jpg