fix linter
This commit is contained in:
parent
5e0af940dd
commit
d07dcd98bc
|
@ -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,25 @@ 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
|
||||
|
|
Loading…
Reference in New Issue