added track submenu to music

This commit is contained in:
Rudis Muiznieks 2022-12-28 11:12:15 -06:00
parent 9ec3f73d7f
commit b8e091a135
Signed by: rudism
GPG key ID: CABF2F86EF7884F9

View file

@ -12,19 +12,33 @@ def execute(cinput: ControlInput, graphics: Graphics, directory: str):
MusicPlayer(cinput, graphics, menu).run()
def create_directory_menu(directory: str, dirname: str, is_resume: bool):
sub_menu = list()
dir_menu = list()
track_menu = list()
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, 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, {
dir_menu.append(create_directory_menu(new_path, fname, is_resume))
elif fname.lower().endswith((".mp3", ".ogg")):
track_menu.append(MenuItem(fname, MenuType.CMD, {
"dir": directory,
"mode": "random"})
else:
"mode": "single",
"track": fname}))
if len(dir_menu) > 0:
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": dir_menu})
else:
if is_resume:
return MenuItem(dirname, MenuType.CMD, {
"dir": directory,
"mode": "resume" if is_resume else "album"})
"mode": "resume"})
else:
return MenuItem(dirname, MenuType.SUB_MENU, {
"sub_menu": [
MenuItem("Play", MenuType.CMD, {
"dir": directory,
"mode": "album"}),
MenuItem("Randomize", MenuType.CMD, {
"dir": directory,
"mode": "random"}),
MenuItem("View Tracks", MenuType.SUB_MENU, {
"sub_menu": track_menu})
]})