0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-26 21:53:54 +01:00

advisor-less mode

This commit is contained in:
2025-12-12 20:01:35 +01:00
parent bf980f7b3e
commit 25169d67f1
4 changed files with 33 additions and 26 deletions

View File

@@ -125,7 +125,7 @@ class ActiveModifier(BaseIMCModule):
Called at start up with the program arguments
"""
pass
def play(self, index: int, track: Track, next_track: Track | None) -> tuple[tuple[Track, None] | tuple[Track, Track], bool] | tuple[tuple[None, None], None]:
def play(self, index: int, track: Track | None, next_track: Track | None) -> tuple[tuple[Track | None, Track | None], bool | None]:
"""
Returns a tuple, in the first case where a is the track and b is a bool, b corresponds to whether to extend the playlist, set to true when adding content instead of replacing it
When None, None is returned then that is treated as a skip, meaning the core will skip this song

View File

@@ -26,7 +26,10 @@ class Module(ActiveModifier):
self.limit_tracks = not bool(self.limit_tracks)
if self.limit_tracks: logger.info("Skipping tracks if they bleed into other times.")
self.can_limit_tracks = self.limit_tracks
def play(self, index: int, track: Track, next_track: Track | None):
def play(self, index: int, track: Track | None, next_track: Track | None):
if not track:
raise NotImplementedError("This active modifer does not support advisor-less mode")
if not self.playlist: return (track, next_track), False
with self.file_lock:

View File

@@ -13,3 +13,4 @@ Each module shall have a python script in the modules directory. Each of the mod
- activemod ('ActiveModifier')
NEW! The procman communicator allows you to get the track duration, but also STOP WHATEVER IS PLAYING! That means we can skip tracks WHILE THEY ARE PLAYING
Newer! You can run advisor-less, this however also remvoes the usage of any and all playlist modifiers, because there is no playlist in such case

View File

@@ -208,20 +208,19 @@ class RadioPlayer:
"""Single functon for starting the core, returns but might exit raising an SystemExit"""
self.logger.info("Core starting, loading modules")
self.load_modules();self.start_modules()
if not self.playlist_advisor:
self.logger.critical_error("Playlist advisor was not found")
raise SystemExit(1)
if not self.playlist_advisor: self.logger.warning("Playlist advisor was not found. Beta mode of advisor-less is running (playlist modifiers will not work)")
def play_once(self):
"""Plays a single playlist"""
if not self.playlist_advisor or not (playlist_path := self.playlist_advisor.advise(self.arg)): return
if self.playlist_advisor:
if not (playlist_path := self.playlist_advisor.advise(self.arg)): return
try: global_args, parsed = self.parser.parse(playlist_path)
except Exception as e:
self.logger.info(f"Exception ({e}) while parsing playlist, retrying in 15 seconds...");traceback.print_exc(file=self.logger.output)
time.sleep(15)
return
playlist: list[Track] = []
playlist: list[Track] | None = []
[playlist.extend(Track(Path(line).absolute(), True, True, True, args) for line in lns) for (lns, args) in parsed] # i can read this, i think
[(playlist := module.modify(global_args, playlist) or playlist) for module in self.playlist_modifier_modules if module] # yep
@@ -230,19 +229,23 @@ class RadioPlayer:
prefetch(playlist[0].path)
[mod.on_new_playlist(playlist) for mod in self.simple_modules + [self.active_modifier] if mod] # one liner'd everything
return_pending = track = False
cross_fade = int(global_args.get("crossfade", 5))
max_iterator = len(playlist)
else:
max_iterator = 1
playlist = None
global_args = {}
return_pending = track = False
cross_fade = int(global_args.get("crossfade", 5))
song_i = i = 0
def get_track():
nonlocal song_i, playlist, max_iterator
track = None
while track is None:
if playlist:
playlist_track = playlist[song_i % len(playlist)]
playlist_next_track = playlist[song_i + 1] if song_i + 1 < len(playlist) else None
else: playlist_track = playlist_next_track = None
if self.active_modifier:
(track, next_track), extend = self.active_modifier.play(song_i, playlist_track, playlist_next_track)
if track is None: song_i += 1