Skip to content

Commit 5164a23

Browse files
authored
Merge pull request #386 from EbbLabs/feature/fix-unavailable-tracks
Feature/fix unavailable tracks
2 parents 183a7a6 + 3edec0a commit 5164a23

File tree

9 files changed

+337
-101
lines changed

9 files changed

+337
-101
lines changed

HISTORY.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ History
55

66
v0.8.9
77
--------
8+
* Bugfix: Return correct Exception, depending on status_code (404, 429). Add missing Raise, comments. Fixes #385 - tehkillerbee_
9+
* Added missing fields to Media, Tracks, Videos. Updated tests - tehkillerbee_
10+
* Bugfix: Handle Unavailable tracks gracefully. - tehkillerbee_
811
* Bugfix: Favorite videos default limit incorrect - tehkillerbee_
912
* Tests: Added get_favorite_* tests - tehkillerbee_
1013

tests/test_genres.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ def test_get_genres(session):
2929

3030

3131
def test_get_items(session):
32-
genres = list(session.genre.get_genres())
33-
genres[0].items(tidalapi.Album)
34-
with pytest.raises(TypeError):
32+
genres = session.genre.get_genres()
33+
first_genre = genres[0]
34+
# Note: Some (all?) genres appear to have albums, tracks but the endpoint is invalid, resulting in an error. Why?
35+
# if first_genre.albums:
36+
# genres[0].items(tidalapi.Album)
37+
# if first_genre.tracks:
38+
# genres[0].items(tidalapi.Track)
39+
if first_genre.artists:
3540
genres[0].items(tidalapi.Artist)
36-
genres[0].items(tidalapi.Track)
37-
genres[0].items(tidalapi.Video)
38-
genres[0].items(tidalapi.Playlist)
41+
if first_genre.videos:
42+
genres[0].items(tidalapi.Video)
43+
if first_genre.playlists:
44+
genres[0].items(tidalapi.Playlist)
3945

4046

4147
def test_get_electronic_items(session):

tests/test_media.py

Lines changed: 116 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,115 @@ def test_media(session):
4444
def test_track(session):
4545
track = session.track(125169484)
4646

47-
assert track.name == "Alone, Pt. II"
47+
# Basic metadata
48+
assert track.id == 125169484
49+
assert track.title == "Alone, Pt. II"
50+
assert track.name == track.title
51+
assert track.version is None
52+
assert track.full_name == track.title # Version is none, full_name == title
4853
assert track.duration == 179
49-
assert track.replay_gain == -10.4
50-
assert track.peak == 0.988312
54+
assert track.explicit is False
55+
assert track.popularity == 73
5156
assert track.available is True
52-
assert track.tidal_release_date == datetime(2019, 12, 27, 0, 0, tzinfo=tz.tzutc())
57+
assert track.stream_start_date == datetime(2019, 12, 27, 0, 0, tzinfo=tz.tzutc())
58+
assert track.tidal_release_date == track.stream_start_date
59+
assert track.date_added is None
60+
assert track.user_date_added == track.user_date_added
5361
assert track.track_num == 1
5462
assert track.volume_num == 1
55-
assert track.version is None
56-
assert (
57-
track.copyright
58-
== "(P) 2019 Kreatell Music under exclusive license to Sony Music Entertainment Sweden AB"
59-
)
60-
assert track.isrc == "NOG841907010"
61-
assert track.explicit is False
62-
assert track.audio_quality == tidalapi.Quality.high_lossless
63+
64+
# Album
6365
assert track.album.name == "Alone, Pt. II"
6466
assert track.album.id == 125169472
67+
assert track.album.cover == "345d81fd-3a06-4fe4-b77a-6f6e28baad25"
68+
assert track.album.video_cover is None
69+
70+
# URLs
71+
assert track.url == "http://www.tidal.com/track/125169484"
6572
assert (
6673
track.listen_url == "https://listen.tidal.com/album/125169472/track/125169484"
6774
)
6875
assert track.share_url == "https://tidal.com/browse/track/125169484"
6976

