Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66ce579992 | |||
| 6f7e69411b | |||
| fe8a4c2410 | |||
| 858d68b491 | |||
| f2d21185af |
+17
-7
@@ -2,6 +2,7 @@ import requests
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def get_mb_id(artist_name, mb_confidence):
|
def get_mb_id(artist_name, mb_confidence):
|
||||||
|
artist_name = artist_name.strip('_')
|
||||||
mb_url = f'https://musicbrainz.org/ws/2/artist?query=artist:%22{artist_name}%22&fmt=json'
|
mb_url = f'https://musicbrainz.org/ws/2/artist?query=artist:%22{artist_name}%22&fmt=json'
|
||||||
response = requests.get(mb_url)
|
response = requests.get(mb_url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@@ -23,14 +24,23 @@ 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 ('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
-1
@@ -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
|
||||||
+7
-2
@@ -6,7 +6,12 @@ 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 +24,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)
|
||||||
|
|||||||
Reference in New Issue
Block a user