case insensitive music dir sorting
This commit is contained in:
parent
685be38c83
commit
9ec3f73d7f
1 changed files with 11 additions and 6 deletions
|
@ -5,21 +5,26 @@ from graphics import Graphics
|
|||
from .player import MusicPlayer
|
||||
|
||||
def execute(cinput: ControlInput, graphics: Graphics, directory: str):
|
||||
is_resume = directory != "music"
|
||||
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)
|
||||
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()
|
||||
for fname in sorted(listdir(directory)):
|
||||
for fname in sorted(listdir(directory), key=str.casefold):
|
||||
new_path = path.join(directory, fname)
|
||||
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:
|
||||
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": sub_menu})
|
||||
else:
|
||||
if dirname.startswith("_"):
|
||||
return MenuItem(dirname.lstrip("_"), MenuType.CMD, {"random": directory})
|
||||
return MenuItem(dirname.lstrip("_"), MenuType.CMD, {
|
||||
"dir": directory,
|
||||
"mode": "random"})
|
||||
else:
|
||||
return MenuItem(dirname, MenuType.CMD, {"album": directory})
|
||||
return MenuItem(dirname, MenuType.CMD, {
|
||||
"dir": directory,
|
||||
"mode": "resume" if is_resume else "album"})
|
||||
|
|
Reference in a new issue