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

better cache

This commit is contained in:
KubaPro010
2025-11-06 19:16:01 +01:00
parent 2bc7c557db
commit 7a1fe3c73f
2 changed files with 11 additions and 26 deletions

View File

@@ -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()