You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-27 14:13:55 +01:00
better cache
This commit is contained in:
@@ -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()
|
|
||||||
@@ -5,6 +5,14 @@ import sys, signal, threading, glob
|
|||||||
import libcache
|
import libcache
|
||||||
from modules import *
|
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] = []
|
simple_modules: list[PlayerModule] = []
|
||||||
playlist_modifier_modules: list[PlaylistModifierModule] = []
|
playlist_modifier_modules: list[PlaylistModifierModule] = []
|
||||||
playlist_advisor: PlaylistAdvisor | None = None
|
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
|
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
|
[mod.on_new_playlist(playlist) for mod in simple_modules + [active_modifier] if mod] # one liner'd everything
|
||||||
|
|
||||||
return_pending = False
|
return_pending = False
|
||||||
@@ -203,6 +213,7 @@ def play_playlist(playlist_path: Path, starting_index: int = 0):
|
|||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
if not extend: song_i += 1
|
if not extend: song_i += 1
|
||||||
|
prefetch(playlist[song_i % len(playlist)])
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logger.info("Core is starting, loading modules")
|
logger.info("Core is starting, loading modules")
|
||||||
|
|||||||
Reference in New Issue
Block a user