Skip to content

Commit 682c476

Browse files
committed
Playlist: Use wide image when no square picture is available.
1 parent 4a0462d commit 682c476

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

tidalapi/playlist.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,30 @@ def items(self, limit: int = 100, offset: int = 0) -> List[Union["Track", "Video
177177
self.request.map_json(request.json(), parse=self.session.parse_media)
178178
)
179179

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

190192
if dimensions not in [160, 320, 480, 640, 750, 1080]:
191193
raise ValueError("Invalid resolution {0} x {0}".format(dimensions))
192-
if self.square_picture is None:
194+
if self.square_picture:
195+
return self.session.config.image_url % (
196+
self.square_picture.replace("-", "/"),
197+
dimensions,
198+
dimensions,
199+
)
200+
elif self.picture and wide_fallback:
201+
return self.wide_image()
202+
else:
193203
raise AttributeError("No picture available")
194-
return self.session.config.image_url % (
195-
self.square_picture.replace("-", "/"),
196-
dimensions,
197-
dimensions,
198-
)
199204

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

0 commit comments

Comments
 (0)