maloja: update submitted payload to follow latest maloja spec
See https://github.com/krateng/maloja/blob/master/API.md Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2359>
This commit is contained in:
parent
a029b845ed
commit
c1c48c9960
|
@ -17,31 +17,40 @@ def submit_listen(listening, conf, **kwargs):
|
||||||
return
|
return
|
||||||
|
|
||||||
logger = PLUGIN["logger"]
|
logger = PLUGIN["logger"]
|
||||||
logger.info("Submitting listening to Majola at %s", server_url)
|
logger.info("Submitting listening to Maloja at %s", server_url)
|
||||||
payload = get_payload(listening, api_key)
|
payload = get_payload(listening, api_key, conf)
|
||||||
logger.debug("Majola payload: %r", payload)
|
logger.debug("Maloja payload: %r", payload)
|
||||||
url = server_url.rstrip("/") + "/apis/mlj_1/newscrobble"
|
url = server_url.rstrip("/") + "/apis/mlj_1/newscrobble"
|
||||||
session = plugins.get_session()
|
session = plugins.get_session()
|
||||||
response = session.post(url, json=payload)
|
response = session.post(url, json=payload)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
details = json.loads(response.text)
|
details = json.loads(response.text)
|
||||||
if details["status"] == "success":
|
if details["status"] == "success":
|
||||||
logger.info("Majola listening submitted successfully")
|
logger.info("Maloja listening submitted successfully")
|
||||||
else:
|
else:
|
||||||
raise MalojaException(response.text)
|
raise MalojaException(response.text)
|
||||||
|
|
||||||
|
|
||||||
def get_payload(listening, api_key):
|
def get_payload(listening, api_key, conf):
|
||||||
track = listening.track
|
track = listening.track
|
||||||
|
|
||||||
|
# See https://github.com/krateng/maloja/blob/master/API.md
|
||||||
payload = {
|
payload = {
|
||||||
"key": api_key,
|
"key": api_key,
|
||||||
"artists": [track.artist.name],
|
"artists": [track.artist.name],
|
||||||
"title": track.title,
|
"title": track.title,
|
||||||
"time": int(listening.creation_date.timestamp()),
|
"time": int(listening.creation_date.timestamp()),
|
||||||
|
"nofix": bool(conf.get("nofix")),
|
||||||
}
|
}
|
||||||
|
|
||||||
if track.album:
|
if track.album:
|
||||||
if track.album.title:
|
if track.album.title:
|
||||||
payload["album"] = track.album.title
|
payload["album"] = track.album.title
|
||||||
|
if track.album.artist:
|
||||||
|
payload["albumartists"] = [track.album.artist.name]
|
||||||
|
|
||||||
|
upload = track.uploads.filter(duration__gte=0).first()
|
||||||
|
if upload:
|
||||||
|
payload["length"] = upload.duration
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
|
|
|
@ -5,10 +5,16 @@ PLUGIN = plugins.get_plugin_config(
|
||||||
label="Maloja",
|
label="Maloja",
|
||||||
description="A plugin that allows you to submit your listens to your Maloja server.",
|
description="A plugin that allows you to submit your listens to your Maloja server.",
|
||||||
homepage="https://docs.funkwhale.audio/users/builtinplugins.html#maloja-plugin",
|
homepage="https://docs.funkwhale.audio/users/builtinplugins.html#maloja-plugin",
|
||||||
version="0.1.1",
|
version="0.2",
|
||||||
user=True,
|
user=True,
|
||||||
conf=[
|
conf=[
|
||||||
{"name": "server_url", "type": "text", "label": "Maloja server URL"},
|
{"name": "server_url", "type": "text", "label": "Maloja server URL"},
|
||||||
{"name": "api_key", "type": "text", "label": "Your Maloja API key"},
|
{"name": "api_key", "type": "text", "label": "Your Maloja API key"},
|
||||||
|
{
|
||||||
|
"name": "nofix",
|
||||||
|
"type": "boolean",
|
||||||
|
"label": "Skip server-side metadata fixing",
|
||||||
|
"default": False,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Maloja: Submit album artists and duration and allow to disable server side metadata fixing
|
Loading…
Reference in New Issue