From 9d4e3e8545d245bd5966cc91d33625a7cb36356d Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Wed, 8 May 2024 12:23:16 +0200 Subject: [PATCH] fix: bounds get respected --- development/actual_donwload.py | 3 ++- music_kraken/cli/main_downloader.py | 8 ++++---- music_kraken/download/results.py | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/development/actual_donwload.py b/development/actual_donwload.py index c5c3890..548e228 100644 --- a/development/actual_donwload.py +++ b/development/actual_donwload.py @@ -7,7 +7,8 @@ logging.getLogger().setLevel(logging.DEBUG) if __name__ == "__main__": commands = [ "s: #a Crystal F", - "10" + "10", + "2", ] diff --git a/music_kraken/cli/main_downloader.py b/music_kraken/cli/main_downloader.py index 73812cd..f9321b4 100644 --- a/music_kraken/cli/main_downloader.py +++ b/music_kraken/cli/main_downloader.py @@ -378,13 +378,13 @@ class Downloader: continue i = 0 - if possible_index.isdigit(): + try: i = int(possible_index) - else: + except ValueError: raise MKInvalidInputException(message=f"The index \"{possible_index}\" is not a number.") - if i < 0 and i >= len(self.current_results): - raise MKInvalidInputException(message=f"The index \"{i}\" is not within the bounds of 0-{len(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) diff --git a/music_kraken/download/results.py b/music_kraken/download/results.py index a96d152..a8fead7 100644 --- a/music_kraken/download/results.py +++ b/music_kraken/download/results.py @@ -28,6 +28,9 @@ class Results: self._by_index = dict() self._page_by_index = dict() + def __len__(self) -> int: + return max(self._by_index.keys()) + def __getitem__(self, index: int): return self._by_index[index]