case insensitive music dir sorting

This commit is contained in:
Rudis Muiznieks 2022-12-28 10:51:41 -06:00
parent 685be38c83
commit 9ec3f73d7f
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
1 changed files with 11 additions and 6 deletions

View File

@ -5,21 +5,26 @@ from graphics import Graphics
from .player import MusicPlayer from .player import MusicPlayer
def execute(cinput: ControlInput, graphics: Graphics, directory: str): def execute(cinput: ControlInput, graphics: Graphics, directory: str):
is_resume = directory != "music"
current_dir = path.join("/home/rudism", directory) current_dir = path.join("/home/rudism", directory)
top_menu = create_directory_menu(current_dir, "music") top_menu = create_directory_menu(current_dir, "music", is_resume)
menu = Menu(top_menu.data["sub_menu"], cinput, graphics) menu = Menu(top_menu.data["sub_menu"], cinput, graphics)
MusicPlayer(cinput, graphics, menu).run() MusicPlayer(cinput, graphics, menu).run()
def create_directory_menu(directory: str, dirname: str): def create_directory_menu(directory: str, dirname: str, is_resume: bool):
sub_menu = list() sub_menu = list()
for fname in sorted(listdir(directory)): for fname in sorted(listdir(directory), key=str.casefold):
new_path = path.join(directory, fname) new_path = path.join(directory, fname)
if path.isdir(new_path): if path.isdir(new_path):
sub_menu.append(create_directory_menu(new_path, fname)) sub_menu.append(create_directory_menu(new_path, fname, is_resume))
if len(sub_menu) > 0: if len(sub_menu) > 0:
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": sub_menu}) return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": sub_menu})
else: else:
if dirname.startswith("_"): if dirname.startswith("_"):
return MenuItem(dirname.lstrip("_"), MenuType.CMD, {"random": directory}) return MenuItem(dirname.lstrip("_"), MenuType.CMD, {
"dir": directory,
"mode": "random"})
else: else:
return MenuItem(dirname, MenuType.CMD, {"album": directory}) return MenuItem(dirname, MenuType.CMD, {
"dir": directory,
"mode": "resume" if is_resume else "album"})