Compare commits
9 Commits
fanart_tv
...
883f594f4f
| Author | SHA1 | Date | |
|---|---|---|---|
| 883f594f4f | |||
| c5ffadd1f0 | |||
| ea7396ff53 | |||
| c01b4cdcdd | |||
| 66ce579992 | |||
| 6f7e69411b | |||
| fe8a4c2410 | |||
| 858d68b491 | |||
| f2d21185af |
35
api_calls.py
35
api_calls.py
@@ -2,8 +2,10 @@ import requests
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def get_mb_id(artist_name, mb_confidence):
|
def get_mb_id(artist_name, mb_confidence):
|
||||||
mb_url = f'https://musicbrainz.org/ws/2/artist?query=artist:%22{artist_name}%22&fmt=json'
|
artist_name = artist_name.strip('_')
|
||||||
response = requests.get(mb_url)
|
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:
|
if response.status_code == 200:
|
||||||
mb_data = response.json()
|
mb_data = response.json()
|
||||||
if mb_data['count'] > 0:
|
if mb_data['count'] > 0:
|
||||||
@@ -23,14 +25,29 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
|||||||
response = requests.get(ftv_api_url)
|
response = requests.get(ftv_api_url)
|
||||||
ftv_data =response.json()
|
ftv_data =response.json()
|
||||||
if not ('status' in ftv_data):
|
if not ('status' in ftv_data):
|
||||||
art_url = ftv_data['artistthumb'][0]['url']
|
if ('artistthumb' in ftv_data):
|
||||||
print(art_url)
|
art_url = ftv_data['artistthumb'][0]['url']
|
||||||
response = requests.get(art_url)
|
print(art_url)
|
||||||
if response.status_code == 200:
|
response = requests.get(art_url)
|
||||||
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
|
if response.status_code == 200:
|
||||||
f.write(response.content)
|
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
|
||||||
|
f.write(response.content)
|
||||||
|
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)
|
||||||
|
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:
|
else:
|
||||||
print("Error downloading: ", response.status_code)
|
print("Thumb not found.")
|
||||||
else:
|
else:
|
||||||
error_msg = ftv_data['error message']
|
error_msg = ftv_data['error message']
|
||||||
print(f"Error: {error_msg}")
|
print(f"Error: {error_msg}")
|
||||||
@@ -4,4 +4,7 @@ def get_all(path):
|
|||||||
return [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
|
return [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
|
||||||
|
|
||||||
def has_artist_art(path):
|
def has_artist_art(path):
|
||||||
return os.path.exists(os.path.join(path, "artist.jpg"))
|
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
|
||||||
@@ -2,11 +2,17 @@
|
|||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
|
from time import sleep
|
||||||
import dir_activities
|
import dir_activities
|
||||||
import api_calls
|
import api_calls
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('config.ini')
|
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']
|
music_path = config['music']['dir']
|
||||||
ftv_api_key = config['fanart_tv']['api_key']
|
ftv_api_key = config['fanart_tv']['api_key']
|
||||||
@@ -19,7 +25,7 @@ for artist in dir_list:
|
|||||||
artist_path = os.path.join(music_path, artist)
|
artist_path = os.path.join(music_path, artist)
|
||||||
if (not(dir_activities.has_artist_art(artist_path))):
|
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)
|
print(str(count) + ": " + artist.strip('_'))
|
||||||
try:
|
try:
|
||||||
found_status, mb_id = api_calls.get_mb_id(artist, mb_confidence)
|
found_status, mb_id = api_calls.get_mb_id(artist, mb_confidence)
|
||||||
# print("Getting ", artist_image)
|
# print("Getting ", artist_image)
|
||||||
@@ -33,3 +39,4 @@ for artist in dir_list:
|
|||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
|
sleep(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user