From ab61ff7e9b230f27e056f4653c7aea86aed47fee Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Fri, 17 May 2024 13:37:49 +0200 Subject: [PATCH] feat: added the option to select all at options at the same time --- music_kraken/cli/main_downloader.py | 38 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/music_kraken/cli/main_downloader.py b/music_kraken/cli/main_downloader.py index b443ac0..c5ba8a9 100644 --- a/music_kraken/cli/main_downloader.py +++ b/music_kraken/cli/main_downloader.py @@ -365,24 +365,30 @@ class Downloader: self.search(":".join(input_str.split(":")[1:])) return False - indices = [] - for possible_index in query.split(","): - possible_index = possible_index.strip() - if possible_index == "": - continue - - i = 0 - try: - i = int(possible_index) - except ValueError: - raise MKInvalidInputException(message=f"The index \"{possible_index}\" is not a number.") + def get_selected_objects(q: str): + if q.strip().lower() == "all": + return list(self.current_results) - if i < 0 or i >= len(self.current_results): - raise MKInvalidInputException(message=f"The index \"{i}\" is not within the bounds of 0-{len(self.current_results) - 1}.") - - indices.append(i) + indices = [] + for possible_index in q.split(","): + possible_index = possible_index.strip() + if possible_index == "": + continue + + i = 0 + try: + i = int(possible_index) + except ValueError: + raise MKInvalidInputException(message=f"The index \"{possible_index}\" is not a number.") - selected_objects = [self.current_results[i] for i in indices] + if i < 0 or i >= len(self.current_results): + raise MKInvalidInputException(message=f"The index \"{i}\" is not within the bounds of 0-{len(self.current_results) - 1}.") + + indices.append(i) + + return [self.current_results[i] for i in indices] + + selected_objects = get_selected_objects(query) if do_merge: old_selected_objects = selected_objects