add optional base64 image parameter to newscrobble

This commit is contained in:
duck 2024-01-21 22:16:55 -05:00
parent ac5c58c919
commit 6a3fc13a4f

View File

@ -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']