feat(tracks): add Audio bit_depth and sample_rate from manifests and carry them over remote

This commit is contained in:
imSp4rky
2026-12-02 15:24:01 -07:00
parent 2c305c475f
commit 3b6bd02e46
14 changed files with 268 additions and 35 deletions
+35 -3
View File
@@ -131,7 +131,12 @@ def song() -> Song:
disc=1,
year=2022,
language="en",
data={"release_date": "2022-01-02", "composer": "Example Composer", "metadata": {"comment": "nested"}},
data={
"release_date": "2022-01-02",
"composer": "Example Composer",
"sample_rate": 96000,
"metadata": {"comment": "nested"},
},
album_artist="Example Band",
release_type="single",
total_tracks=12,
@@ -205,6 +210,8 @@ def audio(**extra: Any) -> Audio:
channels="5.1",
joc=16,
descriptive=True,
bit_depth=24,
sample_rate=48000,
id_="audio-0001",
)
fields.update(extra)
@@ -283,6 +290,8 @@ def track_fields(track: Any) -> dict[str, Any]:
joc=track.joc,
atmos=track.atmos,
descriptive=track.descriptive,
bit_depth=track.bit_depth,
sample_rate=track.sample_rate,
)
elif isinstance(track, Subtitle):
out.update(cc=track.cc, sdh=track.sdh, forced=track.forced)
@@ -402,7 +411,12 @@ REST_SONG = {
"lyrics_suffix": ".lrc",
"artwork_url": "https://img.example/song.jpg",
"position": 7,
"music_data": {"release_date": "2022-01-02", "composer": "Example Composer", "comment": "nested"},
"music_data": {
"release_date": "2022-01-02",
"composer": "Example Composer",
"sample_rate": 96000,
"comment": "nested",
},
}
META_EPISODE = {
@@ -478,6 +492,8 @@ REST_AUDIO = {
"atmos": True,
"joc": 16,
"descriptive": True,
"bit_depth": 24,
"sample_rate": 48000,
"language": "en",
"is_original_lang": False,
"name": None,
@@ -552,6 +568,8 @@ EXPORT_AUDIO = {
"channels": 5.1,
"joc": 16,
"descriptive": True,
"bit_depth": 24,
"sample_rate": 48000,
}
EXPORT_SUBTITLE = {
@@ -618,6 +636,8 @@ AUDIO_FIELDS = {
"joc": 16,
"atmos": True,
"descriptive": True,
"bit_depth": 24,
"sample_rate": 48000,
}
SUBTITLE_FIELDS = {
@@ -784,7 +804,12 @@ def test_build_title_from_rest_song() -> None:
"id": "song-0001",
"language": "en",
"year": 2022,
"data": {"release_date": "2022-01-02", "composer": "Example Composer", "comment": "nested"},
"data": {
"release_date": "2022-01-02",
"composer": "Example Composer",
"sample_rate": 96000,
"comment": "nested",
},
"name": "Example Song",
**{key: REST_SONG[key] for key in SONG_FIELDS},
}
@@ -921,6 +946,11 @@ def test_export_audio() -> None:
assert list(audio().to_dict()) == list(EXPORT_AUDIO)
def test_export_audio_from_an_older_version_has_no_bit_depth_or_sample_rate() -> None:
old = {k: v for k, v in json_copy(EXPORT_AUDIO).items() if k not in ("bit_depth", "sample_rate")}
assert track_fields(track_from_dict(old)) == {**AUDIO_FIELDS, "bit_depth": None, "sample_rate": None}
def test_export_subtitle() -> None:
assert subtitle().to_dict() == EXPORT_SUBTITLE
assert list(subtitle().to_dict()) == list(EXPORT_SUBTITLE)
@@ -986,6 +1016,8 @@ def test_deserialize_a_track_from_an_older_server() -> None:
"joc": None,
"atmos": True,
"descriptive": False,
"bit_depth": None,
"sample_rate": None,
}
odd_subtitle = deserialize_subtitle({"id": "s-old", "codec": "NOPE", "note": 5})
assert track_fields(odd_subtitle) == {