Skip to content

Commit 2175f0d

Browse files
committed
Add ability to use different resolutions for album, artist and playlist images
Update tests to change resolution. Lower the amount of times tests login to tidal.
1 parent 795b85a commit 2175f0d

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

tests/test_api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
logging.basicConfig(level=logging.DEBUG)
2626

27-
@pytest.fixture()
27+
@pytest.fixture(scope='session')
2828
def session():
2929
session = tidalapi.Session()
3030
username = os.getenv("TIDAL_USERNAME")
@@ -108,17 +108,17 @@ def test_search(session):
108108
res = session.search('artist', 'lasgo')
109109
assert res.artists[0].name == "Lasgo"
110110

111-
def test_artist_image(session):
111+
def test_artist_picture(session):
112112
artist = session.get_artist(16147)
113-
assert requests.get(artist.image).status_code == 200
113+
assert requests.get(artist.picture(640,640)).status_code == 200
114114

115-
def test_album_image(session):
116-
artist = session.get_album(17925106)
117-
assert requests.get(artist.image).status_code == 200
115+
def test_album_picture(session):
116+
album = session.get_album(17925106)
117+
assert requests.get(album.picture(640, 640)).status_code == 200
118118

119-
def test_playlist_image(session):
119+
def test_playlist_picture(session):
120120
playlist = session.get_playlist('33136f5a-d93a-4469-9353-8365897aaf94')
121-
assert requests.get(playlist.image).status_code == 200
121+
assert requests.get(playlist.picture(750, 750)).status_code == 200
122122

123123
def test_get_track_url(session):
124124
track = session.get_track(108043415)

tidalapi/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ def __init__(self, quality=Quality.high, videoQuality=videoQuality.high):
5252
self.api_token = 'BI218mwp9ERZ3PFI' if self.quality == \
5353
Quality.lossless else '4zx46pyr9o8qZNRw',
5454

55-
5655
class Session(object):
57-
5856
def __init__(self, config=Config()):
5957
self.session_id = None
6058
self.country_code = None

tidalapi/models.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@ class Album(Model):
3838
release_date = None
3939

4040
@property
41-
def image(self, width=512, height=512):
41+
def image(self, width=1280, height=1280):
42+
return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid')
43+
44+
def picture(self, width, height):
45+
"""
46+
A url to an album picture
47+
48+
:param width: pixel width, maximum 2000
49+
:type width: int
50+
:param height: pixel height, maximum 2000
51+
:type height: int
52+
53+
Original sizes: 80x80, 160x160, 320x320, 640x640 and 1280x1280
54+
"""
4255
return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid')
4356

4457

@@ -47,7 +60,20 @@ class Artist(Model):
4760
role = None
4861

4962
@property
50-
def image(self, width=512, height=512):
63+
def image(self, width=1280, height=1280):
64+
return IMG_URL.format(width=height, height=height, id=self.id, id_type='artistid')
65+
66+
def picture(self, width, height):
67+
"""
68+
A url to an artist picture
69+
70+
:param width: pixel width, maximum 2000
71+
:type width: int
72+
:param height: pixel height, maximum 2000
73+
:type height: int
74+
75+
Original sizes: 80x80, 160x160, 320x320, 480x480, 640x640, 1280x1280
76+
"""
5177
return IMG_URL.format(width=width, height=height, id=self.id, id_type='artistid')
5278

5379

@@ -62,9 +88,24 @@ class Playlist(Model):
6288
duration = -1
6389

6490
@property
65-
def image(self, width=512, height=512):
91+
def image(self, width=1080, height=1080):
92+
return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid')
93+
94+
def picture(self, width, height):
95+
"""
96+
A url to a playlist picture
97+
98+
:param width: pixel width, maximum 2000
99+
:type width: int
100+
:param height: pixel height, maximum 2000
101+
:type height: int
102+
103+
Original sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080
104+
105+
"""
66106
return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid')
67107

108+
68109
class Media(Model):
69110
duration = -1
70111
track_num = -1
@@ -75,12 +116,15 @@ class Media(Model):
75116
album = None
76117
available = True
77118

119+
78120
class Track(Media):
79121
pass
80122

123+
81124
class Video(Media):
82125
type = None
83126

127+
84128
class SearchResult(Model):
85129
artists = []
86130
albums = []

0 commit comments

Comments
 (0)