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
+1 -1
View File
@@ -125,7 +125,7 @@ class ActiveModifier(BaseIMCModule):
Called at start up with the program arguments Called at start up with the program arguments
""" """
pass 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 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 When None, None is returned then that is treated as a skip, meaning the core will skip this song
+4 -1
View File
@@ -26,7 +26,10 @@ class Module(ActiveModifier):
self.limit_tracks = not bool(self.limit_tracks) self.limit_tracks = not bool(self.limit_tracks)
if self.limit_tracks: logger.info("Skipping tracks if they bleed into other times.") if self.limit_tracks: logger.info("Skipping tracks if they bleed into other times.")
self.can_limit_tracks = self.limit_tracks 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 if not self.playlist: return (track, next_track), False
with self.file_lock: with self.file_lock:
+1
View File
@@ -13,3 +13,4 @@ Each module shall have a python script in the modules directory. Each of the mod
- activemod ('ActiveModifier') - 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 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
+23 -20
View File
@@ -208,41 +208,44 @@ class RadioPlayer:
"""Single functon for starting the core, returns but might exit raising an SystemExit""" """Single functon for starting the core, returns but might exit raising an SystemExit"""
self.logger.info("Core starting, loading modules") self.logger.info("Core starting, loading modules")
self.load_modules();self.start_modules() self.load_modules();self.start_modules()
if not self.playlist_advisor: 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)")
self.logger.critical_error("Playlist advisor was not found")
raise SystemExit(1)
def play_once(self): def play_once(self):
"""Plays a single playlist""" """Plays a single playlist"""
if not self.playlist_advisor or not (playlist_path := self.playlist_advisor.advise(self.arg)): return if self.playlist_advisor:
try: global_args, parsed = self.parser.parse(playlist_path) if not (playlist_path := self.playlist_advisor.advise(self.arg)): return
except Exception as e: try: global_args, parsed = self.parser.parse(playlist_path)
self.logger.info(f"Exception ({e}) while parsing playlist, retrying in 15 seconds...");traceback.print_exc(file=self.logger.output) except Exception as e:
time.sleep(15) self.logger.info(f"Exception ({e}) while parsing playlist, retrying in 15 seconds...");traceback.print_exc(file=self.logger.output)
return 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.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 [(playlist := module.modify(global_args, playlist) or playlist) for module in self.playlist_modifier_modules if module] # yep
assert len(playlist) assert len(playlist)
prefetch(playlist[0].path) prefetch(playlist[0].path)
[mod.on_new_playlist(playlist) for mod in self.simple_modules + [self.active_modifier] if mod] # one liner'd everything [mod.on_new_playlist(playlist) for mod in self.simple_modules + [self.active_modifier] if mod] # one liner'd everything
max_iterator = len(playlist)
else:
max_iterator = 1
playlist = None
global_args = {}
return_pending = track = False return_pending = track = False
cross_fade = int(global_args.get("crossfade", 5)) cross_fade = int(global_args.get("crossfade", 5))
max_iterator = len(playlist)
song_i = i = 0 song_i = i = 0
def get_track(): def get_track():
nonlocal song_i, playlist, max_iterator nonlocal song_i, playlist, max_iterator
track = None track = None
while track is None: while track is None:
playlist_track = playlist[song_i % len(playlist)] if playlist:
playlist_next_track = playlist[song_i + 1] if song_i + 1 < len(playlist) else None 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: if self.active_modifier:
(track, next_track), extend = self.active_modifier.play(song_i, playlist_track, playlist_next_track) (track, next_track), extend = self.active_modifier.play(song_i, playlist_track, playlist_next_track)
if track is None: song_i += 1 if track is None: song_i += 1