diff --git a/tests/test_album.py b/tests/test_album.py index 1ccc1b2f..6f9dcc95 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -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 diff --git a/tidalapi/album.py b/tidalapi/album.py index d03f7822..1af8b605 100644 --- a/tidalapi/album.py +++ b/tidalapi/album.py @@ -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": """ diff --git a/tidalapi/session.py b/tidalapi/session.py index d10c4229..53363b98 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -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