Improve error handling of interactive search

searchSelected -> processSelected
    Preselect "Lossless" quality
This commit is contained in:
François Charette 2020-12-05 19:14:11 +01:00
parent 607b0d2795
commit 432b7f250c

11
main.py
View File

@ -56,7 +56,7 @@ def get_id(url):
).group(1) ).group(1)
def searchSelected(Qz, path, albums, ids, types, quality): def processSelected(Qz, path, albums, ids, types, quality):
q = ["5", "6", "7", "27"] q = ["5", "6", "7", "27"]
quality = q[quality[1]] quality = q[quality[1]]
for alb, id_, type_ in zip(albums, ids, types): for alb, id_, type_ in zip(albums, ids, types):
@ -110,8 +110,12 @@ def interactive(Qz, path, limit, tracks=True):
while True: while True:
query = input("\nEnter your search: [Ctrl + c to quit]\n- ") query = input("\nEnter your search: [Ctrl + c to quit]\n- ")
print("Searching...") print("Searching...")
if len(query.strip())==0:
break
start = Search(Qz, query, limit) start = Search(Qz, query, limit)
start.getResults(tracks) start.getResults(tracks)
if len(start.Total)==0:
break
Types.append(start.Types) Types.append(start.Types)
IDs.append(start.IDs) IDs.append(start.IDs)
@ -134,13 +138,14 @@ def interactive(Qz, path, limit, tracks=True):
else: else:
break break
if len(Albums)>0:
desc = ( desc = (
"Select [intro] the quality (the quality will be automat" "Select [intro] the quality (the quality will be automat"
"ically\ndowngraded if the selected is not found)" "ically\ndowngraded if the selected is not found)"
) )
Qualits = ["320", "Lossless", "Hi-res =< 96kHz", "Hi-Res > 96 kHz"] Qualits = ["320", "Lossless", "Hi-res =< 96kHz", "Hi-Res > 96 kHz"]
quality = pick(Qualits, desc) quality = pick(Qualits, desc, default_index=1)
searchSelected(Qz, path, Albums, IDs, Types, quality) processSelected(Qz, path, Albums, IDs, Types, quality)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit("\nBye") sys.exit("\nBye")