Commit 3d9912f4 authored by petitminion's avatar petitminion
Browse files

fix linter

fix linter
parent 4b8d99b3
Pipeline #17884 failed with stages
in 2 minutes and 32 seconds
......@@ -275,7 +275,9 @@ class SimilarAcousticRadio(RelatedObjectRadio):
def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)
mbids_regex = self.get_regex()
return queryset.filter(mbid__regex=r'({mbids_regex})'.format(mbids_regex=mbids_regex))
return queryset.filter(
mbid__regex=r"({mbids_regex})".format(mbids_regex=mbids_regex)
)
@registry.register(name="artist")
......
......@@ -5,8 +5,20 @@ import requests
logger = logging.getLogger(__name__)
VALID_METRICS = ['mfccs', 'mfccsw', 'gfccs', 'gfccsw', 'key', 'bpm', 'onsetrate', 'moods',
'instruments', 'dortmund', 'rosamerica', 'tzanetakis']
VALID_METRICS = [
"mfccs",
"mfccsw",
"gfccs",
"gfccsw",
"key",
"bpm",
"onsetrate",
"moods",
"instruments",
"dortmund",
"rosamerica",
"tzanetakis",
]
class EndpointError(Exception):
......@@ -16,20 +28,24 @@ class EndpointError(Exception):
def get_similar_tracks_mbids_from_mbid(mbid, annoy_similarity):
if annoy_similarity not in VALID_METRICS:
raise AttributeError("Metric %s is not valid. Must be one of : " + print(VALID_METRICS))
raise AttributeError(
"Metric %s is not valid. Must be one of : " + print(VALID_METRICS)
)
headers = {'Content-Type': 'application/json'}
headers = {"Content-Type': 'application/json"}
endpoint = "acousticbrainz.org/api/v1/similarity"
similar_tracks_mbids = []
similar_tracks = requests.get(
'https://{endpoint}/{annoy_similarity}/?recording_ids={mbid}&remove_dups&n_neighbours=1000'
.format(endpoint=endpoint, annoy_similarity=annoy_similarity, mbid=mbid), headers=headers
"https://{endpoint}/{annoy_similarity}/?recording_ids={mbid}&remove_dups&n_neighbours=1000".format(
endpoint=endpoint, annoy_similarity=annoy_similarity, mbid=mbid
),
headers=headers,
)
if similar_tracks.status_code != 200:
logger.warning("Error while querying {endpoint!r} : {similar_tracks.content!r}")
raise EndpointError
j = json.loads(similar_tracks.content)
for tracks in j['{mbid}'.format(mbid=mbid)]['0']:
similar_tracks_mbids.append(tracks['recording_mbid'])
for tracks in j["{mbid}".format(mbid=mbid)]["0"]:
similar_tracks_mbids.append(tracks["recording_mbid"])
return similar_tracks_mbids
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment