def add_picture(b64,key,artist:Multi=[],title=None): if (checkAPIkey(key)): 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"] utilities.set_image(b64,**k_filter)
def trackInfo_external(artist:Multi[str],**keys): # transform into a multidict so we can use our nomral uri_to_internal function keys = FormsDict(keys) for a in artist: keys.append("artist",a) k_filter, _, _, _ = uri_to_internal(keys,forceTrack=True) ckeys = {**k_filter} results = trackInfo(**ckeys) return results
def remove_identical(*dicts): #combine multiple dicts keys = FormsDict() for d in dicts: for k in d: try: #multidicts for v in d.getall(k): keys.append(k, v) except: #normaldicts v = d.get(k) keys.append(k, v) return keys
def pickKeys(d,*keys): if isinstance(d,dict): return {k:d.get(k) for k in d if k in keys} else: # create a normal dictionary of lists newd = {k:d.getall(k) for k in d if k in keys} # one by one add the list entries to the formsdict finald = FormsDict() for k in newd: for v in newd.get(k): finald.append(k,v) return finald
def remove_identical(*dicts): #combine multiple dicts keys = FormsDict() for d in dicts: for k in d: try: #multidicts for v in d.getall(k): keys.append(k, v) except: #normaldicts v = d.get(k) keys.append(k, v) new = FormsDict() for k in keys: #values = set(keys.getall(k)) values = keys.getall(k) # NO IDENTICAL REMOVAL FOR NOW for v in values: new.append(k, v) return new
def internal_to_uri(keys): urikeys = FormsDict() #filter if "artist" in keys: urikeys.append("artist", keys["artist"]) if keys.get("associated"): urikeys.append("associated", "yes") elif "track" in keys: for a in keys["track"]["artists"]: urikeys.append("artist", a) urikeys.append("title", keys["track"]["title"]) #time if "timerange" in keys: keydict = keys["timerange"].urikeys() for k in keydict: urikeys.append(k, keydict[k]) elif "within" in keys: urikeys.append("in", time_str(keys["within"])) else: if "since" in keys and keys["since"] is not None: urikeys.append("since", time_str(keys["since"])) if "to" in keys and keys["to"] is not None: urikeys.append("to", time_str(keys["to"])) # delimit if "step" in keys: urikeys.append("step", keys["step"]) if "stepn" in keys: urikeys.append("stepn", str(keys["stepn"])) if "trail" in keys: if keys["trail"] == math.inf: urikeys.append("cumulative", "yes") else: urikeys.append("trail", str(keys["trail"])) # stuff #if "max_" in keys: # urikeys.append("max",str(keys["max_"])) if "page" in keys: urikeys.append("page", str(keys["page"])) if "perpage" in keys: urikeys.append("perpage", str(keys["perpage"])) return urikeys