Skip to content

Commit

Permalink
Adapt to new labs api query format (#137)
Browse files Browse the repository at this point in the history
* Adapt to new labs api query format

* fix test
  • Loading branch information
amCap1712 authored May 3, 2024
1 parent 7a89353 commit b433c46
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/musicbrainz/test_mbid_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_read(self, req):

r = [ troi.Recording("trigger hippie", artist_credit=troi.ArtistCredit(name="morcheeba")) ]
entities = e.read([r])
req.assert_called_with(e.SERVER_URL, json=[{'[artist_credit_name]': 'morcheeba', '[recording_name]': 'trigger hippie'}])
req.assert_called_with(e.SERVER_URL, json=[{'artist_credit_name': 'morcheeba', 'recording_name': 'trigger hippie'}])

assert len(entities) == 1
assert entities[0].artist_credit.artist_credit_id == 963
Expand Down
3 changes: 2 additions & 1 deletion troi/content_resolver/metadata_lookup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from collections import defaultdict, namedtuple
import datetime
from time import sleep

import requests
from tqdm import tqdm
Expand Down Expand Up @@ -65,7 +66,7 @@ def process_recordings(self, recordings):
mbid_to_recording = {}
for rec in recordings:
mbid_to_recording[rec.mbid] = rec
args.append({"[recording_mbid]": rec.mbid})
args.append({"recording_mbid": rec.mbid})

while True:
r = requests.post("https://labs.api.listenbrainz.org/bulk-tag-lookup/json", json=args)
Expand Down
2 changes: 1 addition & 1 deletion troi/musicbrainz/mbid_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def read(self, inputs):
params = []
for r in inputs[0]:
if r.artist_credit is not None and r.name is not None:
params.append({"[artist_credit_name]": r.artist_credit.name, "[recording_name]": r.name})
params.append({"artist_credit_name": r.artist_credit.name, "recording_name": r.name})

if not params:
return []
Expand Down
4 changes: 3 additions & 1 deletion troi/patches/lb_radio_classes/tag.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from time import sleep

import troi
from random import randint, shuffle

Expand Down Expand Up @@ -35,7 +37,7 @@ def fetch_similar_tags(self, tag):
"""

while True:
r = requests.post( "https://labs.api.listenbrainz.org/tag-similarity/json", json=[{ "tag": tag }])
r = requests.post("https://labs.api.listenbrainz.org/tag-similarity/json", json=[{"tag": tag}])
if r.status_code == 429:
sleep(2)
continue
Expand Down

0 comments on commit b433c46

Please sign in to comment.