Reorganize tadb lookup to actually work
This commit is contained in:
@ -15,25 +15,28 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def lookup_artist_from_tadb(name_or_id: str) -> dict:
|
def lookup_artist_from_tadb(name_or_id: str) -> dict:
|
||||||
artist_info = {}
|
artist_info = {}
|
||||||
name = urllib.parse.quote(name_or_id)
|
response = None
|
||||||
response = requests.get(ARTIST_SEARCH_URL + name)
|
|
||||||
|
|
||||||
found_by_name = True
|
# Look for an ID as an integer
|
||||||
if response.status_code != 200:
|
try:
|
||||||
logger.warn(f"Bad response from TADB: {response.status_code}")
|
tadb_id = int(name_or_id)
|
||||||
found_by_name = False
|
except ValueError:
|
||||||
|
tadb_id = None
|
||||||
|
|
||||||
if not response.content:
|
if tadb_id:
|
||||||
logger.warn(f"Bad content from TADB: {response.content}")
|
response = requests.get(ARTIST_FETCH_URL + str(tadb_id))
|
||||||
found_by_name = False
|
|
||||||
|
|
||||||
if "null" in str(response.content):
|
if response.status_code != 200:
|
||||||
logger.warn(f"Bad content from TADB: {response.content}")
|
logger.warn(f"Bad response from TADB: {response.status_code}")
|
||||||
found_by_name = False
|
return artist_info
|
||||||
|
|
||||||
if not found_by_name:
|
if not response.content:
|
||||||
# Try using an TABD ID
|
logger.warn(f"Bad content from TADB: {response.content}")
|
||||||
response = requests.get(ARTIST_FETCH_URL + name_or_id)
|
return artist_info
|
||||||
|
|
||||||
|
if not response:
|
||||||
|
name = urllib.parse.quote(name_or_id)
|
||||||
|
response = requests.get(ARTIST_SEARCH_URL + name)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logger.warn(f"Bad response from TADB: {response.status_code}")
|
logger.warn(f"Bad response from TADB: {response.status_code}")
|
||||||
@ -43,6 +46,10 @@ def lookup_artist_from_tadb(name_or_id: str) -> dict:
|
|||||||
logger.warn(f"Bad content from TADB: {response.content}")
|
logger.warn(f"Bad content from TADB: {response.content}")
|
||||||
return artist_info
|
return artist_info
|
||||||
|
|
||||||
|
if '{"artists": null}' in str(response.content):
|
||||||
|
logger.warn(f"Bad content from TADB: {response.content}")
|
||||||
|
return artist_info
|
||||||
|
|
||||||
results = json.loads(response.content)
|
results = json.loads(response.content)
|
||||||
if results["artists"]:
|
if results["artists"]:
|
||||||
artist = results["artists"][0]
|
artist = results["artists"][0]
|
||||||
|
|||||||
Reference in New Issue
Block a user