From feb5277d7bb936bc7266d73c08268d2114ed2195 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Tue, 16 Mar 2021 08:13:48 +0000 Subject: [PATCH] max menu items = 9999; this isn't really supposed to give you the entire database --- .gitignore | 1 + config.py | 4 ++++ radiomenu.py | 25 ++++++++++++++----------- radiostations.ini | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 5186c2d..dce4838 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ .idea/ *.lock +*.iml diff --git a/config.py b/config.py index 995ce98..a15a091 100644 --- a/config.py +++ b/config.py @@ -15,3 +15,7 @@ def player(): def options(): return config.get('DEFAULT', 'player.options') + +def maxitems(): + return int(config.get('DEFAULT', 'menu_items.max')) + diff --git a/radiomenu.py b/radiomenu.py index 05d3dab..e88a7d8 100644 --- a/radiomenu.py +++ b/radiomenu.py @@ -1,7 +1,7 @@ from python_console_menu import AbstractMenu, MenuItem import subprocess -from config import player, options +from config import player, options, maxitems class RadioMenu(AbstractMenu): @@ -11,16 +11,19 @@ class RadioMenu(AbstractMenu): station_list = [] for i in range(len(station_list)): - self.add_menu_item( - MenuItem( - i, - station_list[i]["name"] + " " + - station_list[i]["codec"] + " " + - station_list[i]["bitrate"] + " " + - station_list[i]["url"], - lambda url=station_list[i]["url"]: subprocess.run([player(), options(), url]) + if i < maxitems(): # The last item is the exit option, so not "<=". + self.add_menu_item( + MenuItem( + i, + station_list[i]["name"] + " " + + station_list[i]["codec"] + " " + + station_list[i]["bitrate"] + " " + + station_list[i]["url"], + lambda url=station_list[i]["url"]: subprocess.run([player(), options(), url]) + ) ) - ) + else: + break def initialise(self): - self.add_menu_item(MenuItem(9999, "Exit menu").set_as_exit_option()) + self.add_menu_item(MenuItem(maxitems(), "Exit menu").set_as_exit_option()) diff --git a/radiostations.ini b/radiostations.ini index 787fc00..670de80 100644 --- a/radiostations.ini +++ b/radiostations.ini @@ -2,4 +2,4 @@ radio_browser.api=all.api.radio-browser.info player.command=mpv player.options=--no-video - +menu_items.max=9999