Skip to content

Commit

Permalink
Add ability to use different resolutions for album, artist and playli…
Browse files Browse the repository at this point in the history
…st images

Update tests to change resolution.
Lower the amount of times tests login to tidal.
  • Loading branch information
morguldir committed Sep 15, 2019
1 parent 795b85a commit 2175f0d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
16 changes: 8 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

logging.basicConfig(level=logging.DEBUG)

@pytest.fixture()
@pytest.fixture(scope='session')
def session():
session = tidalapi.Session()
username = os.getenv("TIDAL_USERNAME")
Expand Down Expand Up @@ -108,17 +108,17 @@ def test_search(session):
res = session.search('artist', 'lasgo')
assert res.artists[0].name == "Lasgo"

def test_artist_image(session):
def test_artist_picture(session):
artist = session.get_artist(16147)
assert requests.get(artist.image).status_code == 200
assert requests.get(artist.picture(640,640)).status_code == 200

def test_album_image(session):
artist = session.get_album(17925106)
assert requests.get(artist.image).status_code == 200
def test_album_picture(session):
album = session.get_album(17925106)
assert requests.get(album.picture(640, 640)).status_code == 200

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

def test_get_track_url(session):
track = session.get_track(108043415)
Expand Down
2 changes: 0 additions & 2 deletions tidalapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def __init__(self, quality=Quality.high, videoQuality=videoQuality.high):
self.api_token = 'BI218mwp9ERZ3PFI' if self.quality == \
Quality.lossless else '4zx46pyr9o8qZNRw',


class Session(object):

def __init__(self, config=Config()):
self.session_id = None
self.country_code = None
Expand Down
50 changes: 47 additions & 3 deletions tidalapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ class Album(Model):
release_date = None

@property
def image(self, width=512, height=512):
def image(self, width=1280, height=1280):
return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid')

def picture(self, width, height):
"""
A url to an album picture
:param width: pixel width, maximum 2000
:type width: int
:param height: pixel height, maximum 2000
:type height: int
Original sizes: 80x80, 160x160, 320x320, 640x640 and 1280x1280
"""
return IMG_URL.format(width=width, height=height, id=self.id, id_type='albumid')


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

@property
def image(self, width=512, height=512):
def image(self, width=1280, height=1280):
return IMG_URL.format(width=height, height=height, id=self.id, id_type='artistid')

def picture(self, width, height):
"""
A url to an artist picture
:param width: pixel width, maximum 2000
:type width: int
:param height: pixel height, maximum 2000
:type height: int
Original sizes: 80x80, 160x160, 320x320, 480x480, 640x640, 1280x1280
"""
return IMG_URL.format(width=width, height=height, id=self.id, id_type='artistid')


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

@property
def image(self, width=512, height=512):
def image(self, width=1080, height=1080):
return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid')

def picture(self, width, height):
"""
A url to a playlist picture
:param width: pixel width, maximum 2000
:type width: int
:param height: pixel height, maximum 2000
:type height: int
Original sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080
"""
return IMG_URL.format(width=width, height=height, id=self.id, id_type='uuid')


class Media(Model):
duration = -1
track_num = -1
Expand All @@ -75,12 +116,15 @@ class Media(Model):
album = None
available = True


class Track(Media):
pass


class Video(Media):
type = None


class SearchResult(Model):
artists = []
albums = []
Expand Down

0 comments on commit 2175f0d

Please sign in to comment.