diff --git a/modules/cache.py b/modules/cache.py deleted file mode 100644 index 5399797..0000000 --- a/modules/cache.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -from . import PlayerModule, Track - -class Module(PlayerModule): - def __init__(self) -> None: - self.playlist = [] - def on_new_playlist(self, playlist: list[Track]): - self.playlist = [t.path.absolute() for t in playlist] - def on_new_track(self, index: int, track: Track): - if track.path.absolute().as_posix() != self.playlist[index].as_posix(): - # discrepancy, which means that the playing file was modified by the active modifier - # we are playing a file that was not determined in the playlist, that means it was chosen by the active modifier and made up on the fly - next = self.playlist[index] - else: - next = self.playlist[index+1] - def prefetch(path): - with open(path, "rb") as f: - fd = f.fileno() - os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL) - os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_NOREUSE) - os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_WILLNEED) - - prefetch(track.path.absolute()) - prefetch(next) - -module = Module() \ No newline at end of file diff --git a/radioPlayer.py b/radioPlayer.py index 17a79f2..f8ee8a5 100644 --- a/radioPlayer.py +++ b/radioPlayer.py @@ -5,6 +5,14 @@ import sys, signal, threading, glob import libcache from modules import * +def prefetch(path): + if os.name == "nt": return + with open(path, "rb") as f: + fd = f.fileno() + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL) + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_NOREUSE) + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_WILLNEED) + simple_modules: list[PlayerModule] = [] playlist_modifier_modules: list[PlaylistModifierModule] = [] playlist_advisor: PlaylistAdvisor | None = None @@ -148,6 +156,8 @@ def play_playlist(playlist_path: Path, starting_index: int = 0): for module in playlist_modifier_modules: playlist = module.modify(global_args, playlist) or playlist + prefetch(playlist[0]) + [mod.on_new_playlist(playlist) for mod in simple_modules + [active_modifier] if mod] # one liner'd everything return_pending = False @@ -203,6 +213,7 @@ def play_playlist(playlist_path: Path, starting_index: int = 0): i += 1 if not extend: song_i += 1 + prefetch(playlist[song_i % len(playlist)]) def main(): logger.info("Core is starting, loading modules")