Remove Python files.
Remove the Python code from this branch.
This commit is contained in:
parent
ea7396ff53
commit
cfd80b839b
47
api_calls.py
47
api_calls.py
@ -1,47 +0,0 @@
|
||||
import requests
|
||||
import os
|
||||
|
||||
def get_mb_id(artist_name, mb_confidence):
|
||||
artist_name = artist_name.strip('_')
|
||||
mb_url = f'https://musicbrainz.org/ws/2/artist?query=artist:"{artist_name}"&fmt=json'
|
||||
header = {'User-Agent': 'get_artist_art.py/1.0'}
|
||||
response = requests.get(mb_url, headers=header)
|
||||
if response.status_code == 200:
|
||||
mb_data = response.json()
|
||||
if mb_data['count'] > 0:
|
||||
if mb_data['artists'][0]['score'] > mb_confidence:
|
||||
return True, mb_data['artists'][0]['id']
|
||||
else:
|
||||
print("No artist found of hight enough confidance.")
|
||||
else:
|
||||
print("No artist found.")
|
||||
return False, ""
|
||||
else:
|
||||
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}'
|
||||
response = requests.get(ftv_api_url)
|
||||
ftv_data =response.json()
|
||||
if not ('status' in ftv_data):
|
||||
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("Thumb not found.")
|
||||
else:
|
||||
error_msg = ftv_data['error message']
|
||||
print(f"Error: {error_msg}")
|
@ -1,10 +0,0 @@
|
||||
import os
|
||||
|
||||
def get_all(path):
|
||||
return [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
|
||||
|
||||
def has_artist_art(path):
|
||||
if(os.path.exists(os.path.join(path, "artist.jpg")))or (os.path.exists(os.path.join(path, "artist.png"))):
|
||||
return True
|
||||
else:
|
||||
return False
|
@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import configparser
|
||||
import os
|
||||
from time import sleep
|
||||
import dir_activities
|
||||
import api_calls
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
if (os.path.exists('config.ini')):
|
||||
conf_path = 'config.ini'
|
||||
else:
|
||||
conf_path = os.path.join(os.path.expanduser("~"), ".local/share/get_artist_art/config.ini")
|
||||
|
||||
config.read(conf_path)
|
||||
|
||||
music_path = config['music']['dir']
|
||||
ftv_api_key = config['fanart_tv']['api_key']
|
||||
mb_confidence = int(config['musicbrainz']['confidence'])
|
||||
|
||||
count = 1
|
||||
dir_list = dir_activities.get_all(music_path)
|
||||
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(str(count) + ": " + artist.strip('_'))
|
||||
try:
|
||||
found_status, mb_id = api_calls.get_mb_id(artist, mb_confidence)
|
||||
# print("Getting ", artist_image)
|
||||
if found_status:
|
||||
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)
|
||||
|
||||
count += 1
|
||||
sleep(1)
|
Loading…
x
Reference in New Issue
Block a user