77+
# Artist(s)
7078
assert track.artist.name == "Alan Walker"
79+
assert track.artist.picture == "c46be937-9869-4454-8d80-ba6a6e23b6c6"
7180
artist_names = [artist.name for artist in track.artists]
72-
assert [artist in artist_names for artist in ["Alan Walker", "Ava Max"]]
81+
for name in ["Alan Walker", "Ava Max"]:
82+
assert name in artist_names
83+
84+
# Audio / streaming
85+
assert track.audio_quality == tidalapi.Quality.high_lossless
86+
assert track.audio_modes == ["STEREO"]
87+
assert track.media_metadata_tags == ["LOSSLESS", "HIRES_LOSSLESS"]
88+
assert track.is_lossless is True
89+
assert track.is_hi_res_lossless is True
90+
assert track.is_dolby_atmos is False
91+
assert track.ad_supported_stream_ready is True
92+
assert track.allow_streaming is True
93+
assert track.stream_ready is True
94+
assert track.stem_ready is False
95+
assert track.dj_ready is True
96+
assert track.pay_to_stream is False
97+
assert track.premium_streaming_only is False
98+
assert track.access_type == "PUBLIC"
99+
100+
# Music metadata
101+
assert track.bpm == 88
102+
assert track.replay_gain == -10.4
103+
assert track.peak == 0.988312
104+
assert track.mixes == {"TRACK_MIX": "001603cb31f1842e052770e0ad7647"}
105+
assert track.key == "FSharp"
106+
assert track.key_scale == "MAJOR"
107+
assert track.allow_streaming is True
108+
assert track.pay_to_stream is False
109+
assert track.date_added is None # Missing
110+
assert track.description is None
111+
assert track.editable is False
112+
assert track.index is None
113+
assert track.item_uuid is None
114+
assert track.spotlighted is False
115+
assert track.upload is False
116+
117+
# Copyright / ISRC
118+
assert (
119+
track.copyright
120+
== "(P) 2019 Kreatell Music under exclusive license to Sony Music Entertainment Sweden AB"
121+
)
122+
assert track.isrc == "NOG841907010"
123+
124+
# Session / requests
125+
assert track.session is not None
126+
assert track.requests is not None
127+
128+
# Type info
129+
assert track.type is None
130+
assert track.artist_roles is None
131+
132+
133+
def test_unavailable_track(session):
134+
# Unavailable tracks are only "accessible" through playlist
135+
pl = session.playlist("93f6d95b-cdfe-4ee6-8c10-84098e265535")
136+
# Get an "Unavailable" track from playlist
137+
track = pl.tracks(1, 28)[0]
138+
# Unavailable track will have most of the below flags set to "False"
139+
assert track.available is False
140+
assert track.allow_streaming is False
141+
assert track.pay_to_stream is False
142+
assert track.premium_streaming_only is False
143+
assert track.editable is False
144+
assert track.upload is False
145+
assert track.spotlighted is False
146+
# Certain fields will have valid values
147+
assert track.id == 77909345
148+
assert track.title == "Fostul Remix"
149+
assert track.full_name == track.title
150+
assert track.url == "http://www.tidal.com/track/77909345"
151+
assert track.listen_url == "https://listen.tidal.com/album/77909343/track/77909345"
152+
assert track.share_url == "https://tidal.com/browse/track/77909345"
153+
154+
assert track.audio_quality == "LOSSLESS"
155+
assert track.audio_modes == ["STEREO"]
73156

74157

75158
def test_track_url(session):
@@ -304,20 +387,37 @@ def test_video(session):
304387
video = session.video(125506698)
305388

306389
assert video.id == 125506698
307-
assert video.name == "Alone, Pt. II"
390+
assert video.title == "Alone, Pt. II"
391+
assert video.name == video.title
308392
assert video.track_num == 0
309393
assert video.volume_num == 0
310394
assert video.release_date == datetime(2019, 12, 26, tzinfo=tz.tzutc())
311395
assert video.tidal_release_date == datetime(2019, 12, 27, 9, tzinfo=tz.tzutc())
312396
assert video.duration == 237
313397
assert video.video_quality == "MP4_1080P"
314-
assert video.available is True
315-
assert video.explicit is False
316398
assert video.type == "Music Video"
317399
assert video.album is None
400+
assert video.available is True
401+
assert video.explicit is False
402+
assert video.ad_supported_stream_ready is True # adSupportedStreamReady
403+
assert video.ads_pre_paywall_only is True # adsPrePaywallOnly
404+
assert video.ads_url is None # adsUrl
405+
assert video.allow_streaming is True # allowStreaming
406+
assert video.dj_ready is True # djReady
407+
assert video.stem_ready is False # stemReady
408+
assert video.stream_ready is True # streamReady
409+
410+
assert video.popularity == 21 # popularity
411+
assert video.image_id == "7f1160e3-bdc3-4764-810b-93194443913d" # imageId
412+
assert video.image_path is None # imagePath
413+
assert video.tidal_release_date == datetime(
414+
2019, 12, 27, 9, tzinfo=tz.tzutc()
415+
) # streamStartDate
416+
assert video.vibrant_color == "#e2f2e5" # vibrantColor
318417

319418
assert video.artist.name == "Alan Walker"
320419
assert video.artist.id == 6159368
420+
assert video.artist.picture == "c46be937-9869-4454-8d80-ba6a6e23b6c6"
321421
artist_names = [artist.name for artist in video.artists]
322422
assert [artist in artist_names for artist in ["Alan Walker", "Ava Max"]]
323423

tests/test_page.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ def test_page_iterator(session):
139139
def test_get_video_items(session):
140140
videos = session.videos()
141141
mix = videos.categories[1].items[0]
142-
for item in mix.items():
143-
assert isinstance(item, tidalapi.Video)
142+
items = mix.items()
143+
for item in items:
144+
# Video playlists might contain both tracks and videos
145+
assert isinstance(item, tidalapi.Video) or isinstance(item, tidalapi.Track)
144146

145147
assert len(mix.items()) >= 25
146148

0 commit comments

Comments
 (0)