Compare commits
11 Commits
mb_request
...
master
Author | SHA1 | Date | |
---|---|---|---|
ad575cd418 | |||
dc4e83b133 | |||
dad5a3709d | |||
b15145426b | |||
26dfe543a1 | |||
36a1f0ffab | |||
cbde52eb59 | |||
883f594f4f | |||
c5ffadd1f0 | |||
485b565a3f | |||
386f17779b |
117
.gitignore
vendored
117
.gitignore
vendored
@ -435,3 +435,120 @@ Temporary Items
|
|||||||
# Built Visual Studio Code Extensions
|
# Built Visual Studio Code Extensions
|
||||||
*.vsix
|
*.vsix
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/pycharm
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm
|
||||||
|
|
||||||
|
### PyCharm ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
### PyCharm Patch ###
|
||||||
|
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||||
|
|
||||||
|
# *.iml
|
||||||
|
# modules.xml
|
||||||
|
# .idea/misc.xml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# Sonarlint plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||||
|
.idea/**/sonarlint/
|
||||||
|
|
||||||
|
# SonarQube Plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||||
|
.idea/**/sonarIssues.xml
|
||||||
|
|
||||||
|
# Markdown Navigator plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||||
|
.idea/**/markdown-navigator.xml
|
||||||
|
.idea/**/markdown-navigator-enh.xml
|
||||||
|
.idea/**/markdown-navigator/
|
||||||
|
|
||||||
|
# Cache file creation bug
|
||||||
|
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||||
|
.idea/$CACHE_FILE$
|
||||||
|
|
||||||
|
# CodeStream plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||||
|
.idea/codestream.xml
|
||||||
|
|
||||||
|
# Azure Toolkit for IntelliJ plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||||
|
.idea/**/azureSettings.xml
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/pycharm
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# get_artist_art
|
# get_artist_art
|
||||||
|
|
||||||
Pulls artist art from https://www.theaudiodb.com/
|
Pulls artist art from https://fanart.tv/ using identifiers from https://musicbrainz.org.
|
40
api_calls.py
40
api_calls.py
@ -1,5 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
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('_')
|
||||||
@ -10,38 +11,61 @@ def get_mb_id(artist_name, mb_confidence):
|
|||||||
mb_data = response.json()
|
mb_data = response.json()
|
||||||
if mb_data['count'] > 0:
|
if mb_data['count'] > 0:
|
||||||
if mb_data['artists'][0]['score'] > mb_confidence:
|
if mb_data['artists'][0]['score'] > mb_confidence:
|
||||||
return True, mb_data['artists'][0]['id']
|
return True, mb_data['artists'][0]['id'], True
|
||||||
else:
|
else:
|
||||||
print("No artist found of hight enough confidance.")
|
print("No artist found of hight enough confidance.")
|
||||||
|
return False, "", True
|
||||||
else:
|
else:
|
||||||
print("No artist found.")
|
print("No artist found.")
|
||||||
return False, ""
|
return False, "", True
|
||||||
|
elif response.status_code == 503:
|
||||||
|
sleep(1)
|
||||||
|
return False, "", False
|
||||||
else:
|
else:
|
||||||
print(f"Error: {response.status_code}")
|
print(f"MB Error: {response.status_code}")
|
||||||
return False, ""
|
return False, "", True
|
||||||
|
|
||||||
def get_image(mb_id, ftv_api_key, artist_path):
|
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}'
|
ftv_api_url = f'https://webservice.fanart.tv/v3/music/{mb_id}?api_key={ftv_api_key}'
|
||||||
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):
|
||||||
if ('artistthumb' in ftv_data):
|
if 'artistthumb' in ftv_data:
|
||||||
art_url = ftv_data['artistthumb'][0]['url']
|
art_url = ftv_data['artistthumb'][0]['url']
|
||||||
print(art_url)
|
print(art_url)
|
||||||
response = requests.get(art_url)
|
response = requests.get(art_url)
|
||||||
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 ('hdmusiclogo' in ftv_data):
|
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']
|
art_url = ftv_data['hdmusiclogo'][0]['url']
|
||||||
response = requests.get(art_url)
|
response = requests.get(art_url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
with open(os.path.join(artist_path, 'artist.png'), 'wb') as f:
|
with open(os.path.join(artist_path, 'artist.png'), 'wb') as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
print("Error downloading: ", response.status_code)
|
print("Error downloading: ", response.status_code)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
print("Thumb not found.")
|
print("Thumb not found.")
|
||||||
|
return True
|
||||||
|
elif response.status_code == 503:
|
||||||
|
sleep(1)
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
error_msg = ftv_data['error message']
|
error_msg = ftv_data['error message']
|
||||||
print(f"Error: {error_msg}")
|
if error_msg == "503":
|
||||||
|
sleep(1)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print(f"FTV Error: {error_msg}")
|
||||||
|
return True
|
@ -7,7 +7,7 @@ import dir_activities
|
|||||||
import api_calls
|
import api_calls
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
if (os.path.exists('config.ini')):
|
if os.path.exists('config.ini'):
|
||||||
conf_path = 'config.ini'
|
conf_path = 'config.ini'
|
||||||
else:
|
else:
|
||||||
conf_path = os.path.join(os.path.expanduser("~"), ".local/share/get_artist_art/config.ini")
|
conf_path = os.path.join(os.path.expanduser("~"), ".local/share/get_artist_art/config.ini")
|
||||||
@ -23,20 +23,25 @@ dir_list = dir_activities.get_all(music_path)
|
|||||||
dir_list.sort()
|
dir_list.sort()
|
||||||
for artist in dir_list:
|
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.strip('_'))
|
print(str(count) + ": " + artist.strip('_'))
|
||||||
try:
|
try:
|
||||||
found_status, mb_id = api_calls.get_mb_id(artist, mb_confidence)
|
ftv_response = False
|
||||||
|
mb_exit = False
|
||||||
|
while not mb_exit:
|
||||||
|
found_status, mb_id, mb_exit = api_calls.get_mb_id(artist, mb_confidence)
|
||||||
# print("Getting ", artist_image)
|
# print("Getting ", artist_image)
|
||||||
if found_status:
|
if found_status:
|
||||||
artist_image = api_calls.get_image(mb_id, ftv_api_key, artist_path)
|
while not ftv_response:
|
||||||
|
ftv_response = api_calls.get_image(mb_id, ftv_api_key, artist_path)
|
||||||
|
# print(ftv_response)
|
||||||
else:
|
else:
|
||||||
print(f"{artist} returned no results.")
|
print(f"{artist} returned no results.")
|
||||||
# api_requests.get_art(artist_image, artist, music_path)
|
# api_requests.get_art(artist_image, artist, music_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Artist or art not found.")
|
print("Artist or art not found.")
|
||||||
print(e)
|
print(e)
|
||||||
|
print("---------")
|
||||||
count += 1
|
count += 1
|
||||||
sleep(1)
|
#sleep(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user