Compare commits

..

No commits in common. "26dfe543a1c74f863d27f4e3eaa52a5429bef0c4" and "883f594f4f7ae2484de4be9ab4303baa83c5287a" have entirely different histories.

2 changed files with 11 additions and 34 deletions

View File

@ -1,6 +1,5 @@
import requests
import os
from time import sleep
def get_mb_id(artist_name, mb_confidence):
artist_name = artist_name.strip('_')
@ -11,19 +10,15 @@ def get_mb_id(artist_name, mb_confidence):
mb_data = response.json()
if mb_data['count'] > 0:
if mb_data['artists'][0]['score'] > mb_confidence:
return True, mb_data['artists'][0]['id'], True
return True, mb_data['artists'][0]['id']
else:
print("No artist found of hight enough confidance.")
return False, "", True
else:
print("No artist found.")
return False, "", True
elif (response.status_code == 503):
sleep(1)
return False, "", False
return False, ""
else:
print(f"MB Error: {response.status_code}")
return False, "", True
print(f"Error: {response.status_code}")
return False, ""
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}'
@ -37,35 +32,22 @@ def get_image(mb_id, ftv_api_key, artist_path):
if response.status_code == 200:
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
f.write(response.content)
return True
elif ('artistbackground' in ftv_data):
art_url = ftv_data['artistbackground'][0]['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)
return True
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)
return True
f.write(response.content)
else:
print("Error downloading: ", response.status_code)
return True
else:
print("Thumb not found.")
return True
elif (response.status_code == 503):
sleep(1)
return False
else:
error_msg = ftv_data['error message']
if (error_msg == "503"):
sleep(1)
return False
else:
print(f"FTV Error: {error_msg}")
return True
print(f"Error: {error_msg}")

View File

@ -24,24 +24,19 @@ dir_list.sort()
for artist in dir_list:
artist_path = os.path.join(music_path, artist)
if (not(dir_activities.has_artist_art(artist_path))):
# print(dir_activities.has_artist_art(artist_path))
print(dir_activities.has_artist_art(artist_path))
print(str(count) + ": " + artist.strip('_'))
try:
ftv_response = False
mb_exit = False
while not mb_exit:
found_status, mb_id, mb_exit = api_calls.get_mb_id(artist, mb_confidence)
found_status, mb_id = api_calls.get_mb_id(artist, mb_confidence)
# print("Getting ", artist_image)
if found_status:
while not ftv_response:
ftv_response = api_calls.get_image(mb_id, ftv_api_key, artist_path)
print(ftv_response)
artist_image = api_calls.get_image(mb_id, ftv_api_key, artist_path)
else:
print(f"{artist} returned no results.")
# api_requests.get_art(artist_image, artist, music_path)
except Exception as e:
print("Artist or art not found.")
print(e)
print("---------")
count += 1
#sleep(1)
sleep(1)