d6060c2e61
The combination of getting an artist ID from MusicBrainz that is then used to pull an image from FanArt.TV seems to work.
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import requests
|
|
import os
|
|
|
|
def get_mb_id(artist_name):
|
|
mb_url = f'https://musicbrainz.org/ws/2/artist?query=artist:%22{artist_name}%22&fmt=json'
|
|
response = requests.get(mb_url)
|
|
if response.status_code == 200:
|
|
mb_data = response.json()
|
|
if mb_data['count'] > 0:
|
|
if mb_data['artists'][0]['score'] > 80:
|
|
return mb_data['artists'][0]['id']
|
|
else:
|
|
print("No artist found of hight enough confidance.")
|
|
else:
|
|
print("No artist found.")
|
|
else:
|
|
print(f"Error: {response.status_code}")
|
|
|
|
def get_image(mb_id, ftv_api_key, artist_path):
|
|
ftv_api_url = f'https://webservice.fanart.tv/v3/music/{mb_id}?api_key={ftv_api_key}'
|
|
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)
|
|
else:
|
|
print("Error downloading: ", response.status_code)
|
|
else:
|
|
error_msg = ftv_data['error message']
|
|
print(f"Error: {error_msg}") |