def do_search(query="",node="playlist"):
dev=conf['dev']
app_id=conf['app_id']
url=f'https://www.qobuz.com/api.json/0.2/{node}/search?query={query}&limit=100&offset=0&app_id={app_id}'
try:
ret = requests.get(url).json()
items = ret[f"{node}s"]["items"]
except:
return ""
options=[]
idx=1
for item in items:
if node=="album":
preview=[str(item["id"]),str(item["artist"]["id"]),f'Tracks: {item["tracks_count"]}',f'Released: {item["release_date_original"]}', f'Quality: {item["maximum_bit_depth"]}/{item["maximum_sampling_rate"]}']
preview="~".join(preview)
option = f'{idx} {item["artist"]["name"]} - {item["title"]}|{preview}'
else:
preview=f'{item["name"]}^Tracks: {item["tracks_count"]}^{item["description"]}'
option = f'{idx} {item["name"]}|{preview}'
options.append(option)
idx = idx+1
terminal_menu = TerminalMenu(options,
clear_screen=True,
title="Enter:Play Esc:Exit",
preview_command=from_title,
preview_size=0.5)
menu_entry_index = terminal_menu.show()
if menu_entry_index == None:
return
else:
if node=="album":
list_name=items[menu_entry_index]["title"].replace("&","&")
extra=""
else:
list_name=items[menu_entry_index]["name"].replace("&","&")
extra="&extra=tracks,subscribers&limit=100&"
list_name = list_name.upper()
item_id=items[menu_entry_index]["id"]
user_auth_token=conf["accessToken"]
Login_username=conf["Login_username"]
xml = f'<?xml version="1.0"?><PlayList><ListName>{list_name}</ListName><ListInfo><SourceName>Qobuz</SourceName><requestQuality>6</requestQuality> <SearchUrl>https://www.qobuz.com/api.json/0.2/{node}/get?{node}_id={item_id}{extra}</SearchUrl><Login_username>{Login_username}</Login_username></ListInfo></PlayList>'
#### Populate the WiiM Queue
dev.PlayQueue.CreateQueue(QueueContext=xml)
#### Play
dev.PlayQueue.PlayQueueWithIndex(QueueName=list_name,Index=0)