You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
move the argument parsing into the advisor, which means the advisor is now always neccesary
This commit is contained in:
@@ -2,7 +2,7 @@ class PlaylistAdvisor:
|
||||
"""
|
||||
Only one of a playlist advisor can be loaded. This module picks the playlist file to play, this can be a scheduler or just a static file
|
||||
"""
|
||||
def advise(self) -> str: return "/path/to/playlist.txt"
|
||||
def advise(self, arguments: str | None) -> str: return "/path/to/playlist.txt"
|
||||
def new_playlist(self) -> int:
|
||||
"""
|
||||
Whether to play a new playlist, if this is 1, then the player will refresh, if this is two then the player will refresh quietly
|
||||
@@ -56,7 +56,13 @@ class Module(PlaylistAdvisor):
|
||||
def __init__(self) -> None:
|
||||
self.last_mod_time = 0
|
||||
self.last_playlist = None
|
||||
def advise(self) -> str:
|
||||
self.custom_playlist = None
|
||||
def advise(self, arguments: str | None) -> str:
|
||||
if self.custom_playlist: return self.custom_playlist
|
||||
if arguments and arguments.startswith("list:"):
|
||||
self.custom_playlist = arguments.removeprefix("list:")
|
||||
logger.info(f"The list {arguments.split(';')[0]} will be played instead of the daily section lists.")
|
||||
return self.custom_playlist
|
||||
current_day, current_hour = datetime.datetime.now().strftime('%A').lower(), datetime.datetime.now().hour
|
||||
|
||||
morning_playlist = os.path.join(playlist_dir, current_day, 'morning')
|
||||
@@ -100,6 +106,7 @@ class Module(PlaylistAdvisor):
|
||||
self.last_playlist = night_playlist
|
||||
return night_playlist
|
||||
def new_playlist(self) -> int:
|
||||
if self.custom_playlist: return 0
|
||||
if not self.last_playlist: return 1
|
||||
time_change = check_if_playlist_modifed(self.last_playlist)
|
||||
if time_change: return 2
|
||||
|
||||
@@ -25,7 +25,7 @@ class PlaylistAdvisor:
|
||||
"""
|
||||
Only one of a playlist advisor can be loaded. This module picks the playlist file to play, this can be a scheduler or just a static file
|
||||
"""
|
||||
def advise(self) -> str: return "/path/to/playlist.txt"
|
||||
def advise(self, arguments: str | None) -> str: return "/path/to/playlist.txt"
|
||||
def new_playlist(self) -> int:
|
||||
"""
|
||||
Whether to play a new playlist, if this is 1, then the player will refresh, if this is two then the player will refresh quietly
|
||||
@@ -189,7 +189,7 @@ def parse_playlistfile(playlist_path: str):
|
||||
out.append(([f for f in glob.glob(line) if os.path.isfile(f)], arguments))
|
||||
return global_arguments, out
|
||||
|
||||
def play_playlist(playlist_path, custom_playlist: bool=False):
|
||||
def play_playlist(playlist_path):
|
||||
procman.stop_all(1)
|
||||
if not playlist_advisor: raise Exception("No playlist advisor")
|
||||
|
||||
@@ -230,8 +230,7 @@ def play_playlist(playlist_path, custom_playlist: bool=False):
|
||||
for module in simple_modules: module.on_new_track(i, track_path, to_fade_in, to_fade_out, official)
|
||||
track_name = os.path.basename(track_path)
|
||||
|
||||
if not custom_playlist: refresh = playlist_advisor.new_playlist()
|
||||
else: refresh = 0
|
||||
refresh = playlist_advisor.new_playlist()
|
||||
|
||||
if refresh == 1:
|
||||
logger.info("Reloading now...")
|
||||
@@ -252,26 +251,6 @@ def play_playlist(playlist_path, custom_playlist: bool=False):
|
||||
if official: print_wait(ttw, 1, pr.duration, f"{track_name}: ")
|
||||
else: time.sleep(ttw)
|
||||
|
||||
def parse_arguments():
|
||||
"""Parse command line arguments and return configuration"""
|
||||
arg = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
selected_list = None
|
||||
|
||||
if arg:
|
||||
if arg.lower() == "-h":
|
||||
print("Arguments:")
|
||||
print(" list:playlist - Play custom playlist, bypasses the playlist advisor")
|
||||
print()
|
||||
exit(0)
|
||||
|
||||
if arg:
|
||||
if arg.startswith("list:"):
|
||||
selected_list = arg.removeprefix("list:")
|
||||
logger.info(f"The list {selected_list.split(';')[0]} will be played instead of the daily section lists.")
|
||||
else: logger.error(f"Invalid argument or file not found: {arg}")
|
||||
|
||||
return selected_list
|
||||
|
||||
def main():
|
||||
global playlist_advisor
|
||||
for filename in os.listdir(MODULES_DIR):
|
||||
@@ -301,17 +280,11 @@ def main():
|
||||
|
||||
try:
|
||||
while True:
|
||||
selected_list = parse_arguments()
|
||||
arg = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else None
|
||||
|
||||
play_loop = True
|
||||
while play_loop:
|
||||
if selected_list:
|
||||
logger.info("Playing custom list")
|
||||
result = play_playlist(selected_list, True)
|
||||
if result == "reload": play_loop = False
|
||||
continue
|
||||
|
||||
result = play_playlist(playlist_advisor.advise())
|
||||
result = play_playlist(playlist_advisor.advise(arg))
|
||||
|
||||
if exit_pending: exit()
|
||||
elif reload_pending:
|
||||
|
||||
Reference in New Issue
Block a user