Skip to content

Commit 7a288be

Browse files
ktnrg45morguldir
authored andcommitted
Fix Wimp images not resolving and some tests with incorrect resolutions
1 parent c5a89b6 commit 7a288be

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

tests/test_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_get_album_videos(session):
9696
assert videos[0].album.name == 'Lemonade'
9797
assert videos[1].name == 'Lemonade Film'
9898
assert videos[1].track_num == 15
99-
assert videos[1].duration == 3955
99+
assert videos[1].duration == 3951
100100

101101

102102
def test_get_album_items(session):
@@ -108,7 +108,7 @@ def test_get_album_items(session):
108108
assert items[0].album.name == 'Lemonade'
109109
assert items[-1].name == 'Lemonade Film'
110110
assert items[-1].track_num == 15
111-
assert items[-1].duration == 3955
111+
assert items[-1].duration == 3951
112112
assert items[-1].type == 'Music Video'
113113

114114

@@ -125,8 +125,8 @@ def test_search(session):
125125

126126
def test_artist_picture(session):
127127
artist = session.get_artist(16147)
128-
assert requests.get(artist.picture(640,640)).status_code == 200
129-
assert requests.get(tidalapi.models.Artist.image.fget(artist, 640, 640)).status_code == 200
128+
assert requests.get(artist.picture(750,750)).status_code == 200
129+
assert requests.get(tidalapi.models.Artist.image.fget(artist, 750, 750)).status_code == 200
130130

131131

132132
def test_album_picture(session):

tidalapi/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _parse_artist(json_obj):
286286
for role in json_obj.get('artistTypes', [json_obj.get('type')]):
287287
roles.append(Role(role))
288288

289-
return Artist(id=json_obj['id'], name=json_obj['name'], roles=roles, role=roles[0])
289+
return Artist(id=json_obj['id'], name=json_obj['name'], img_uuid=json_obj.get('picture'), roles=roles, role=roles[0])
290290

291291

292292
def _parse_artists(json_obj):
@@ -301,6 +301,7 @@ def _parse_album(json_obj, artist=None, artists=None):
301301
kwargs = {
302302
'id': json_obj['id'],
303303
'name': json_obj['title'],
304+
'img_uuid': json_obj.get('cover'),
304305
'num_tracks': json_obj.get('numberOfTracks'),
305306
'num_discs': json_obj.get('numberOfVolumes'),
306307
'duration': json_obj.get('duration'),
@@ -328,6 +329,7 @@ def _parse_playlist(json_obj):
328329
kwargs = {
329330
'id': json_obj['uuid'],
330331
'name': json_obj['title'],
332+
'img_uuid': json_obj.get('squareImage'),
331333
'description': json_obj['description'],
332334
'num_tracks': int(json_obj['numberOfTracks']),
333335
'duration': int(json_obj['duration']),

tidalapi/models.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
from __future__ import unicode_literals
2121
from enum import Enum
2222

23-
IMG_URL = "http://images.osl.wimpmusic.com/im/im?w={width}&h={height}&{id_type}={id}"
23+
IMG_URL = "https://resources.tidal.com/images/{uuid}/{width}x{height}.jpg"
2424

2525

2626
class Model(object):
2727
id = None
2828
name = None
29+
img_uuid = None
2930

3031
def __init__(self, **kwargs):
3132
self.__dict__.update(kwargs)
@@ -40,7 +41,8 @@ class Album(Model):
4041

4142
@property
4243
def image(self, width=1280, height=1280):
43-
return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid')
44+
uuid = self.img_uuid.replace('-', '/')
45+
return IMG_URL.format(uuid=uuid, width=width, height=height)
4446

4547
def picture(self, width, height):
4648
"""
@@ -51,31 +53,34 @@ def picture(self, width, height):
5153
:param height: pixel height, maximum 2000
5254
:type height: int
5355
54-
Original sizes: 80x80, 160x160, 320x320, 640x640 and 1280x1280
56+
Accepted sizes: 80x80, 160x160, 320x320, 640x640 and 1280x1280
5557
"""
56-
return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid')
58+
uuid = self.img_uuid.replace('-', '/')
59+
return IMG_URL.format(uuid=uuid, width=width, height=height)
5760

5861

5962
class Artist(Model):
6063
roles = []
6164
role = None
6265

6366
@property
64-
def image(self, width=1280, height=1280):
65-
return IMG_URL.format(width=width, height=height, id=self.id, id_type='artistid')
67+
def image(self, width=750, height=750):
68+
uuid = self.img_uuid.replace('-', '/')
69+
return IMG_URL.format(uuid=uuid, width=width, height=height)
6670

6771
def picture(self, width, height):
6872
"""
6973
A url to an artist picture
7074
71-
:param width: pixel width, maximum 2000
75+
:param width: pixel width, maximum 750
7276
:type width: int
73-
:param height: pixel height, maximum 2000
77+
:param height: pixel height, maximum 750
7478
:type height: int
7579
76-
Original sizes: 80x80, 160x160, 320x320, 480x480, 640x640, 1280x1280
80+
Accepted sizes: 80x80, 160x160, 320x320, 480x480, 750x750
7781
"""
78-
return IMG_URL.format(width=width, height=height, id=self.id, id_type='artistid')
82+
uuid = self.img_uuid.replace('-', '/')
83+
return IMG_URL.format(uuid=uuid, width=width, height=height)
7984

8085

8186
class Playlist(Model):
@@ -90,21 +95,23 @@ class Playlist(Model):
9095

9196
@property
9297
def image(self, width=1080, height=1080):
93-
return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid')
98+
uuid = self.img_uuid.replace('-', '/')
99+
return IMG_URL.format(uuid=uuid, width=width, height=height)
94100

95101
def picture(self, width, height):
96102
"""
97103
A url to a playlist picture
98104
99-
:param width: pixel width, maximum 2000
105+
:param width: pixel width, maximum 1080
100106
:type width: int
101-
:param height: pixel height, maximum 2000
107+
:param height: pixel height, maximum 1080
102108
:type height: int
103109
104-
Original sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080
110+
Accepted sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080
105111
106112
"""
107-
return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid')
113+
uuid = self.img_uuid.replace('-', '/')
114+
return IMG_URL.format(uuid=uuid, width=width, height=height)
108115

109116

110117
class Media(Model):

0 commit comments

Comments
 (0)