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:
@@ -6,10 +6,9 @@ from datetime import date
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core.config import Config, config
|
||||
from unshackle.core.titles.episode import Episode
|
||||
from unshackle.core.wire import build_title, serialize_title
|
||||
from unshackle.core.wire import build_title, serialize_title, title_to_meta
|
||||
|
||||
SERIES = "{title}.{year?}.{season_episode}.{episode_name?}.{quality?}-{tag?}"
|
||||
SPORTS = "{title}.{year?}.{date?}.{episode_name}.{quality?}-{tag?}"
|
||||
@@ -90,7 +89,7 @@ def test_the_sport_flag_survives_the_remote_round_trip():
|
||||
|
||||
|
||||
def test_the_sport_flag_survives_the_export_round_trip():
|
||||
rebuilt = build_title(dl.title_to_meta(make_episode()), "TEST", fallback_id="x")
|
||||
rebuilt = build_title(title_to_meta(make_episode()), "TEST", fallback_id="x")
|
||||
assert isinstance(rebuilt, Episode) and rebuilt.sport
|
||||
|
||||
|
||||
|
||||
+97
-48
@@ -1,6 +1,6 @@
|
||||
"""Tests for ``dl.write_export``, the ``--export`` mediaexport sidecar.
|
||||
"""Tests for ``ExportWriter.record``, the ``--export`` mediaexport sidecar.
|
||||
|
||||
Regression: DRM-free tracks never pass through ``prepare_drm``, so ``write_export``
|
||||
Regression: DRM-free tracks never pass through ``prepare_drm``, so ``record``
|
||||
must accept ``drm=None`` (and DRM systems without ``to_dict``/``content_keys`` such
|
||||
as ClearKey) and still record the track/manifest/chapter/attachment info that
|
||||
``unshackle import`` rebuilds a download from.
|
||||
@@ -18,9 +18,9 @@ from uuid import UUID
|
||||
import click
|
||||
import pytest
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core.drm.clearkey import ClearKey
|
||||
from unshackle.core.drm.clearkey_cenc import ClearKeyCENC
|
||||
from unshackle.core.export_writer import ExportWriter
|
||||
from unshackle.core.import_service import ImportService
|
||||
from unshackle.core.titles import Movie
|
||||
from unshackle.core.tracks import Audio, Chapter, Subtitle, Video
|
||||
@@ -43,12 +43,21 @@ class StubDRM:
|
||||
return {"system": "Widevine", "pssh_b64": "AAAA"}
|
||||
|
||||
|
||||
def make_dl() -> dl:
|
||||
# __new__ skips the CLI-driven __init__; write_export only needs `service` and `log`.
|
||||
instance = dl.__new__(dl)
|
||||
instance.service = "EXAMPLE"
|
||||
instance.log = logging.getLogger("download")
|
||||
return instance
|
||||
class StubSource:
|
||||
"""A title source with no session headers and no region."""
|
||||
|
||||
session = None
|
||||
current_region = None
|
||||
|
||||
|
||||
def make_writer(tmp_path: Path, source: Any = None, proxy_requested: bool = False) -> ExportWriter:
|
||||
return ExportWriter(tmp_path / "export_EXAMPLE_1.json", "EXAMPLE", source or StubSource(), proxy_requested)
|
||||
|
||||
|
||||
def written(writer: ExportWriter) -> Path:
|
||||
"""The export file after the writer named it."""
|
||||
assert writer.namer.path is not None
|
||||
return writer.namer.path
|
||||
|
||||
|
||||
def make_title() -> Movie:
|
||||
@@ -100,11 +109,12 @@ def entry(path: Path) -> dict:
|
||||
|
||||
def test_drm_free_track_exports(tmp_path: Path) -> None:
|
||||
"""The reported bug: DRM-free downloads produced no usable export."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
video = title.tracks.videos[0]
|
||||
|
||||
make_dl().write_export(export, title, video)
|
||||
writer.record(title, video)
|
||||
export = written(writer)
|
||||
|
||||
doc = read_export(export)
|
||||
assert doc["kind"] == "mediaexport" and doc["version"] == 1
|
||||
@@ -119,11 +129,12 @@ def test_drm_free_track_exports(tmp_path: Path) -> None:
|
||||
|
||||
def test_clearkey_drm_exports_track_without_keys(tmp_path: Path) -> None:
|
||||
"""ClearKey has no to_dict/content_keys; the track info must still export."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
video = title.tracks.videos[0]
|
||||
|
||||
make_dl().write_export(export, title, video, ClearKey(key="bb" * 16))
|
||||
writer.record(title, video, ClearKey(key="bb" * 16))
|
||||
export = written(writer)
|
||||
|
||||
tinfo = entry(export)
|
||||
assert "keys" not in tinfo and "drm" not in tinfo
|
||||
@@ -132,13 +143,13 @@ def test_clearkey_drm_exports_track_without_keys(tmp_path: Path) -> None:
|
||||
|
||||
def test_post_download_write_keeps_licensed_keys(tmp_path: Path) -> None:
|
||||
"""The drm=None write after download must not clobber prepare_drm's DRM/keys."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
video = title.tracks.videos[0]
|
||||
runner = make_dl()
|
||||
|
||||
runner.write_export(export, title, video, StubDRM()) # prepare_drm
|
||||
runner.write_export(export, title, video) # post-download hook
|
||||
writer.record(title, video, StubDRM()) # prepare_drm
|
||||
writer.record(title, video) # post-download hook
|
||||
export = written(writer)
|
||||
|
||||
tinfo = entry(export)
|
||||
assert tinfo["drm"] == [{"system": "widevine", "pssh": "AAAA"}]
|
||||
@@ -149,12 +160,12 @@ def test_post_download_write_keeps_licensed_keys(tmp_path: Path) -> None:
|
||||
def test_drm_free_export_roundtrips_through_import_service(tmp_path: Path) -> None:
|
||||
"""A DRM-free export must rebuild via ImportService: titles, tracks (no DRM),
|
||||
empty key pool (resolve_server_keys no-op) and chapters."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
title.tracks.chapters.add(Chapter("00:00:10.000", "Intro"))
|
||||
runner = make_dl()
|
||||
for track in [*title.tracks.videos, *title.tracks.audio, *title.tracks.subtitles]:
|
||||
runner.write_export(export, title, track)
|
||||
writer.record(title, track)
|
||||
export = written(writer)
|
||||
|
||||
svc = ImportService(import_ctx(), "EXAMPLE", "movie-1", str(export))
|
||||
|
||||
@@ -181,12 +192,13 @@ def test_drm_free_export_roundtrips_through_import_service(tmp_path: Path) -> No
|
||||
def test_clearkey_cenc_exports_drm_and_keys(tmp_path: Path) -> None:
|
||||
"""A licensed ClearKeyCENC exports its system dict and KID:KEY map, and the
|
||||
exported DRM dict plus keys rebuild a decrypt-ready instance via drm_from_dict."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
video = title.tracks.videos[0]
|
||||
drm = ClearKeyCENC(kids=[KID], laurl="https://license.example.test/ck", content_keys={KID: "cc" * 16})
|
||||
|
||||
make_dl().write_export(export, title, video, drm)
|
||||
writer.record(title, video, drm)
|
||||
export = written(writer)
|
||||
|
||||
tinfo = entry(export)
|
||||
assert tinfo["drm"] == [{"system": "clearkey"}]
|
||||
@@ -201,13 +213,14 @@ def test_clearkey_cenc_exports_drm_and_keys(tmp_path: Path) -> None:
|
||||
|
||||
def test_keyless_content_keys_writes_no_keys_entry(tmp_path: Path) -> None:
|
||||
"""A DRM object with empty content_keys must not create an empty keys map."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
video = title.tracks.videos[0]
|
||||
drm = StubDRM()
|
||||
drm.content_keys = {}
|
||||
|
||||
make_dl().write_export(export, title, video, drm)
|
||||
writer.record(title, video, drm)
|
||||
export = written(writer)
|
||||
|
||||
tinfo = entry(export)
|
||||
assert tinfo["drm"] == [{"system": "widevine", "pssh": "AAAA"}]
|
||||
@@ -313,14 +326,13 @@ class KeyDRM:
|
||||
|
||||
def test_export_drops_session_headers(tmp_path: Path) -> None:
|
||||
"""The file travels between people: the session cookie and bearer token must not go with it."""
|
||||
export = tmp_path / "export.json"
|
||||
title = make_title()
|
||||
title.tracks.manifest_url = "https://example.test/m.mpd"
|
||||
runner = make_dl()
|
||||
headers = {"User-Agent": "example-ua", "Cookie": "session=secret", "Authorization": "Bearer secret"}
|
||||
runner.export_service = cast(Any, SimpleNamespace(session=SimpleNamespace(headers=headers)))
|
||||
writer = make_writer(tmp_path, SimpleNamespace(session=SimpleNamespace(headers=headers)))
|
||||
|
||||
runner.write_export(export, title, title.tracks.videos[0])
|
||||
writer.record(title, title.tracks.videos[0])
|
||||
export = written(writer)
|
||||
|
||||
assert entry(export)["manifests"][0]["headers"] == {"User-Agent": "example-ua"}
|
||||
assert "secret" not in export.read_text(encoding="utf8")
|
||||
@@ -328,14 +340,14 @@ def test_export_drops_session_headers(tmp_path: Path) -> None:
|
||||
|
||||
def test_second_key_for_one_kid_keeps_the_first(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Two titles that license one KID to different keys: the file keeps the first key and stays readable."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
first, second = make_title(), make_title()
|
||||
second.id = "movie-2"
|
||||
runner = make_dl()
|
||||
|
||||
runner.write_export(export, first, first.tracks.videos[0], KeyDRM("aa" * 16))
|
||||
writer.record(first, first.tracks.videos[0], KeyDRM("aa" * 16))
|
||||
with caplog.at_level(logging.WARNING, logger="download"):
|
||||
runner.write_export(export, second, second.tracks.videos[0], KeyDRM("bb" * 16))
|
||||
writer.record(second, second.tracks.videos[0], KeyDRM("bb" * 16))
|
||||
export = written(writer)
|
||||
|
||||
titles = read_export(export)["titles"]
|
||||
assert titles[0]["keys"] == {KID.hex: "aa" * 16}
|
||||
@@ -345,14 +357,14 @@ def test_second_key_for_one_kid_keeps_the_first(tmp_path: Path, caplog: pytest.L
|
||||
|
||||
def test_uppercase_content_key_is_stored_lowercase(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""A licence server that sends uppercase hex still gives one key, not a conflict with itself."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
first, second = make_title(), make_title()
|
||||
second.id = "movie-2"
|
||||
runner = make_dl()
|
||||
|
||||
runner.write_export(export, first, first.tracks.videos[0], KeyDRM("AA" * 16))
|
||||
writer.record(first, first.tracks.videos[0], KeyDRM("AA" * 16))
|
||||
with caplog.at_level(logging.WARNING, logger="download"):
|
||||
runner.write_export(export, second, second.tracks.videos[0], KeyDRM("AA" * 16))
|
||||
writer.record(second, second.tracks.videos[0], KeyDRM("AA" * 16))
|
||||
export = written(writer)
|
||||
|
||||
titles = read_export(export)["titles"]
|
||||
assert titles[0]["keys"] == {KID.hex: "aa" * 16}
|
||||
@@ -364,13 +376,13 @@ def test_malformed_content_key_skips_the_key_not_the_download(
|
||||
tmp_path: Path, caplog: pytest.LogCaptureFixture, key: str
|
||||
) -> None:
|
||||
"""A key that is not 16 bytes of hex, as a new DRM system's tool might return, must not stop licensing."""
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
title.tracks.manifest_url = "https://example.test/m.mpd"
|
||||
runner = make_dl()
|
||||
|
||||
with caplog.at_level(logging.WARNING, logger="download"):
|
||||
runner.write_export(export, title, title.tracks.videos[0], KeyDRM(key))
|
||||
writer.record(title, title.tracks.videos[0], KeyDRM(key))
|
||||
export = written(writer)
|
||||
|
||||
assert "keys" not in entry(export)
|
||||
assert f"Not exporting the key for KID {KID.hex}" in caplog.text
|
||||
@@ -412,8 +424,9 @@ def export_service_filtered_title(tmp_path: Path, manifest_url: str | None) -> P
|
||||
assert video.data["dash"]["filtered_period_ids"] == ["ad-1"]
|
||||
title.tracks.add(video)
|
||||
title.tracks.manifest_url = manifest_url
|
||||
export = tmp_path / "export.json"
|
||||
make_dl().write_export(export, title, video)
|
||||
writer = make_writer(tmp_path)
|
||||
writer.record(title, video)
|
||||
export = written(writer)
|
||||
doc = read_export(export)
|
||||
doc["titles"][0]["x-unshackle"].pop("snapshot", None)
|
||||
export.write_text(json.dumps(doc), encoding="utf8")
|
||||
@@ -479,12 +492,12 @@ def test_import_keeps_every_period_when_no_exported_period_is_left(
|
||||
|
||||
|
||||
def test_a_3d_video_stays_3d_through_export_and_import(tmp_path: Path) -> None:
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
title.tracks.videos[0].stereo = True
|
||||
runner = make_dl()
|
||||
for track in [*title.tracks.videos, *title.tracks.audio]:
|
||||
runner.write_export(export, title, track)
|
||||
writer.record(title, track)
|
||||
export = written(writer)
|
||||
assert [row.get("stereo") for row in entry(export)["tracks"]][0] is True
|
||||
svc = ImportService(import_ctx(), "EXAMPLE", "movie-1", str(export))
|
||||
movie = next(iter(svc.get_titles()))
|
||||
@@ -498,12 +511,48 @@ class ProviderService:
|
||||
|
||||
|
||||
def test_the_service_metadata_provider_survives_export_and_import(tmp_path: Path) -> None:
|
||||
export = tmp_path / "export.json"
|
||||
title = make_title()
|
||||
runner = make_dl()
|
||||
runner.export_service = cast(Any, ProviderService())
|
||||
writer = make_writer(tmp_path, ProviderService())
|
||||
|
||||
runner.write_export(export, title, title.tracks.videos[0])
|
||||
writer.record(title, title.tracks.videos[0])
|
||||
export = written(writer)
|
||||
|
||||
movie = list(ImportService(import_ctx(), "EXAMPLE", "movie-1", str(export)).get_titles())[0]
|
||||
assert (movie.metadata_provider, movie.anime) == ("tmdb", True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("proxy_requested, region", [(True, "us"), (False, None)])
|
||||
def test_the_region_is_recorded_only_for_a_proxy_run(tmp_path: Path, proxy_requested: bool, region: str | None) -> None:
|
||||
writer = make_writer(tmp_path, SimpleNamespace(session=None, current_region="us"), proxy_requested)
|
||||
title = make_title()
|
||||
|
||||
writer.record(title, title.tracks.videos[0])
|
||||
|
||||
assert read_export(written(writer)).get("region") == region
|
||||
|
||||
|
||||
def test_the_log_lines_read_the_named_file(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
with caplog.at_level(logging.INFO, logger="download"):
|
||||
writer.log_summary()
|
||||
writer.record(title, title.tracks.videos[0], StubDRM())
|
||||
writer.log_title(title)
|
||||
writer.log_summary()
|
||||
|
||||
assert caplog.messages[0] == "Nothing was exported"
|
||||
assert f"Saved the export to {written(writer)}: 1 title, 1 key" in caplog.messages
|
||||
assert "The export holds content keys: keep it private" in caplog.messages
|
||||
|
||||
|
||||
def test_a_title_with_no_record_logs_that_nothing_was_exported(
|
||||
tmp_path: Path, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
writer = make_writer(tmp_path)
|
||||
first, second = make_title(), make_title()
|
||||
second.id = "movie-2"
|
||||
writer.record(first, first.tracks.videos[0])
|
||||
with caplog.at_level(logging.WARNING, logger="download"):
|
||||
writer.log_title(second)
|
||||
|
||||
assert caplog.messages == ["Exported nothing for 'Example Movie' (2024)"]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ re-parse path and needs ``track.data["ism"]["segments"]`` restored, because
|
||||
restored, because ``HLS.download_track`` re-fetches the variant from ``track.url``. That makes
|
||||
the stored per-track URL load-bearing for HLS in a way it is not for ISM.
|
||||
|
||||
These drive the real ``dl.write_export`` rather than hand-written export dicts, so a change to
|
||||
These drive the real ``ExportWriter`` rather than hand-written export dicts, so a change to
|
||||
the export format fails here instead of silently invalidating the fixtures.
|
||||
"""
|
||||
|
||||
@@ -18,7 +18,7 @@ from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from tests.core.test_export import make_writer, written
|
||||
from unshackle.core.import_service import ImportService
|
||||
from unshackle.core.manifests import HLS, ISM
|
||||
|
||||
@@ -63,12 +63,10 @@ def export_tracks(tmp_path: Path, tracks, manifest_url: str | None) -> Path:
|
||||
title.tracks.add(track)
|
||||
title.tracks.manifest_url = manifest_url
|
||||
|
||||
runner = dl.__new__(dl)
|
||||
runner.service = "EXAMPLE"
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
for track in [*title.tracks.videos, *title.tracks.audio, *title.tracks.subtitles]:
|
||||
runner.write_export(export, title, track)
|
||||
return export
|
||||
writer.record(title, track)
|
||||
return written(writer)
|
||||
|
||||
|
||||
def import_tracks(export: Path):
|
||||
|
||||
@@ -8,7 +8,6 @@ the fallback for a track that declares no KID.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, cast
|
||||
@@ -18,7 +17,7 @@ from uuid import UUID
|
||||
import click
|
||||
from pywidevine.pssh import PSSH
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from tests.core.test_export import make_writer, written
|
||||
from unshackle.core.drm import ClearKey, Widevine
|
||||
from unshackle.core.drm.key_args import ZERO_KID
|
||||
from unshackle.core.import_service import ImportService
|
||||
@@ -85,13 +84,11 @@ def write_export(tmp_path: Path, kids: bool = True) -> Path:
|
||||
for track in DASH.from_text(MPD, MPD_URL).to_tracks(language="en"):
|
||||
title.tracks.add(track)
|
||||
title.tracks.manifest_url = MPD_URL
|
||||
runner = dl.__new__(dl)
|
||||
runner.service = "EXAMPLE"
|
||||
runner.log = logging.getLogger("download")
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
drm = {"video": widevine(VIDEO_KID, VIDEO_KEY), "en": widevine(AUDIO_KID, AUDIO_KEY)}
|
||||
for track in [*title.tracks.videos, *title.tracks.audio]:
|
||||
runner.write_export(export, title, track, drm.get(label(track)))
|
||||
writer.record(title, track, drm.get(label(track)))
|
||||
export = written(writer)
|
||||
if not kids:
|
||||
doc = json.loads(export.read_text(encoding="utf8"))
|
||||
for row in doc["titles"][0]["tracks"]:
|
||||
@@ -220,13 +217,11 @@ def hls_import(
|
||||
for track in HLS.from_text(HLS_MASTER, HLS_URL).to_tracks(language="en"):
|
||||
title.tracks.add(track)
|
||||
title.tracks.manifest_url = HLS_URL
|
||||
runner = dl.__new__(dl)
|
||||
runner.service = "EXAMPLE"
|
||||
runner.log = logging.getLogger("download")
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
drm = {"video": widevine(VIDEO_KID, VIDEO_KEY), "en": audio_drm, "es": subtitle_drm}
|
||||
for track in [*title.tracks.videos, *title.tracks.audio, *title.tracks.subtitles]:
|
||||
runner.write_export(export, title, track, drm.get(label(track)))
|
||||
writer.record(title, track, drm.get(label(track)))
|
||||
export = written(writer)
|
||||
if not kids:
|
||||
doc = json.loads(export.read_text(encoding="utf8"))
|
||||
for row in doc["titles"][0]["tracks"]:
|
||||
|
||||
@@ -79,17 +79,16 @@ def detach_video(tracks: Tracks, track_id: str | None = None) -> Track:
|
||||
|
||||
|
||||
def export_and_import(tmp_path: Any, tracks: Tracks) -> Tracks:
|
||||
from tests.core.test_export import StubService, import_ctx, make_dl
|
||||
from tests.core.test_export import StubService, import_ctx, make_writer, written
|
||||
from unshackle.core.import_service import ImportService
|
||||
from unshackle.core.titles import Movie
|
||||
|
||||
export = tmp_path / "export.json"
|
||||
writer = make_writer(tmp_path)
|
||||
title = Movie(id_="movie-1", service=StubService, name="Example Movie", year=2024, language="en")
|
||||
title.tracks = tracks
|
||||
runner = make_dl()
|
||||
for track in title.tracks:
|
||||
runner.write_export(export, title, track)
|
||||
service = ImportService(import_ctx(), "EXAMPLE", "movie-1", str(export))
|
||||
writer.record(title, track)
|
||||
service = ImportService(import_ctx(), "EXAMPLE", "movie-1", str(written(writer)))
|
||||
return service.get_tracks(next(iter(service.get_titles())))
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import pytest
|
||||
from pywidevine.pssh import PSSH as WidevinePSSH
|
||||
|
||||
from tests.core.test_zero_kid_fallback import _playready_pssh
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core import wire
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.drm import BlowfishStripe, ClearKeyCENC, ClearKeyCTR, PlayReady, Widevine
|
||||
@@ -715,13 +714,13 @@ def test_rest_title_key_order_is_stable() -> None:
|
||||
|
||||
|
||||
def test_export_episode_meta() -> None:
|
||||
meta = dl.title_to_meta(full_episode())
|
||||
meta = title_to_meta(full_episode())
|
||||
assert meta == META_EPISODE
|
||||
assert list(meta) == list(META_EPISODE)
|
||||
|
||||
|
||||
def test_export_movie_meta() -> None:
|
||||
assert dl.title_to_meta(movie()) == {
|
||||
assert title_to_meta(movie()) == {
|
||||
"id": "movie-0001",
|
||||
"language": "fr",
|
||||
"type": "movie",
|
||||
@@ -731,7 +730,7 @@ def test_export_movie_meta() -> None:
|
||||
|
||||
|
||||
def test_export_meta_of_another_title_is_a_movie_named_by_str() -> None:
|
||||
assert dl.title_to_meta(song()) == {
|
||||
assert title_to_meta(song()) == {
|
||||
"id": "song-0001",
|
||||
"language": "en",
|
||||
"type": "movie",
|
||||
|
||||
Reference in New Issue
Block a user