diff --git a/modules/__init__.py b/modules/__init__.py index 7387046..1e05f7b 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -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 diff --git a/modules/active_modifier.py b/modules/active_modifier.py index b0b938b..5453400 100644 --- a/modules/active_modifier.py +++ b/modules/active_modifier.py @@ -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: diff --git a/modules/modules.txt b/modules/modules.txt index 1d7c732..fd7e894 100644 --- a/modules/modules.txt +++ b/modules/modules.txt @@ -12,4 +12,5 @@ Each module shall have a python script in the modules directory. Each of the mod - advisor ('PlaylistAdvisor') - 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 \ No newline at end of file +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 \ No newline at end of file diff --git a/radioPlayer.py b/radioPlayer.py index 8c817f2..060b87a 100644 --- a/radioPlayer.py +++ b/radioPlayer.py @@ -127,7 +127,7 @@ class RadioPlayer: self.arg = arg self.logger = log95.log95("CORE", output=output) - def shutdown(self): + def shutdown(self): self.procman.stop_all() for module in self.simple_modules: if module: @@ -208,46 +208,49 @@ 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 - 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 + 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.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: 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 - assert len(playlist) - - prefetch(playlist[0].path) - [mod.on_new_playlist(playlist) for mod in self.simple_modules + [self.active_modifier] if mod] # one liner'd everything + [(playlist := module.modify(global_args, playlist) or playlist) for module in self.playlist_modifier_modules if module] # yep + assert len(playlist) + prefetch(playlist[0].path) + [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 - cross_fade = int(global_args.get("crossfade", 5)) - - max_iterator = len(playlist) song_i = i = 0 def get_track(): nonlocal song_i, playlist, max_iterator track = None while track is None: - playlist_track = playlist[song_i % len(playlist)] - playlist_next_track = playlist[song_i + 1] if song_i + 1 < len(playlist) else 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 if extend and track: max_iterator += 1 - else: + else: track = playlist_track next_track = playlist_next_track extend = False