You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
caching
This commit is contained in:
26
modules/cache.py
Normal file
26
modules/cache.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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]
|
||||
|
||||
with open(track.path.absolute(), "rb") as f:
|
||||
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_SEQUENTIAL)
|
||||
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_NOREUSE)
|
||||
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_WILLNEED)
|
||||
with open(next, "rb") as f:
|
||||
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_SEQUENTIAL)
|
||||
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_NOREUSE)
|
||||
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_WILLNEED)
|
||||
|
||||
module = Module()
|
||||
@@ -1,4 +1,4 @@
|
||||
from . import PlayerModule, log95, Track
|
||||
from . import PlayerModule, log95, Track, Popen
|
||||
|
||||
logger = log95.log95("PlayView")
|
||||
|
||||
@@ -6,7 +6,7 @@ class Module(PlayerModule):
|
||||
def __init__(self) -> None:
|
||||
self.playlist = []
|
||||
def on_new_playlist(self, playlist: list[Track]):
|
||||
self.playlist = [str(t.path) for t in playlist]
|
||||
self.playlist = [str(t.path.absolute()) for t in playlist]
|
||||
def on_new_track(self, index: int, track: Track):
|
||||
if str(track.path) != self.playlist[index]:
|
||||
# discrepancy, which means that the playing file was modified by the active modifier
|
||||
|
||||
Reference in New Issue
Block a user