2021-03-14 07:30:29 +00:00
|
|
|
from python_console_menu import AbstractMenu, MenuItem
|
|
|
|
import subprocess
|
|
|
|
|
2021-03-16 08:13:48 +00:00
|
|
|
from config import player, options, maxitems
|
2021-03-15 20:46:15 +00:00
|
|
|
|
2021-03-14 07:30:29 +00:00
|
|
|
|
|
|
|
class RadioMenu(AbstractMenu):
|
|
|
|
def __init__(self, station_list=None):
|
|
|
|
super().__init__("Radio Player Menu")
|
|
|
|
if station_list is None:
|
|
|
|
station_list = []
|
|
|
|
|
|
|
|
for i in range(len(station_list)):
|
2021-03-16 09:41:38 +00:00
|
|
|
if i < maxitems(): # The very first item is the exit option, so not "<=".
|
2021-03-16 08:13:48 +00:00
|
|
|
self.add_menu_item(
|
|
|
|
MenuItem(
|
|
|
|
i,
|
2021-03-16 09:45:15 +00:00
|
|
|
"{:<30}".format(station_list[i]["name"][:30]) + " " + # force 35 character fixed length
|
2021-03-16 09:41:38 +00:00
|
|
|
"{:<5}".format(station_list[i]["codec"][:5]) + " " + # force 5 character fixed length
|
|
|
|
"{:<5}".format(station_list[i]["bitrate"][:5]) + " " +
|
2021-03-16 08:13:48 +00:00
|
|
|
station_list[i]["url"],
|
|
|
|
lambda url=station_list[i]["url"]: subprocess.run([player(), options(), url])
|
|
|
|
)
|
2021-03-14 07:30:29 +00:00
|
|
|
)
|
2021-03-16 08:13:48 +00:00
|
|
|
else:
|
|
|
|
break
|
2021-03-14 07:30:29 +00:00
|
|
|
|
|
|
|
def initialise(self):
|
2021-03-16 08:13:48 +00:00
|
|
|
self.add_menu_item(MenuItem(maxitems(), "Exit menu").set_as_exit_option())
|