Skip to content

Commit

Permalink
Playlist: Use wide image when no square picture is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
tehkillerbee committed Mar 1, 2024
1 parent 4a0462d commit 682c476
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tidalapi/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,30 @@ def items(self, limit: int = 100, offset: int = 0) -> List[Union["Track", "Video
self.request.map_json(request.json(), parse=self.session.parse_media)
)

def image(self, dimensions: int = 480) -> str:
def image(self, dimensions: int = 480, wide_fallback: bool = True) -> str:
"""A URL to a playlist picture.
:param dimensions: The width and height that want from the image
:type dimensions: int
:param wide_fallback: Use wide image as fallback if no square cover picture exists
:type wide_fallback: bool
:return: A url to the image
Original sizes: 160x160, 320x320, 480x480, 640x640, 750x750, 1080x1080
"""

if dimensions not in [160, 320, 480, 640, 750, 1080]:
raise ValueError("Invalid resolution {0} x {0}".format(dimensions))
if self.square_picture is None:
if self.square_picture:
return self.session.config.image_url % (
self.square_picture.replace("-", "/"),
dimensions,
dimensions,
)
elif self.picture and wide_fallback:
return self.wide_image()
else:
raise AttributeError("No picture available")
return self.session.config.image_url % (
self.square_picture.replace("-", "/"),
dimensions,
dimensions,
)

def wide_image(self, width: int = 1080, height: int = 720) -> str:
"""Create a url to a wider playlist image.
Expand Down

0 comments on commit 682c476

Please sign in to comment.