Skip to content

Commit 7d765c3

Browse files
Nokse22tehkillerbee
authored andcommitted
Add Track.get_radio_mix and Artist.get_radio_mix to get radio as Mix
1 parent f45189e commit 7d765c3

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/test_artist.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def test_get_radio(session):
140140
assert radio[0].artist.name == artist.name
141141

142142

143+
def test_get_radio_mix(session):
144+
artist = session.artist(3514310)
145+
radio = artist.get_radio_mix()
146+
assert radio.id == "000038b3b74d5ce3a17b43a36d62bb"
147+
148+
143149
def test_artist_image(session):
144150
artist = session.artist(4822757)
145151
verify_image_cover(session, artist, [160, 320, 480, 750])

tests/test_media.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ def test_get_track_radio_limit_100(session):
448448
assert len(similar_tracks) == 100
449449

450450

451+
def test_get_radio_mix(session):
452+
track = session.track(12445712)
453+
radio = track.get_radio_mix()
454+
assert radio.id == "001c2cbc32b5b7c17f8c0aa55d9541"
455+
456+
451457
def test_get_stream_bts(session):
452458
track = session.track(77646170) # Beck: Sea Change, Track: The Golden Age
453459
# Set session as BTS type (i.e. low_320k/HIGH Quality)

tidalapi/artist.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from tidalapi.exceptions import ObjectNotFound, TooManyRequests
2929
from tidalapi.types import JsonObj
3030

31+
from . import mix
32+
3133
if TYPE_CHECKING:
3234
from tidalapi.album import Album
3335
from tidalapi.media import Track, Video
@@ -242,6 +244,16 @@ def get_radio(self) -> List["Track"]:
242244
),
243245
)
244246

247+
def get_radio_mix(self) -> mix.Mix:
248+
"""Queries TIDAL for the artist radio, which is a mix of tracks that are similar
249+
to what the artist makes.
250+
251+
:return: A :class:`Mix <tidalapi.mix.Mix>`
252+
"""
253+
json = self.request.request("GET", f"artists/{self.id}/mix").json()
254+
255+
return self.session.mix(json.get("id"))
256+
245257
def items(self) -> List[NoReturn]:
246258
"""The artist page does not supply any items. This only exists for symmetry with
247259
other model types.

tidalapi/media.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
)
5252
from tidalapi.types import JsonObj
5353

54+
from . import mix
55+
5456

5557
class Quality(str, Enum):
5658
low_96k: str = "LOW"
@@ -407,6 +409,16 @@ def get_track_radio(self, limit: int = 100) -> List["Track"]:
407409
assert isinstance(tracks, list)
408410
return cast(List["Track"], tracks)
409411

412+
def get_radio_mix(self) -> mix.Mix:
413+
"""Queries TIDAL for the track radio, which is a mix of tracks that are similar
414+
to this track.
415+
416+
:return: A :class:`Mix <tidalapi.mix.Mix>`
417+
"""
418+
json = self.request.request("GET", f"tracks/{self.id}/mix").json()
419+
420+
return self.session.mix(json.get("id"))
421+
410422
def get_stream(self) -> "Stream":
411423
"""Retrieves the track streaming object, allowing for audio transmission.
412424

0 commit comments

Comments
 (0)