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 1/2] 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 1ea2716a..f129eae4 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'] From 8a1db5a64c42673708ad87ddeffaba6977772fb0 Mon Sep 17 00:00:00 2001 From: duck <113956421+duckfromdiscord@users.noreply.github.com> Date: Mon, 6 May 2024 11:17:57 -0400 Subject: [PATCH 2/2] specify album and track images separately --- maloja/apis/native_v1.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index f129eae4..77c68d04 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -596,7 +596,8 @@ def post_scrobble( length:int=None, time:int=None, nofix=None, - image=None, + album_image=None, + track_image=None, auth_result=None, **extra_kwargs): """Submit a new scrobble. @@ -610,7 +611,8 @@ 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. + :param string album_image: Data URI base64 encoded album art. Optional. + :param string track_image: Data URI base64 encoded track art. Optional. :return: status (String), track (Mapping) :rtype: Dictionary @@ -657,22 +659,19 @@ 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: + if album_image or track_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 album_image: + if 'album' in result['track']: + albumartists = result['track']['album']['artists'] + album = result['track']['album']['albumtitle'] + images.set_image(album_image,artists=albumartists or artists,albumtitle=album) + if track_image: + images.set_image(track_image,artists=artists,title=title) if len(responsedict['warnings']) == 0: del responsedict['warnings']