mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 23:45:07 +00:00
fix(tracks): show the audio bit depth and sample rate in the track listing only for a song
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from rich.text import Text
|
||||
|
||||
from tests.core.test_music_renderer import flac_release, run_release
|
||||
from tests.lang_selection.test_kind_only_selection import FakeService
|
||||
from unshackle.core.manifests.dash import DASH
|
||||
from unshackle.core.manifests.hls import HLS
|
||||
from unshackle.core.manifests.ism import ISM
|
||||
from unshackle.core.music.renderer import MusicRenderer
|
||||
from unshackle.core.tracks import Audio, Tracks
|
||||
from unshackle.core.tracks import Audio, Tracks, Video
|
||||
|
||||
|
||||
def dash_audio(set_attrs: str = "", rep_attrs: str = "") -> Audio:
|
||||
@@ -73,19 +76,49 @@ def test_hls_reads_bit_depth_and_sample_rate_when_the_playlist_states_them(
|
||||
assert (audio.bit_depth, audio.sample_rate) == expected
|
||||
|
||||
|
||||
def listing(audio: Audio, music: bool) -> str:
|
||||
"""The audio line of the track listing as plain text."""
|
||||
(node,) = Tracks([audio]).tree(music=music)[0].children[0].children
|
||||
return Text.from_markup(str(node.label)).plain
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("bit_depth", "sample_rate", "label"),
|
||||
[(24, 96000, "24-bit / 96 kHz"), (16, 44100, "16-bit / 44.1 kHz"), (None, 48000, "48 kHz"), (24, None, "24-bit")],
|
||||
)
|
||||
def test_the_listing_shows_bit_depth_and_sample_rate(
|
||||
def test_a_music_listing_shows_bit_depth_and_sample_rate(
|
||||
bit_depth: int | None, sample_rate: int | None, label: str
|
||||
) -> None:
|
||||
audio = Audio(url="https://cdn.example/a.flac", language="en", bit_depth=bit_depth, sample_rate=sample_rate)
|
||||
assert f" | {label}" in str(audio)
|
||||
audio = Audio(
|
||||
url="https://cdn.example/a.flac", language="en", bitrate=900_000, bit_depth=bit_depth, sample_rate=sample_rate
|
||||
)
|
||||
assert f"| 900 kb/s | {label} | English" in listing(audio, music=True)
|
||||
|
||||
|
||||
def test_the_listing_shows_neither_when_unset() -> None:
|
||||
assert "bit" not in str(Audio(url="https://cdn.example/a.flac", language="en"))
|
||||
def test_a_music_listing_shows_neither_when_unset() -> None:
|
||||
assert "bit" not in listing(Audio(url="https://cdn.example/a.flac", language="en"), music=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("list_", [True, False], ids=["list", "download"])
|
||||
@pytest.mark.parametrize("song", [True, False], ids=["song", "episode"])
|
||||
def test_dl_shows_the_label_only_for_a_song(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, song: bool, list_: bool
|
||||
) -> None:
|
||||
album, tracks = flac_release()
|
||||
titles = album if song else FakeService({1: {}}).get_titles()
|
||||
if not song:
|
||||
tracks.add(Video(id_="v", url="https://x/v", language="en", codec=Video.Codec.AVC, range_=Video.Range.SDR))
|
||||
monkeypatch.setattr("unshackle.commands.dl.mux_title", lambda *a, **k: ([], []))
|
||||
out = run_release(monkeypatch, caplog, titles, tracks, list_=list_, to_end=True) # type: ignore[arg-type]
|
||||
assert "3075 kb/s" in out
|
||||
assert ("3075 kb/s | 24-bit / 96 kHz" in out) is song
|
||||
|
||||
|
||||
def test_a_video_listing_shows_neither() -> None:
|
||||
audio = Audio(url="https://cdn.example/a.mp4", language="en", bit_depth=24, sample_rate=48000)
|
||||
text = listing(audio, music=False)
|
||||
assert "English" in text
|
||||
assert "kHz" not in text and "24-bit" not in text
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["24", 24.0])
|
||||
|
||||
Reference in New Issue
Block a user