Skip to content

Commit

Permalink
various hotfixes: checker playlist name on pause + __max_str scope + …
Browse files Browse the repository at this point in the history
…default value on sort_by_field
  • Loading branch information
geo-martino committed Jan 24, 2024
1 parent edbff97 commit 9d99b7f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
11 changes: 11 additions & 0 deletions docs/release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ This project adheres to a modified `Calendar Versioning <https://calver.org/>`_
* ``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
========

Expand Down
16 changes: 8 additions & 8 deletions musify/local/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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] = {}

Expand Down Expand Up @@ -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)
)


Expand Down Expand Up @@ -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)
)
2 changes: 1 addition & 1 deletion musify/processors/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions musify/shared/remote/processors/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 9d99b7f

Please sign in to comment.