From fe8a4c2410186cd41dff7643074247fa5b5f1104 Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Fri, 20 Sep 2024 14:12:54 -0400 Subject: [PATCH] Add fetching of hdmusiclogo if artistthumb fails. This will catch a few more artists and at least place something in their directory. --- api_calls.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/api_calls.py b/api_calls.py index 0ecdfa7..f86f03a 100644 --- a/api_calls.py +++ b/api_calls.py @@ -23,14 +23,23 @@ def get_image(mb_id, ftv_api_key, artist_path): response = requests.get(ftv_api_url) ftv_data =response.json() if not ('status' in ftv_data): - art_url = ftv_data['artistthumb'][0]['url'] - print(art_url) - response = requests.get(art_url) - if response.status_code == 200: - with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f: - f.write(response.content) + if ('artistthumb' in ftv_data): + art_url = ftv_data['artistthumb'][0]['url'] + print(art_url) + response = requests.get(art_url) + if response.status_code == 200: + with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f: + f.write(response.content) + elif ('hdmusiclogo' in ftv_data): + art_url = ftv_data['hdmusiclogo'][0]['url'] + response = requests.get(art_url) + if response.status_code == 200: + with open(os.path.join(artist_path, 'artist.png'), 'wb') as f: + f.write(response.content) + else: + print("Error downloading: ", response.status_code) else: - print("Error downloading: ", response.status_code) + print("Thumb not found.") else: error_msg = ftv_data['error message'] print(f"Error: {error_msg}") \ No newline at end of file