@@ -32,3 +32,68 @@ def get_queue_id_from_player_data(player_data):
3232 if current_media is None :
3333 return None
3434 return current_media .get ("queue_id" )
35+
36+
37+ def return_image_or_none (img_data : dict ):
38+ """Returns None if image is not present or not remotely accessible."""
39+ if type (img_data ) is dict :
40+ img = img_data .get ("path" )
41+ remote = img_data .get ("remotely_accessible" )
42+ if remote :
43+ return img
44+ return None
45+
46+
47+ def search_image_list (images : list ):
48+ """Checks through a list of image data and attempts to find an image."""
49+ result = None
50+ for item in images :
51+ image = return_image_or_none (item )
52+ if image is not None :
53+ result = image
54+ break
55+ return result
56+
57+
58+ def find_image_from_image (data : dict ):
59+ """Attempts to find the image via the image key."""
60+ img_data = data .get ("image" )
61+ return return_image_or_none (img_data )
62+
63+
64+ def find_image_from_metadata (data : dict ):
65+ """Attempts to find the image via the metadata key."""
66+ media_item = data .get ("media_item" , {})
67+ metadata = media_item .get ("metadata" , {})
68+ img_data = metadata .get ("images" )
69+ if img_data is None :
70+ return None
71+ return search_image_list (img_data )
72+
73+
74+ def find_image_from_album (data : dict ):
75+ """Attempts to find the image via the album key."""
76+ album = data .get ("album" , {})
77+ metadata = album .get ("metadata" , {})
78+ img_data = metadata .get ("images" )
79+ if img_data is None :
80+ return None
81+ return search_image_list (img_data )
82+
83+
84+ def find_image_from_artists (data : dict ):
85+ """Attempts to find the image via the artists key."""
86+ artist = data .get ("artist" , {})
87+ img_data = artist .get ("image" )
88+ if img_data is list :
89+ return search_image_list (img_data )
90+ return return_image_or_none (img_data )
91+
92+
93+ def find_image (data : dict ):
94+ """Returns None if image is not present or not remotely accessible."""
95+ from_image = find_image_from_image (data )
96+ from_metadata = find_image_from_metadata (data )
97+ from_album = find_image_from_album (data )
98+ from_artists = find_image_from_artists (data )
99+ return from_image or from_metadata or from_album or from_artists
0 commit comments