@@ -26,6 +26,8 @@ def get_images(web_client, uris):
26
26
for uri in group :
27
27
if uri ["key" ] in _cache :
28
28
result [uri ["uri" ]] = _cache [uri ["key" ]]
29
+ elif uri_type == "playlist" :
30
+ result .update (_process_uri (web_client , uri ))
29
31
else :
30
32
batch .append (uri )
31
33
if len (batch ) >= _API_MAX_IDS_PER_REQUEST :
@@ -45,7 +47,8 @@ def _parse_uri(uri):
45
47
if parsed_uri .netloc in ("open.spotify.com" , "play.spotify.com" ):
46
48
uri_type , uri_id = parsed_uri .path .split ("/" )[1 :3 ]
47
49
48
- if uri_type and uri_type in ("track" , "album" , "artist" ) and uri_id :
50
+ supported_types = ("track" , "album" , "artist" , "playlist" )
51
+ if uri_type and uri_type in supported_types and uri_id :
49
52
return {
50
53
"uri" : uri ,
51
54
"type" : uri_type ,
@@ -56,6 +59,13 @@ def _parse_uri(uri):
56
59
raise ValueError (f"Could not parse { repr (uri )} as a Spotify URI" )
57
60
58
61
62
+ def _process_uri (web_client , uri ):
63
+ data = web_client .get (f"{ uri ['type' ]} s/{ uri ['id' ]} " )
64
+ print (data )
65
+ _cache [uri ["key" ]] = tuple (_translate_image (i ) for i in data ["images" ])
66
+ return {uri ["uri" ]: _cache [uri ["key" ]]}
67
+
68
+
59
69
def _process_uris (web_client , uri_type , uris ):
60
70
result = {}
61
71
ids = [u ["id" ] for u in uris ]
0 commit comments