diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index 06aba79..1e3cfab 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -504,6 +504,32 @@ def post_scrobble( +@api.post("addpicture") +@authenticated_function(alternate=api_key_correct,api=True) +@catch_exceptions +def add_picture(b64,artist:Multi=[],title=None): + """Uploads a new image for an artist or track. + + param string b64: Base 64 representation of the image + param string artist: Artist name. Can be supplied multiple times for tracks with multiple artists. + param string title: Title of the track. Optional. + + """ + keys = FormsDict() + for a in artist: + keys.append("artist",a) + if title is not None: keys.append("title",title) + k_filter, _, _, _, _ = uri_to_internal(keys) + if "track" in k_filter: k_filter = k_filter["track"] + url = images.set_image(b64,**k_filter) + + return { + 'status': 'success', + 'url': url + } + + + @api.post("importrules") @authenticated_function(api=True) @catch_exceptions @@ -582,20 +608,6 @@ def search(**keys): return {"artists":artists_result[:max_],"tracks":tracks_result[:max_]} -@api.post("addpicture") -@authenticated_function(api=True) -@catch_exceptions -def add_picture(b64,artist:Multi=[],title=None): - """Internal Use Only""" - keys = FormsDict() - for a in artist: - keys.append("artist",a) - if title is not None: keys.append("title",title) - k_filter, _, _, _, _ = uri_to_internal(keys) - if "track" in k_filter: k_filter = k_filter["track"] - images.set_image(b64,**k_filter) - - @api.post("newrule") @authenticated_function(api=True) @catch_exceptions diff --git a/maloja/images.py b/maloja/images.py index 80802ed..8421d0c 100644 --- a/maloja/images.py +++ b/maloja/images.py @@ -298,3 +298,5 @@ def set_image(b64,**keys): # set as current picture in rotation if track: set_image_in_cache(id,'tracks',os.path.join("/images",folder,filename)) else: set_image_in_cache(id,'artists',os.path.join("/images",folder,filename)) + + return os.path.join("/images",folder,filename)