mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-30 13:05:08 +00:00
refactor(export): move the --export writer out of dl into core ExportWriter
This commit is contained in:
@@ -9,9 +9,9 @@ from uuid import UUID
|
||||
import mediaexport
|
||||
import pytest
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from tests.core.test_export import make_writer
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.export_name import ExportNamer, export_name, move_export, quality_parts, season_episodes
|
||||
from unshackle.core.export_name import export_name, move_export, quality_parts, season_episodes
|
||||
from unshackle.core.titles import Episode, Movie, Song
|
||||
from unshackle.core.tracks import Audio, Subtitle, Video
|
||||
|
||||
@@ -186,45 +186,36 @@ def test_collision_gets_a_suffix(tmp_path: Path) -> None:
|
||||
assert move_export(moved, "Example.Movie.2024-EXAMPLE") == moved
|
||||
|
||||
|
||||
def make_dl(tmp_path: Path, seasons: dict[int, set[int]] | None = None) -> dl:
|
||||
instance = dl.__new__(dl)
|
||||
instance.service = "EXAMPLE"
|
||||
instance.log = logging.getLogger("download")
|
||||
instance.export_namer = ExportNamer("EXAMPLE", seasons or {})
|
||||
return instance
|
||||
|
||||
|
||||
def test_export_is_renamed_as_titles_arrive_and_stays_valid(tmp_path: Path) -> None:
|
||||
instance = make_dl(tmp_path, seasons_of((1, 2)))
|
||||
work = tmp_path / "export_EXAMPLE_1.json"
|
||||
writer = make_writer(tmp_path)
|
||||
writer.namer.seasons = seasons_of((1, 2))
|
||||
first, second = episode(1, 1), episode(1, 2)
|
||||
for title in (first, second):
|
||||
title.tracks.add(video(f"v{title.number}"))
|
||||
|
||||
instance.write_export(work, first, first.tracks.videos[0], StubDRM())
|
||||
writer.record(first, first.tracks.videos[0], StubDRM())
|
||||
partial = tmp_path / "Example.Show.S01E01.1080p.h264.sdr.dash-EXAMPLE.json"
|
||||
assert [p.name for p in tmp_path.iterdir()] == [partial.name]
|
||||
assert [e.id for e in mediaexport.read(partial).titles] == ["ep-1-1"]
|
||||
|
||||
instance.write_export(work, second, second.tracks.videos[0])
|
||||
writer.record(second, second.tracks.videos[0])
|
||||
final = tmp_path / "Example.Show.S01.1080p.h264.sdr.dash-EXAMPLE.json"
|
||||
assert [p.name for p in tmp_path.iterdir()] == [final.name]
|
||||
assert [e.id for e in mediaexport.read(final).titles] == ["ep-1-1", "ep-1-2"]
|
||||
|
||||
|
||||
def test_export_messages(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
|
||||
instance = make_dl(tmp_path)
|
||||
writer = make_writer(tmp_path)
|
||||
title = movie()
|
||||
title.tracks.add(video())
|
||||
title.tracks.add(audio())
|
||||
title.tracks.add(audio("a2"))
|
||||
work = tmp_path / "export_EXAMPLE_1.json"
|
||||
|
||||
with caplog.at_level(logging.INFO, logger="download"):
|
||||
for track in title.tracks:
|
||||
instance.write_export(work, title, track, StubDRM() if isinstance(track, Video) else None)
|
||||
instance.log_export_title(title)
|
||||
instance.log_export_summary()
|
||||
writer.record(title, track, StubDRM() if isinstance(track, Video) else None)
|
||||
writer.log_title(title)
|
||||
writer.log_summary()
|
||||
|
||||
lines = [r.getMessage() for r in caplog.records]
|
||||
assert "Exporting to Example.Movie.2024.1080p.h264.sdr.dash.aac2.0-EXAMPLE.json" in lines
|
||||
@@ -235,21 +226,21 @@ def test_export_messages(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> No
|
||||
|
||||
|
||||
def test_episode_message_names_the_episode(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
|
||||
instance = make_dl(tmp_path)
|
||||
writer = make_writer(tmp_path)
|
||||
title = episode(1, 5, "Example Episode")
|
||||
title.tracks.add(video())
|
||||
instance.write_export(tmp_path / "export_EXAMPLE_1.json", title, title.tracks.videos[0])
|
||||
writer.record(title, title.tracks.videos[0])
|
||||
|
||||
with caplog.at_level(logging.INFO, logger="download"):
|
||||
instance.log_export_title(title)
|
||||
writer.log_title(title)
|
||||
|
||||
assert "Exported S01E05 'Example Episode': 1 video, 0 audio, 0 subtitles, 0 keys" in caplog.messages
|
||||
|
||||
|
||||
def test_summary_when_nothing_was_exported(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
|
||||
instance = make_dl(tmp_path)
|
||||
writer = make_writer(tmp_path)
|
||||
with caplog.at_level(logging.INFO, logger="download"):
|
||||
instance.log_export_summary()
|
||||
writer.log_summary()
|
||||
assert "Nothing was exported" in caplog.messages
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user