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

something

This commit is contained in:
2025-11-22 19:24:43 +01:00
parent f33c7f050a
commit 4a359d932a
2 changed files with 14 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ class Module(ActiveModifier):
self.originals = [] self.originals = []
self.last_track = None self.last_track = None
self.limit_tracks = False self.limit_tracks = False
self.can_limit_tracks = False
self.morning_start = self.day_end = 0 self.morning_start = self.day_end = 0
def on_new_playlist(self, playlist: list[Track]): def on_new_playlist(self, playlist: list[Track]):
self.playlist = playlist self.playlist = playlist
@@ -21,6 +22,7 @@ class Module(ActiveModifier):
self.limit_tracks, self.morning_start, self.day_end = self._imc.send(self, "advisor", None) # pyright: ignore[reportGeneralTypeIssues] self.limit_tracks, self.morning_start, self.day_end = self._imc.send(self, "advisor", None) # pyright: ignore[reportGeneralTypeIssues]
self.limit_tracks = not bool(self.limit_tracks) self.limit_tracks = not bool(self.limit_tracks)
if self.limit_tracks: logger.info("Skipping tracks if they bleed into other times.") if self.limit_tracks: logger.info("Skipping tracks if they bleed into other times.")
self.can_limit_tracks = self.limit_tracks
def play(self, index: int, track: Track, next_track: Track | None): def play(self, index: int, track: Track, next_track: Track | None):
if not self.playlist: return (track, next_track), False if not self.playlist: return (track, next_track), False
if not os.path.exists("/tmp/radioPlayer_toplay"): open("/tmp/radioPlayer_toplay", "a").close() if not os.path.exists("/tmp/radioPlayer_toplay"): open("/tmp/radioPlayer_toplay", "a").close()
@@ -69,11 +71,13 @@ class Module(ActiveModifier):
else: else:
self.last_track = Track(song, next_track_to_fade_in, last_track_to_fade_out, official, {}) self.last_track = Track(song, next_track_to_fade_in, last_track_to_fade_out, official, {})
next_track = track next_track = track
self.limit_tracks = False
return (self.last_track, next_track), True return (self.last_track, next_track), True
elif len(self.originals): elif len(self.originals):
self.last_track = self.originals.pop(0) self.last_track = self.originals.pop(0)
if len(self.originals): next_track = self.originals[0] if len(self.originals): next_track = self.originals[0]
else: self.last_track = track else: self.last_track = track
self.limit_tracks = self.can_limit_tracks
if self.limit_tracks: if self.limit_tracks:
last_track_duration = self._imc.send(self, "procman", {"op": 1, "arg": self.last_track.path}) last_track_duration = self._imc.send(self, "procman", {"op": 1, "arg": self.last_track.path})
@@ -92,7 +96,7 @@ class Module(ActiveModifier):
elif future.day != now.day: # late night goes mid day, as it starts at midnight elif future.day != now.day: # late night goes mid day, as it starts at midnight
logger.warning("Skipping track as it the next day") logger.warning("Skipping track as it the next day")
return (None, None), None return (None, None), None
logger.info("Track ends at", repr(future)) if last_track_duration: logger.info("Track ends at", repr(future))
return (self.last_track, next_track), False return (self.last_track, next_track), False
activemod = Module() activemod = Module()

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import time, types import time, types
import os, subprocess, importlib.util import os, subprocess, importlib.util
import sys, signal, glob import sys, signal, glob
@@ -28,7 +27,7 @@ class ProcessManager(Skeleton_ProcessManager):
result = subprocess.run(['ffprobe', '-v', 'quiet', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', str(file_path)], capture_output=True, text=True) result = subprocess.run(['ffprobe', '-v', 'quiet', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', str(file_path)], capture_output=True, text=True)
if result.returncode == 0: if result.returncode == 0:
result = float(result.stdout.strip()) result = float(result.stdout.strip())
self.duration_cache.saveElement(file_path.as_posix(), result, (60*60), False, True) self.duration_cache.saveElement(file_path.as_posix(), result, (60*60*2), False, True)
return result return result
def play(self, track: Track, fade_time: int=5) -> Process: def play(self, track: Track, fade_time: int=5) -> Process:
cmd = ['ffplay', '-nodisp', '-hide_banner', '-autoexit', '-loglevel', 'quiet'] cmd = ['ffplay', '-nodisp', '-hide_banner', '-autoexit', '-loglevel', 'quiet']
@@ -40,10 +39,9 @@ class ProcessManager(Skeleton_ProcessManager):
if track.offset > 0: cmd.extend(['-ss', str(track.offset)]) if track.offset > 0: cmd.extend(['-ss', str(track.offset)])
filters = [] filters = []
if track.fade_in: filters.append(f"afade=t=in:st=0:d={fade_time}") if track.fade_in and fade_time != 0: filters.append(f"afade=t=in:st=0:d={fade_time}")
if track.fade_out: filters.append(f"afade=t=out:st={duration - fade_time - track.offset}:d={fade_time}") if track.fade_out and fade_time != 0: filters.append(f"afade=t=out:st={duration - fade_time - track.offset}:d={fade_time}")
if filters: cmd.extend(['-af', ",".join(filters)]) if filters: cmd.extend(['-af', ",".join(filters)])
cmd.append(str(track.path.absolute())) cmd.append(str(track.path.absolute()))
pr = Process(Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True), track.path.name, time.monotonic(), duration - track.offset) pr = Process(Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True), track.path.name, time.monotonic(), duration - track.offset)
@@ -93,7 +91,6 @@ class PlaylistParser:
def parse(self, playlist_path: Path) -> tuple[dict[str, str], list[tuple[list[str], dict[str, str]]]]: def parse(self, playlist_path: Path) -> tuple[dict[str, str], list[tuple[list[str], dict[str, str]]]]:
lines = self._check_for_imports(playlist_path) lines = self._check_for_imports(playlist_path)
out = [] out = []
global_arguments = {} global_arguments = {}
for line in lines: for line in lines:
@@ -121,7 +118,6 @@ class RadioPlayer:
self.playlist_modifier_modules: list[PlaylistModifierModule] = [] self.playlist_modifier_modules: list[PlaylistModifierModule] = []
self.playlist_advisor: PlaylistAdvisor | None = None self.playlist_advisor: PlaylistAdvisor | None = None
self.active_modifier: ActiveModifier | None = None self.active_modifier: ActiveModifier | None = None
self.logger = log95.log95("CORE", output=output)
self.exit_pending = False self.exit_pending = False
self.exit_status_code = 0 self.exit_status_code = 0
self.intr_time = 0 self.intr_time = 0
@@ -129,7 +125,9 @@ class RadioPlayer:
self.procman = ProcessManager() self.procman = ProcessManager()
self.modules: list[tuple] = [] self.modules: list[tuple] = []
self.parser = PlaylistParser(output) self.parser = PlaylistParser(output)
self.arg = arg self.arg = arg
self.logger = log95.log95("CORE", output=output)
def shutdown(self): def shutdown(self):
self.procman.stop_all() self.procman.stop_all()
@@ -223,13 +221,12 @@ class RadioPlayer:
prefetch(playlist[0].path) prefetch(playlist[0].path)
[mod.on_new_playlist(playlist) for mod in self.simple_modules + [self.active_modifier] if mod] # one liner'd everything [mod.on_new_playlist(playlist) for mod in self.simple_modules + [self.active_modifier] if mod] # one liner'd everything
return_pending = False return_pending = track = False
cross_fade = int(global_args.get("crossfade", 5)) cross_fade = int(global_args.get("crossfade", 5))
max_iterator = len(playlist) max_iterator = len(playlist)
song_i = i = 0 song_i = i = 0
track = None
def get_track(): def get_track():
nonlocal song_i, playlist, max_iterator nonlocal song_i, playlist, max_iterator
@@ -239,10 +236,8 @@ class RadioPlayer:
playlist_next_track = playlist[song_i + 1] if song_i + 1 < len(playlist) else None playlist_next_track = playlist[song_i + 1] if song_i + 1 < len(playlist) else None
if self.active_modifier: if self.active_modifier:
(track, next_track), extend = self.active_modifier.play(song_i, playlist_track, playlist_next_track) (track, next_track), extend = self.active_modifier.play(song_i, playlist_track, playlist_next_track)
if track is None: if track is None: song_i += 1
song_i += 1 if extend and track: max_iterator += 1
continue
if extend: max_iterator += 1
else: else:
track = playlist_track track = playlist_track
next_track = playlist_next_track next_track = playlist_next_track
@@ -266,7 +261,6 @@ class RadioPlayer:
while i < max_iterator: while i < max_iterator:
if check_conditions(): return if check_conditions(): return
if not track: track, next_track, extend = get_track() if not track: track, next_track, extend = get_track()
prefetch(track.path) prefetch(track.path)
@@ -299,7 +293,7 @@ class RadioPlayer:
self.play_once() self.play_once()
if self.exit_pending: raise SystemExit(self.exit_status_code) if self.exit_pending: raise SystemExit(self.exit_status_code)
except Exception as e: except Exception as e:
self.logger.critical_error(f"Unexpected error: {e}") traceback.print_exc(file=self.logger.output)
raise raise
def main(): def main():