This repository has been archived on 2022-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
zeropod/plugin/music/__init__.py

23 lines
907 B
Python
Raw Normal View History

2022-12-28 10:14:33 -06:00
from os import path, listdir
from menu import Menu, MenuItem, MenuType
from cinput import ControlInput
from graphics import Graphics
from .player import MusicPlayer
def execute(cinput: ControlInput, graphics: Graphics, directory: str):
current_dir = path.join("/home/rudism", directory)
top_menu = create_directory_menu(current_dir, "music")
menu = Menu(top_menu.data["sub_dir"], cinput, graphics)
MusicPlayer(cinput, graphics, menu).run()
def create_directory_menu(directory: str, dirname: str):
sub_menu = list()
for fname in listdir(directory):
new_path = path.join(directory, fname)
if path.isdir(new_path):
sub_menu.append(create_directory_menu(new_path, fname))
if len(sub_menu) > 0:
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": sub_menu})
else:
return MenuItem(dirname, MenuType.CMD, {"directory": directory})