From 7a288be75a2766d0deca3a3c01a88c720a62ebd6 Mon Sep 17 00:00:00 2001 From: ktnrg45 Date: Thu, 9 Jul 2020 19:41:16 -0700 Subject: [PATCH] Fix Wimp images not resolving and some tests with incorrect resolutions --- tests/test_api.py | 8 ++++---- tidalapi/__init__.py | 4 +++- tidalapi/models.py | 37 ++++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 500979d..ebf8284 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -96,7 +96,7 @@ def test_get_album_videos(session): assert videos[0].album.name == 'Lemonade' assert videos[1].name == 'Lemonade Film' assert videos[1].track_num == 15 - assert videos[1].duration == 3955 + assert videos[1].duration == 3951 def test_get_album_items(session): @@ -108,7 +108,7 @@ def test_get_album_items(session): assert items[0].album.name == 'Lemonade' assert items[-1].name == 'Lemonade Film' assert items[-1].track_num == 15 - assert items[-1].duration == 3955 + assert items[-1].duration == 3951 assert items[-1].type == 'Music Video' @@ -125,8 +125,8 @@ def test_search(session): def test_artist_picture(session): artist = session.get_artist(16147) - assert requests.get(artist.picture(640,640)).status_code == 200 - assert requests.get(tidalapi.models.Artist.image.fget(artist, 640, 640)).status_code == 200 + assert requests.get(artist.picture(750,750)).status_code == 200 + assert requests.get(tidalapi.models.Artist.image.fget(artist, 750, 750)).status_code == 200 def test_album_picture(session): diff --git a/tidalapi/__init__.py b/tidalapi/__init__.py index 20c3d19..27be0b5 100644 --- a/tidalapi/__init__.py +++ b/tidalapi/__init__.py @@ -286,7 +286,7 @@ def _parse_artist(json_obj): for role in json_obj.get('artistTypes', [json_obj.get('type')]): roles.append(Role(role)) - return Artist(id=json_obj['id'], name=json_obj['name'], roles=roles, role=roles[0]) + return Artist(id=json_obj['id'], name=json_obj['name'], img_uuid=json_obj.get('picture'), roles=roles, role=roles[0]) def _parse_artists(json_obj): @@ -301,6 +301,7 @@ def _parse_album(json_obj, artist=None, artists=None): kwargs = { 'id': json_obj['id'], 'name': json_obj['title'], + 'img_uuid': json_obj.get('cover'), 'num_tracks': json_obj.get('numberOfTracks'), 'num_discs': json_obj.get('numberOfVolumes'), 'duration': json_obj.get('duration'), @@ -328,6 +329,7 @@ def _parse_playlist(json_obj): kwargs = { 'id': json_obj['uuid'], 'name': json_obj['title'], + 'img_uuid': json_obj.get('squareImage'), 'description': json_obj['description'], 'num_tracks': int(json_obj['numberOfTracks']), 'duration': int(json_obj['duration']), diff --git a/tidalapi/models.py b/tidalapi/models.py index 7300af4..a70363d 100644 --- a/tidalapi/models.py +++ b/tidalapi/models.py @@ -20,12 +20,13 @@ from __future__ import unicode_literals from enum import Enum -IMG_URL = "http://images.osl.wimpmusic.com/im/im?w={width}&h={height}&{id_type}={id}" +IMG_URL = "https://resources.tidal.com/images/{uuid}/{width}x{height}.jpg" class Model(object): id = None name = None + img_uuid = None def __init__(self, **kwargs): self.__dict__.update(kwargs) @@ -40,7 +41,8 @@ class Album(Model): @property def image(self, width=1280, height=1280): - return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid') + uuid = self.img_uuid.replace('-', '/') + return IMG_URL.format(uuid=uuid, width=width, height=height) def picture(self, width, height): """ @@ -51,9 +53,10 @@ def picture(self, width, height): :param height: pixel height, maximum 2000 :type height: int - Original sizes: 80x80, 160x160, 320x320, 640x640 and 1280x1280 + Accepted sizes: 80x80, 160x160, 320x320, 640x640 and 1280x1280 """ - return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid') + uuid = self.img_uuid.replace('-', '/') + return IMG_URL.format(uuid=uuid, width=width, height=height) class Artist(Model): @@ -61,21 +64,23 @@ class Artist(Model): role = None @property - def image(self, width=1280, height=1280): - return IMG_URL.format(width=width, height=height, id=self.id, id_type='artistid') + def image(self, width=750, height=750): + uuid = self.img_uuid.replace('-', '/') + return IMG_URL.format(uuid=uuid, width=width, height=height) def picture(self, width, height): """ A url to an artist picture - :param width: pixel width, maximum 2000 + :param width: pixel width, maximum 750 :type width: int - :param height: pixel height, maximum 2000 + :param height: pixel height, maximum 750 :type height: int - Original sizes: 80x80, 160x160, 320x320, 480x480, 640x640, 1280x1280 + Accepted sizes: 80x80, 160x160, 320x320, 480x480, 750x750 """ - return IMG_URL.format(width=width, height=height, id=self.id, id_type='artistid') + uuid = self.img_uuid.replace('-', '/') + return IMG_URL.format(uuid=uuid, width=width, height=height) class Playlist(Model): @@ -90,21 +95,23 @@ class Playlist(Model): @property def image(self, width=1080, height=1080): - return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid') + uuid = self.img_uuid.replace('-', '/') + return IMG_URL.format(uuid=uuid, width=width, height=height) def picture(self, width, height): """ A url to a playlist picture - :param width: pixel width, maximum 2000 + :param width: pixel width, maximum 1080 :type width: int - :param height: pixel height, maximum 2000 + :param height: pixel height, maximum 1080 :type height: int - Original sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080 + Accepted sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080 """ - return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid') + uuid = self.img_uuid.replace('-', '/') + return IMG_URL.format(uuid=uuid, width=width, height=height) class Media(Model):