refactor(core): move the title, track and DRM wire form into core/wire.py

This commit is contained in:
imSp4rky
2026-11-24 14:37:51 -07:00
parent e385234a92
commit 55138f95c2
36 changed files with 2250 additions and 907 deletions
+1 -2
View File
@@ -2,10 +2,9 @@
import pytest
from unshackle.core.api.handlers import serialize_title
from unshackle.core.remote_service import build_title
from unshackle.core.titles.availability import availability_metadata
from unshackle.core.titles.episode import Episode
from unshackle.core.wire import build_title, serialize_title
pytestmark = pytest.mark.unit
+1 -3
View File
@@ -16,8 +16,8 @@ import pytest
from unshackle.core.api import handlers
from unshackle.core.api.errors import APIError
from unshackle.core.api.handlers import serialize_title
from unshackle.core.titles.episode import Episode
from unshackle.core.wire import build_title, serialize_title
pytestmark = pytest.mark.unit
@@ -116,8 +116,6 @@ def test_part_stays_out_of_the_name_field() -> None:
def test_remote_build_title_round_trip() -> None:
from unshackle.core.remote_service import build_title
rebuilt = build_title(serialize_title(ep(1, 4, 2)), "FAKE", "fallback-id")
assert (rebuilt.season, rebuilt.number, rebuilt.part, rebuilt.name) == (1, 4, 2, "Pilot")
+3 -3
View File
@@ -1,7 +1,7 @@
"""The title fields that cross the remote wire: air_date, absolute, anime and daily.
Covers serialize_title's conditional keys, the service-class ANIME/DAILY stamp, and the
serialize_title / title_to_meta round trips through remote_service.build_title.
serialize_title / title_to_meta round trips through wire.build_title.
"""
from __future__ import annotations
@@ -16,11 +16,11 @@ from langcodes import Language
from unshackle.commands.dl import dl
from unshackle.core.api import handlers
from unshackle.core.api.handlers import serialize_title, stamp_service_flags
from unshackle.core.remote_service import build_title
from unshackle.core.api.handlers import stamp_service_flags
from unshackle.core.titles.episode import Episode
from unshackle.core.titles.movie import Movie
from unshackle.core.titles.music import Song
from unshackle.core.wire import build_title, serialize_title
pytestmark = pytest.mark.unit
+7 -5
View File
@@ -14,11 +14,6 @@ from unshackle.core.api.handlers import (
listed_titles,
sanitize_log,
search_handler,
serialize_audio_track,
serialize_drm,
serialize_subtitle_track,
serialize_title,
serialize_video_track,
validate_download_parameters,
validate_service,
)
@@ -27,6 +22,13 @@ from unshackle.core.titles.episode import Episode
from unshackle.core.titles.movie import Movie
from unshackle.core.tracks import Audio, Subtitle, Video
from unshackle.core.tracks.track import Track
from unshackle.core.wire import (
serialize_audio_track,
serialize_drm,
serialize_subtitle_track,
serialize_title,
serialize_video_track,
)
pytestmark = pytest.mark.unit
@@ -6,10 +6,12 @@ from enum import Enum
import pytest
from unshackle.core.api.handlers import serialize_audio_track, serialize_subtitle_track, serialize_video_track
from unshackle.core.manifests.snapshot import match_track
from unshackle.core.remote_service import (
RemoteService,
from unshackle.core.remote_service import RemoteService
from unshackle.core.titles.episode import Episode
from unshackle.core.titles.movie import Movie
from unshackle.core.tracks import Audio, Subtitle, Video
from unshackle.core.wire import (
build_title,
build_tracks,
deserialize_audio,
@@ -17,10 +19,12 @@ from unshackle.core.remote_service import (
deserialize_video,
enum_get,
reconstruct_drm,
serialize_audio_track,
serialize_subtitle_track,
serialize_video_track,
track_from_dict,
track_to_dict,
)
from unshackle.core.titles.episode import Episode
from unshackle.core.titles.movie import Movie
from unshackle.core.tracks import Audio, Subtitle, Video
pytestmark = pytest.mark.unit
@@ -64,14 +68,12 @@ def test_a_stereo_track_stays_3d_over_remote() -> None:
def test_a_track_note_shows_over_remote_and_export_and_is_not_an_edition() -> None:
from unshackle.core.tracks.track import Track
v = Video(url="https://x/v.mp4", language="ja", codec=Video.Codec.AVC, note="h264mpl40-dash")
a = Audio(url="https://x/a.mp4", language="ja", codec=Audio.Codec.AAC, note="heaac-2-dash")
s = Subtitle(url="https://x/s.vtt", language="en", codec=Subtitle.Codec.WebVTT, note="webvtt-lssdh")
copies = [deserialize_video(serialize_video_track(v)), deserialize_audio(serialize_audio_track(a))]
copies += [deserialize_subtitle(serialize_subtitle_track(s))]
copies += [Track.from_dict(t.to_dict()) for t in (v, a, s)]
copies += [track_from_dict(track_to_dict(t)) for t in (v, a, s)]
for copy in copies:
assert copy.note and str(copy).endswith(f"| {copy.note}")
assert copy.edition == []
@@ -299,7 +299,7 @@ def test_reconstruct_drm_keeps_the_default_kid_of_a_pssh_without_kids():
from pywidevine.pssh import PSSH
from unshackle.core.drm import real_kids
from unshackle.core.remote_service import reconstruct_drm
from unshackle.core.wire import reconstruct_drm
content_id_only = PSSH.new(system_id=PSSH.SystemId.Widevine, init_data=b"\x22\x03abc")
(drm,) = reconstruct_drm([{"type": "widevine", "pssh": content_id_only.dumps(), "kids": [str(KID)]}])
+2 -1
View File
@@ -11,9 +11,10 @@ import requests
import responses
from langcodes import Language
from unshackle.core.remote_service import RemoteClient, RemoteError, RemoteService, build_title, quiet
from unshackle.core.remote_service import RemoteClient, RemoteError, RemoteService, quiet
from unshackle.core.tracks import Audio
from unshackle.core.tracks.track import Track
from unshackle.core.wire import build_title
pytestmark = pytest.mark.unit