🏷️ add not required to TrackResponse

This commit is contained in:
oskvr37
2024-07-30 21:39:47 +02:00
parent d6eb7c9bc6
commit 1a44f1002e
2 changed files with 10 additions and 7 deletions
+6 -4
View File
@@ -131,12 +131,14 @@ def main():
track = api.getTrack(int(track_id), track_quality)
quality = TRACK_QUALITY[track["audioQuality"]]
# qualities below master dont have `bitDepth` and `sampleRate`
# TODO: add special types for master quality 🏷️
MASTER_QUALITIES: list[TrackQuality] = ["HI_RES_LOSSLESS", "LOSSLESS"]
if track["audioQuality"] in MASTER_QUALITIES:
details = f"{track['bitDepth']} bit {track['sampleRate']/1000:.1f} kHz"
bit_depth, sample_rate = track.get("bitDepth"), track.get("sampleRate")
if bit_depth is None or sample_rate is None:
raise ValueError(
"bitDepth and sampleRate must be provided for master qualities"
)
details = f"{bit_depth} bit {sample_rate/1000:.1f} kHz"
else:
details = quality["details"]
+4 -3
View File
@@ -1,9 +1,10 @@
from typing import TypedDict, Optional, List, Any, Literal
from typing import TypedDict, Optional, List, Any, Literal, NotRequired
TrackQuality = Literal["LOW", "HIGH", "LOSSLESS", "HI_RES_LOSSLESS"]
TrackArg = Literal["low", "normal", "high", "master"]
class QualityDetails(TypedDict):
name: str
details: str
@@ -135,5 +136,5 @@ class TrackResponse(TypedDict):
albumPeakAmplitude: float
trackReplayGain: float
trackPeakAmplitude: float
bitDepth: int
sampleRate: int
bitDepth: NotRequired[int]
sampleRate: NotRequired[int]