mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
67f28b8a9b
+ ditch the LAST FM API KEY thing + expose the Musixmatch urls + use the kerve last fm api to download similar artist data + use google.it instead of the Google public dns to check internet connectivity (to make it work in all environments) + return og Dockerfile to fix ARM support
34 lines
823 B
Python
34 lines
823 B
Python
"""
|
|
Requests related to artists
|
|
"""
|
|
import urllib.parse
|
|
|
|
import requests
|
|
from requests import ConnectionError, HTTPError, ReadTimeout
|
|
|
|
from app import settings
|
|
from app.utils.hashing import create_hash
|
|
|
|
|
|
def fetch_similar_artists(name: str):
|
|
"""
|
|
Fetches similar artists from Last.fm
|
|
"""
|
|
url = f"https://kerve.last.fm/kerve/similarartists?artist={urllib.parse.quote_plus(name, safe='')}&autocorrect=1&tracks=1&image_size=large&limit=250&format=json"
|
|
|
|
try:
|
|
response = requests.get(url, timeout=10)
|
|
response.raise_for_status()
|
|
except (ConnectionError, ReadTimeout, HTTPError):
|
|
return []
|
|
|
|
data = response.json()
|
|
|
|
try:
|
|
artists = data["results"]["artist"]
|
|
except KeyError:
|
|
return []
|
|
|
|
for artist in artists:
|
|
yield create_hash(artist["name"])
|