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
@@ -12,13 +12,12 @@ import pytest
import requests
from Cryptodome.Cipher import Blowfish
from unshackle.core.api.handlers import serialize_audio_track, serialize_drm
from unshackle.core.config import config
from unshackle.core.constants import DOWNLOAD_CANCELLED
from unshackle.core.drm import BlowfishStripe
from unshackle.core.remote_service import build_tracks, reconstruct_drm
from unshackle.core.tracks import Audio, Track
from unshackle.core.tracks import track as track_module
from unshackle.core.wire import build_tracks, reconstruct_drm, serialize_audio_track, serialize_drm
KEY = bytes.fromhex("00112233445566778899aabbccddeeff")
CHUNK = BlowfishStripe.CHUNK
+1 -1
View File
@@ -20,9 +20,9 @@ import pytest
# lxml.etree: XML parser used to build ContentProtection fixtures for DASH.get_drm
from lxml import etree
from unshackle.core.drm import drm_from_dict
from unshackle.core.drm.clearkey_cenc import ClearKeyCENC
from unshackle.core.manifests.dash import DASH
from unshackle.core.wire import drm_from_dict
KID = UUID("9eb4050d-e44b-4802-932e-27d75083e266")
KEY = bytes.fromhex("ccd0064c43f7e9fcbaa9b12af3fd1f40")
+1 -1
View File
@@ -5,8 +5,8 @@ from __future__ import annotations
from types import SimpleNamespace
from unshackle.commands.dl import dl
from unshackle.core.remote_service import apply_title_fields
from unshackle.core.titles.episode import Episode, Series
from unshackle.core.wire import apply_title_fields
class DummyService:
+1 -2
View File
@@ -7,10 +7,9 @@ from datetime import date
import pytest
from unshackle.commands.dl import dl
from unshackle.core.api.handlers import serialize_title
from unshackle.core.config import Config, config
from unshackle.core.remote_service import build_title
from unshackle.core.titles.episode import Episode
from unshackle.core.wire import build_title, serialize_title
SERIES = "{title}.{year?}.{season_episode}.{episode_name?}.{quality?}-{tag?}"
SPORTS = "{title}.{year?}.{date?}.{episode_name}.{quality?}-{tag?}"
+1 -1
View File
@@ -19,12 +19,12 @@ import click
import pytest
from unshackle.commands.dl import dl
from unshackle.core.drm import drm_from_dict
from unshackle.core.drm.clearkey import ClearKey
from unshackle.core.drm.clearkey_cenc import ClearKeyCENC
from unshackle.core.import_service import ImportService
from unshackle.core.titles import Movie
from unshackle.core.tracks import Audio, Chapter, Subtitle, Video
from unshackle.core.wire import drm_from_dict
KID = UUID(hex="00000000000000000000000000000001")
+3 -2
View File
@@ -13,6 +13,7 @@ from unshackle.core.remote_service import RemoteService
from unshackle.core.tracks import Audio, Video
from unshackle.core.utils import hdr10plus
from unshackle.core.utils.hdr10plus import HDR10PLUS_T35, TS_PACKET, fragment_has_t35
from unshackle.core.wire import track_from_dict, track_to_dict
def box(kind: bytes, body: bytes) -> bytes:
@@ -127,7 +128,7 @@ def test_a_dv_track_with_hdr10plus_lists_as_dv_plus_hdr10p() -> None:
assert "[H.265, DV]" in str(video)
video.hdr10plus = True
assert "[H.265, DV+HDR10P]" in str(video)
assert Video.from_dict(video.to_dict()).hdr10plus
assert track_from_dict(track_to_dict(video)).hdr10plus
def test_on_start_runs_only_when_there_is_a_track_to_probe(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -229,7 +230,7 @@ def test_a_quoted_dl_workers_value_works_like_the_cli(monkeypatch: pytest.Monkey
def test_a_dv_track_with_an_hdr10_base_lists_as_dv_plus_hdr10() -> None:
video = Video(url="https://x/v.mp4", language="en", codec=Video.Codec.HEVC, range_=Video.Range.DV, hdr10_base=True)
assert "[H.265, DV+HDR10]" in str(video)
assert Video.from_dict(video.to_dict()).hdr10_base
assert track_from_dict(track_to_dict(video)).hdr10_base
def ts_packet(pid: int, section: bytes) -> bytes:
+1 -1
View File
@@ -3,9 +3,9 @@ from types import SimpleNamespace
from langcodes import Language
from unshackle.commands.dl import apply_enrich, load_tracks
from unshackle.core.remote_service import apply_title_fields
from unshackle.core.titles import Episode, Movie, Song
from unshackle.core.tracks import Chapters, Tracks
from unshackle.core.wire import apply_title_fields
SERVICE = type("SVC", (), {})
+4 -3
View File
@@ -16,6 +16,7 @@ from unshackle.core.manifests import snapshot as snapshot_module
from unshackle.core.manifests.snapshot import capture, parse, restore
from unshackle.core.tracks import Tracks
from unshackle.core.tracks.track import Track
from unshackle.core.wire import track_from_dict, track_to_dict
URL = "https://cdn.example/title/manifest.mpd"
@@ -116,7 +117,7 @@ def round_trip(tracks: Tracks, level: int = -1) -> Tracks:
assert {"manifests", "track_manifests"} <= set(snapshot)
client = Tracks()
for track in tracks:
client.add(Track.from_dict(track.to_dict()))
client.add(track_from_dict(track_to_dict(track)))
restore(client, snapshot)
return client
@@ -174,7 +175,7 @@ def test_a_filtered_period_that_reuses_a_kept_id_keeps_the_content():
@pytest.mark.parametrize("snapshot", ["garbage", {"manifests": "x"}, {"manifests": [1]}, {"track_manifests": {"a": 1}}])
def test_a_malformed_snapshot_restores_nothing(snapshot):
client = Tracks()
client.add(Track.from_dict(service_tracks().videos[0].to_dict()))
client.add(track_from_dict(track_to_dict(service_tracks().videos[0])))
restore(client, snapshot)
assert not client.videos[0].data.get("dash")
assert parse(snapshot, URL, "en") is None
@@ -193,7 +194,7 @@ def test_the_inflate_budget_covers_every_entry_of_one_restore(monkeypatch, caplo
assert parse(saved, URL, "en") is not None
client = Tracks()
client.add(Track.from_dict(service_tracks().videos[0].to_dict()))
client.add(track_from_dict(track_to_dict(service_tracks().videos[0])))
with caplog.at_level(logging.WARNING, logger="snapshot"):
restore(client, saved)
assert client.videos[0].data.get("dash")
+2 -1
View File
@@ -16,10 +16,11 @@ from pyplayready.system.wrmheader import WRMHeader
from pywidevine.pssh import PSSH as WV_PSSH
from unshackle.core.api.handlers import pssh_kids
from unshackle.core.drm import PlayReady, Widevine, drm_from_dict
from unshackle.core.drm import PlayReady, Widevine
from unshackle.core.manifests.dash import DASH
from unshackle.core.manifests.hls import HLS
from unshackle.core.manifests.ism import ISM
from unshackle.core.wire import drm_from_dict
KID = UUID("00112233-4455-6677-8899-aabbccddeeff")
KID_B64 = base64.b64encode(KID.bytes_le).decode()
+2 -1
View File
@@ -20,6 +20,7 @@ from unshackle.core.titles.movie import Movie
from unshackle.core.tracks import Audio, Chapter, Chapters, Track, Tracks, Video
from unshackle.core.tracks import tracks as tracks_module
from unshackle.core.tracks.tracks import pick_video
from unshackle.core.wire import track_from_dict, track_to_dict
VIDEO_IDS = itertools.count()
@@ -59,7 +60,7 @@ def test_hls_marks_stereo_tracks_from_the_layout_or_the_codec() -> None:
def test_a_stereo_track_lists_as_3d_and_keeps_the_flag_through_to_dict() -> None:
video = Video(url="https://x/v.mp4", language="en", codec=Video.Codec.HEVC, range_=Video.Range.DV, stereo=True)
assert str(video).startswith("VID | [H.265, DV, 3D] |")
assert Video.from_dict(video.to_dict()).stereo
assert track_from_dict(track_to_dict(video)).stereo
def stereo_video(tmp_path: Path, stereo: bool = True, **kwargs: Any) -> Video:
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -8,8 +8,9 @@ import pytest
from pyplayready.system.pssh import PSSH as PlayReadyPSSH
from pywidevine.pssh import PSSH as WidevinePSSH
from unshackle.core.drm import PlayReady, Widevine, drm_from_dict, key_args
from unshackle.core.drm import PlayReady, Widevine, key_args
from unshackle.core.drm.key_args import ZERO_KID
from unshackle.core.wire import drm_from_dict
VIDEO_KID = UUID("00112233-4455-6677-8899-aabbccddeeff")
AUDIO_KID = UUID("ffeeddcc-bbaa-9988-7766-554433221100")