From 6a3fc13a4f55f244ef0e7e433f2a1c8410140a93 Mon Sep 17 00:00:00 2001 From: duck <113956421+duckfromdiscord@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:16:55 -0500 Subject: [PATCH] add optional base64 image parameter to `newscrobble` --- maloja/apis/native_v1.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index 1ea2716..f129eae 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -596,6 +596,7 @@ def post_scrobble( length:int=None, time:int=None, nofix=None, + image=None, auth_result=None, **extra_kwargs): """Submit a new scrobble. @@ -609,6 +610,7 @@ def post_scrobble( :param int length: Total length of the track in seconds. Optional. :param int time: UNIX timestamp of the scrobble. Optional, not needed if scrobble is at time of request. :param flag nofix: Skip server-side metadata parsing. Optional. + :param string image: Base64 encoded album art. Optional. :return: status (String), track (Mapping) :rtype: Dictionary @@ -655,6 +657,22 @@ def post_scrobble( {'type':'mixed_schema','value':['artist','artists'], 'desc':"These two fields are meant as alternative methods to submit information. Use of both is discouraged, but works at the moment."} ] + if image: + # Using the parameters supplied directly won't work because they aren't parsed + # for example, album artists will be all one big string instead of an array of strings + # we also need to check if the track has an album before we decide to give just the track the art + # so take details from `result` + albumartists = result['track']['album']['artists'] + artists = result['track']['artists'] + album = result['track']['album']['albumtitle'] + title = result['track']['title'] + if album: + # Album artists take priority, in case the album artist is different from the track artist + # We want the image to apply to the entire album + images.set_image(image,artists=albumartists or artists,albumtitle=album) + else: + # we could not find an album associated with this track + images.set_image(image,artists=artists,title=title) if len(responsedict['warnings']) == 0: del responsedict['warnings']