Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,20 @@ def test_image_cover(session):
verify_image_cover(session, session.album(108043414), [80, 160, 320, 640, 1280])


def test_image_cover_origin(session):
image_url = session.album(108043414).image(dimensions="origin")
assert image_url.endswith("/origin.jpg")


def test_video_cover(session):
verify_video_cover(session.album(108043414), [80, 160, 320, 640, 1280])


def test_video_cover_origin(session):
video_url = session.album(108043414).video(dimensions="origin")
assert video_url.endswith("/origin.mp4")


def test_no_release_date(session):
album = session.album(174114082)
assert album.release_date is None
Expand Down
63 changes: 40 additions & 23 deletions tidalapi/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,52 +238,69 @@ def items(
assert isinstance(items, list)
return cast(List[Union["Track", "Video"]], items)

def image(self, dimensions: int = 320, default: str = DEFAULT_ALBUM_IMG) -> str:
def image(
self, dimensions: Union[int, str] = 320, default: str = DEFAULT_ALBUM_IMG
) -> str:
"""A url to an album image cover.

:param dimensions: The width and height that you want from the image
:param dimensions: The width and height of the album image. If "origin", the original resolution will be used
:param default: An optional default image to serve if one is not available
:return: A url to the image.

Valid resolutions: 80x80, 160x160, 320x320, 640x640, 1280x1280
Valid resolutions: 80x80, 160x160, 320x320, 640x640, 1280x1280, 3000x3000 (origin)
"""

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

if not self.cover:
return self.session.config.image_url % (
default.replace("-", "/"),
dimensions,
dimensions,
)
if dimensions == "origin":
if not self.cover:
return self.session.config.image_url_origin % (
default.replace("-", "/")
)
else:
return self.session.config.image_url_origin % (
self.cover.replace("-", "/")
)
else:
return self.session.config.image_url % (
self.cover.replace("-", "/"),
dimensions,
dimensions,
)
if not self.cover:
return self.session.config.image_url % (
default.replace("-", "/"),
dimensions,
dimensions,
)
else:
return self.session.config.image_url % (
self.cover.replace("-", "/"),
dimensions,
dimensions,
)

def video(self, dimensions: int) -> str:
def video(self, dimensions: Union[int, str] = 320) -> str:
"""Creates a url to an mp4 video cover for the album.

Valid resolutions: 80x80, 160x160, 320x320, 640x640, 1280x1280

:param dimensions: The width an height of the video
:param dimensions: The width and height of the album video. If "origin", the original resolution will be used
:type dimensions: int
:return: A url to an mp4 of the video cover.
"""
if not self.video_cover:
raise AttributeError("This album does not have a video cover.")

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

return self.session.config.video_url % (
self.video_cover.replace("-", "/"),
dimensions,
dimensions,
)
if dimensions == "origin":
return self.session.config.video_url_origin % (
self.video_cover.replace("-", "/")
)
else:
return self.session.config.video_url % (
self.video_cover.replace("-", "/"),
dimensions,
dimensions,
)

def page(self) -> "Page":
"""
Expand Down
2 changes: 2 additions & 0 deletions tidalapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ class Config:
client_id: str
client_secret: str
image_url: str = "https://resources.tidal.com/images/%s/%ix%i.jpg"
image_url_origin: str = "https://resources.tidal.com/images/%s/origin.jpg"
item_limit: int
quality: str
video_quality: str
video_url: str = "https://resources.tidal.com/videos/%s/%ix%i.mp4"
video_url_origin: str = "https://resources.tidal.com/videos/%s/origin.mp4"
# Necessary for PKCE authorization only
client_unique_key: str
code_verifier: str
Expand Down