Compare commits
4 Commits
fix_config
...
883f594f4f
| Author | SHA1 | Date | |
|---|---|---|---|
| 883f594f4f | |||
| c5ffadd1f0 | |||
| ea7396ff53 | |||
| c01b4cdcdd |
11
api_calls.py
11
api_calls.py
@@ -3,8 +3,9 @@ import os
|
|||||||
|
|
||||||
def get_mb_id(artist_name, mb_confidence):
|
def get_mb_id(artist_name, mb_confidence):
|
||||||
artist_name = artist_name.strip('_')
|
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:"{artist_name}"&fmt=json'
|
||||||
response = requests.get(mb_url)
|
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:
|
||||||
@@ -31,6 +32,12 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
|
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
|
||||||
f.write(response.content)
|
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):
|
elif ('hdmusiclogo' in ftv_data):
|
||||||
art_url = ftv_data['hdmusiclogo'][0]['url']
|
art_url = ftv_data['hdmusiclogo'][0]['url']
|
||||||
response = requests.get(art_url)
|
response = requests.get(art_url)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
|
from time import sleep
|
||||||
import dir_activities
|
import dir_activities
|
||||||
import api_calls
|
import api_calls
|
||||||
|
|
||||||
@@ -38,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