Skip to content

Commit c904d21

Browse files
committed
Add support for album cover/video in "origin" size (Fixes #319)
1 parent 652e19e commit c904d21

2 files changed

Lines changed: 42 additions & 23 deletions

File tree

tidalapi/album.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,52 +238,69 @@ def items(
238238
assert isinstance(items, list)
239239
return cast(List[Union["Track", "Video"]], items)
240240

241-
def image(self, dimensions: int = 320, default: str = DEFAULT_ALBUM_IMG) -> str:
241+
def image(
242+
self, dimensions: Union[int, str] = 320, default: str = DEFAULT_ALBUM_IMG
243+
) -> str:
242244
"""A url to an album image cover.
243245
244-
:param dimensions: The width and height that you want from the image
246+
:param dimensions: The width and height of the album image. If "origin", the original resolution will be used
245247
:param default: An optional default image to serve if one is not available
246248
:return: A url to the image.
247249
248-
Valid resolutions: 80x80, 160x160, 320x320, 640x640, 1280x1280
250+
Valid resolutions: 80x80, 160x160, 320x320, 640x640, 1280x1280, 3000x3000 (origin)
249251
"""
250252

251-
if dimensions not in [80, 160, 320, 640, 1280]:
253+
if dimensions not in [80, 160, 320, 640, 1280, "origin"]:
252254
raise ValueError("Invalid resolution {0} x {0}".format(dimensions))
253255

254-
if not self.cover:
255-
return self.session.config.image_url % (
256-
default.replace("-", "/"),
257-
dimensions,
258-
dimensions,
259-
)
256+
if dimensions == "origin":
257+
if not self.cover:
258+
return self.session.config.image_url_origin % (
259+
default.replace("-", "/")
260+
)
261+
else:
262+
return self.session.config.image_url_origin % (
263+
self.cover.replace("-", "/")
264+
)
260265
else:
261-
return self.session.config.image_url % (
262-
self.cover.replace("-", "/"),
263-
dimensions,
264-
dimensions,
265-
)
266+
if not self.cover:
267+
return self.session.config.image_url % (
268+
default.replace("-", "/"),
269+
dimensions,
270+
dimensions,
271+
)
272+
else:
273+
return self.session.config.image_url % (
274+
self.cover.replace("-", "/"),
275+
dimensions,
276+
dimensions,
277+
)
266278

267-
def video(self, dimensions: int) -> str:
279+
def video(self, dimensions: Union[int, str] = 320) -> str:
268280
"""Creates a url to an mp4 video cover for the album.
269281
270282
Valid resolutions: 80x80, 160x160, 320x320, 640x640, 1280x1280
271283
272-
:param dimensions: The width an height of the video
284+
:param dimensions: The width and height of the album video. If "origin", the original resolution will be used
273285
:type dimensions: int
274286
:return: A url to an mp4 of the video cover.
275287
"""
276288
if not self.video_cover:
277289
raise AttributeError("This album does not have a video cover.")
278290

279-
if dimensions not in [80, 160, 320, 640, 1280]:
291+
if dimensions not in [80, 160, 320, 640, 1280, "origin"]:
280292
raise ValueError("Invalid resolution {0} x {0}".format(dimensions))
281293

282-
return self.session.config.video_url % (
283-
self.video_cover.replace("-", "/"),
284-
dimensions,
285-
dimensions,
286-
)
294+
if dimensions == "origin":
295+
return self.session.config.video_url_origin % (
296+
self.video_cover.replace("-", "/")
297+
)
298+
else:
299+
return self.session.config.video_url % (
300+
self.video_cover.replace("-", "/"),
301+
dimensions,
302+
dimensions,
303+
)
287304

288305
def page(self) -> "Page":
289306
"""

tidalapi/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ class Config:
115115
client_id: str
116116
client_secret: str
117117
image_url: str = "https://resources.tidal.com/images/%s/%ix%i.jpg"
118+
image_url_origin: str = "https://resources.tidal.com/images/%s/origin.jpg"
118119
item_limit: int
119120
quality: str
120121
video_quality: str
121122
video_url: str = "https://resources.tidal.com/videos/%s/%ix%i.mp4"
123+
video_url_origin: str = "https://resources.tidal.com/videos/%s/origin.mp4"
122124
# Necessary for PKCE authorization only
123125
client_unique_key: str
124126
code_verifier: str

0 commit comments

Comments
 (0)