diff --git a/modules/__init__.py b/modules/__init__.py index ef1c1d0..fef4dea 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -86,6 +86,11 @@ class PlayerModule(BaseIMCModule): Please don't put any blocking or code that takes time """ pass + def shutdown(self): + """ + Ran while shutting down + """ + pass class PlaylistModifierModule: """ Playlist modifier, this type of module allows you to shuffle, or put jingles into your playlist diff --git a/modules/play_counter.py b/modules/play_counter.py index c8016df..05cb3c0 100644 --- a/modules/play_counter.py +++ b/modules/play_counter.py @@ -34,5 +34,7 @@ class Module(PlayerModule): def on_new_track(self, index: int, track: Track, next_track: Track | None) -> None: self.counts[track.path.as_posix()] = self.counts.get(track.path.as_posix(), 0) + 1 if sum(self.counts.values()) % 3 == 0: self._save_counts() + def shutdown(self): + self._save_counts() module = Module() \ No newline at end of file diff --git a/radioPlayer.py b/radioPlayer.py index 84d5b8c..e528bef 100644 --- a/radioPlayer.py +++ b/radioPlayer.py @@ -131,6 +131,7 @@ class RadioPlayer: def shutdown(self): self.procman.stop_all() + [module.shutdown() for module in self.simple_modules if module] def handle_sigint(self, signum, frame): with self.exit_lock: