diff --git a/docs/release-history.rst b/docs/release-history.rst index 6fd78edd..c865674d 100644 --- a/docs/release-history.rst +++ b/docs/release-history.rst @@ -35,6 +35,17 @@ This project adheres to a modified `Calendar Versioning `_ * ``M`` = The current month * ``P`` = An 0-indexed incrementing index for the release version for this month +2024.1.6 +======== + +Fixed +----- + +* Rename __max_str in local/collection.py to _max_str - functions could not see variable +* Add default value of 0 to sort_key in ItemSorter.sort_by_field +* Fixed RemoteItemChecker _pause logic to only get playlist name when input is not False-y + + 2024.1.5 ======== diff --git a/musify/local/collection.py b/musify/local/collection.py index a03d03c8..247af9fa 100644 --- a/musify/local/collection.py +++ b/musify/local/collection.py @@ -30,7 +30,7 @@ from musify.shared.types import UnitIterable from musify.shared.utils import get_most_common_values, to_collection, align_and_truncate, get_max_width -__max_str = "z" * 50 +_max_str = "z" * 50 class LocalCollection[T: LocalTrack](ItemCollection[T], metaclass=ABCMeta): @@ -326,7 +326,7 @@ def __init__( tracks = [load_track(path) for path in glob(join(name, "*")) if splitext(path)[1] in TRACK_FILETYPES] name = basename(name) super().__init__(tracks=tracks, name=name, remote_wrangler=remote_wrangler) - self.tracks.sort(key=lambda x: x.filename or __max_str) + self.tracks.sort(key=lambda x: x.filename or _max_str) def set_compilation_tags(self) -> None: """ @@ -441,7 +441,7 @@ def __init__( ): super().__init__(tracks=tracks, name=name, remote_wrangler=remote_wrangler) self.tracks.sort( - key=lambda x: (x.disc_number or sys.maxsize, x.track_number or sys.maxsize, x.filename or __max_str) + key=lambda x: (x.disc_number or sys.maxsize, x.track_number or sys.maxsize, x.filename or _max_str) ) self._image_links: dict[str, str] = {} @@ -477,10 +477,10 @@ def __init__( ): super().__init__(tracks=tracks, name=name, remote_wrangler=remote_wrangler) self.tracks.sort( - key=lambda x: (x.album or __max_str, + key=lambda x: (x.album or _max_str, x.disc_number or sys.maxsize, x.track_number or sys.maxsize, - x.filename or __max_str) + x.filename or _max_str) ) @@ -509,9 +509,9 @@ def __init__( ): super().__init__(tracks=tracks, name=name, remote_wrangler=remote_wrangler) self.tracks.sort( - key=lambda x: (x.artist or __max_str, - x.album or __max_str, + key=lambda x: (x.artist or _max_str, + x.album or _max_str, x.disc_number or sys.maxsize, x.track_number or sys.maxsize, - x.filename or __max_str) + x.filename or _max_str) ) diff --git a/musify/processors/sort.py b/musify/processors/sort.py index 196996c5..67d06267 100644 --- a/musify/processors/sort.py +++ b/musify/processors/sort.py @@ -95,7 +95,7 @@ def sort_key(t: Item) -> float: elif isinstance(example_value, str): # key strips ignore words from string sort_key: Callable[[Item], (bool, str)] = lambda t: strip_ignore_words(t[tag_name]) else: - sort_key: Callable[[Item], object] = lambda t: t[tag_name] + sort_key: Callable[[Item], object] = lambda t: t[tag_name] if t[tag_name] else 0 items.sort(key=sort_key, reverse=reverse) diff --git a/musify/shared/remote/processors/check.py b/musify/shared/remote/processors/check.py index 7d459120..9145f26e 100644 --- a/musify/shared/remote/processors/check.py +++ b/musify/shared/remote/processors/check.py @@ -260,7 +260,10 @@ def _pause(self, page: int, total: int) -> None: print("\n" + help_text) while current_input != '': # while user has not hit return only current_input = self._get_user_input(f"Enter ({page}/{total})") - pl_names = [name for name in self._playlist_name_collection if current_input.casefold() in name.casefold()] + pl_name = next( + name for name in self._playlist_name_collection + if current_input and current_input.casefold() in name.casefold() + ) if current_input.casefold() == "h": # print help text print("\n" + help_text) @@ -270,12 +273,11 @@ def _pause(self, page: int, total: int) -> None: self._skip = current_input.casefold() == 's' or self._skip break - elif pl_names: # print originally added items - name = pl_names[0] - items = [item for item in self._playlist_name_collection[name] if item.has_uri] + elif pl_name: # print originally added items + items = [item for item in self._playlist_name_collection[pl_name] if item.has_uri] max_width = get_max_width(items) - print(f"\n\t\33[96mShowing items originally added to \33[94m{name}\33[0m:\n") + print(f"\n\t\33[96mShowing items originally added to \33[94m{pl_name}\33[0m:\n") for i, item in enumerate(items, 1): length = getattr(item, "length", 0) self.api.print_item(