Skip to content

Commit

Permalink
Fix Wimp images not resolving and some tests with incorrect resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
ktnrg45 authored and morguldir committed Dec 4, 2020
1 parent c5a89b6 commit 7a288be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'


Expand All @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion tidalapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'),
Expand Down Expand Up @@ -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']),
Expand Down
37 changes: 22 additions & 15 deletions tidalapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
"""
Expand All @@ -51,31 +53,34 @@ 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):
roles = []
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):
Expand All @@ -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):
Expand Down

0 comments on commit 7a288be

Please sign in to comment.