You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
update modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from . import ActiveModifier, log95, Track, InterModuleCommunication
|
from . import ActiveModifier, log95, Track, Path
|
||||||
import os, glob, datetime
|
import os, glob, datetime
|
||||||
|
|
||||||
from .advisor import MORNING_START, DAY_END
|
from .advisor import MORNING_START, DAY_END
|
||||||
@@ -29,6 +29,8 @@ class Module(ActiveModifier):
|
|||||||
if song.startswith("!"):
|
if song.startswith("!"):
|
||||||
song = song[1:]
|
song = song[1:]
|
||||||
official = False # NOT FLOATINGPOINTERROR
|
official = False # NOT FLOATINGPOINTERROR
|
||||||
|
|
||||||
|
song = Path(song).absolute()
|
||||||
|
|
||||||
if self.last_track: last_track_to_fade_out = self.last_track.fade_out
|
if self.last_track: last_track_to_fade_out = self.last_track.fade_out
|
||||||
else:
|
else:
|
||||||
@@ -46,7 +48,7 @@ class Module(ActiveModifier):
|
|||||||
f.write('\n'.join(songs))
|
f.write('\n'.join(songs))
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
|
||||||
logger.info(f"Playing {song} instead, as instructed by toplay")
|
logger.info(f"Playing {song.name} instead, as instructed by toplay")
|
||||||
|
|
||||||
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, {})
|
||||||
return self.last_track, True
|
return self.last_track, True
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from modules import ActiveModifier, InterModuleCommunication, PlayerModule
|
from modules import ActiveModifier, InterModuleCommunication, PlayerModule
|
||||||
from . import PlaylistAdvisor, log95
|
from . import PlaylistAdvisor, log95, Path
|
||||||
import os, datetime
|
import os, datetime
|
||||||
|
|
||||||
logger = log95.log95("ADVISOR")
|
logger = log95.log95("ADVISOR")
|
||||||
@@ -50,10 +50,11 @@ class Module(PlaylistAdvisor):
|
|||||||
self.last_playlist = None
|
self.last_playlist = None
|
||||||
self.custom_playlist = None
|
self.custom_playlist = None
|
||||||
self.class_imc = None
|
self.class_imc = None
|
||||||
def advise(self, arguments: str | None) -> str:
|
def advise(self, arguments: str | None) -> Path:
|
||||||
if self.custom_playlist: return self.custom_playlist
|
if self.custom_playlist: return self.custom_playlist
|
||||||
if arguments and arguments.startswith("list:"):
|
if arguments and arguments.startswith("list:"):
|
||||||
self.custom_playlist = arguments.removeprefix("list:")
|
self.custom_playlist = Path(arguments.removeprefix("list:"))
|
||||||
|
assert self.custom_playlist.exists()
|
||||||
logger.info(f"The list {arguments.split(';')[0]} will be played instead of the daily section lists.")
|
logger.info(f"The list {arguments.split(';')[0]} will be played instead of the daily section lists.")
|
||||||
return self.custom_playlist
|
return self.custom_playlist
|
||||||
current_day, current_hour = datetime.datetime.now().strftime('%A').lower(), datetime.datetime.now().hour
|
current_day, current_hour = datetime.datetime.now().strftime('%A').lower(), datetime.datetime.now().hour
|
||||||
@@ -82,22 +83,22 @@ class Module(PlaylistAdvisor):
|
|||||||
logger.info(f"Playing {current_day} day playlist...")
|
logger.info(f"Playing {current_day} day playlist...")
|
||||||
self.last_mod_time = Time.get_playlist_modification_time(day_playlist)
|
self.last_mod_time = Time.get_playlist_modification_time(day_playlist)
|
||||||
self.last_playlist = day_playlist
|
self.last_playlist = day_playlist
|
||||||
return day_playlist
|
return Path(day_playlist)
|
||||||
elif MORNING_START <= current_hour < MORNING_END:
|
elif MORNING_START <= current_hour < MORNING_END:
|
||||||
logger.info(f"Playing {current_day} morning playlist...")
|
logger.info(f"Playing {current_day} morning playlist...")
|
||||||
self.last_mod_time = Time.get_playlist_modification_time(morning_playlist)
|
self.last_mod_time = Time.get_playlist_modification_time(morning_playlist)
|
||||||
self.last_playlist = morning_playlist
|
self.last_playlist = morning_playlist
|
||||||
return morning_playlist
|
return Path(morning_playlist)
|
||||||
elif LATE_NIGHT_START <= current_hour < LATE_NIGHT_END:
|
elif LATE_NIGHT_START <= current_hour < LATE_NIGHT_END:
|
||||||
logger.info(f"Playing {current_day} late_night playlist...")
|
logger.info(f"Playing {current_day} late_night playlist...")
|
||||||
self.last_mod_time = Time.get_playlist_modification_time(late_night_playlist)
|
self.last_mod_time = Time.get_playlist_modification_time(late_night_playlist)
|
||||||
self.last_playlist = late_night_playlist
|
self.last_playlist = late_night_playlist
|
||||||
return late_night_playlist
|
return Path(late_night_playlist)
|
||||||
else:
|
else:
|
||||||
logger.info(f"Playing {current_day} night playlist...")
|
logger.info(f"Playing {current_day} night playlist...")
|
||||||
self.last_mod_time = Time.get_playlist_modification_time(night_playlist)
|
self.last_mod_time = Time.get_playlist_modification_time(night_playlist)
|
||||||
self.last_playlist = night_playlist
|
self.last_playlist = night_playlist
|
||||||
return night_playlist
|
return Path(night_playlist)
|
||||||
def new_playlist(self) -> bool:
|
def new_playlist(self) -> bool:
|
||||||
if self.custom_playlist: return False
|
if self.custom_playlist: return False
|
||||||
if not self.last_playlist: return True
|
if not self.last_playlist: return True
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ def format_time(seconds) -> str:
|
|||||||
class Module(PlayerModule):
|
class Module(PlayerModule):
|
||||||
def progress(self, index: int, track: Track, elapsed: float, total: float, real_total: float) -> None:
|
def progress(self, index: int, track: Track, elapsed: float, total: float, real_total: float) -> None:
|
||||||
if track.official:
|
if track.official:
|
||||||
print(f"{os.path.basename(track.path)}: {format_time(elapsed)} / {format_time(total)}", end="\r", flush=True)
|
print(f"{track.path.name}: {format_time(elapsed)} / {format_time(total)}", end="\r", flush=True)
|
||||||
if os.path.exists("/tmp/radioPlayer_skip"):
|
if os.path.exists("/tmp/radioPlayer_skip"):
|
||||||
self._imc.send(self, "procman", {"op": 2})
|
self._imc.send(self, "procman", {"op": 2})
|
||||||
os.remove("/tmp/radioPlayer_skip")
|
os.remove("/tmp/radioPlayer_skip")
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ Reacts to the 'no_jingle' argument, for global usage it does not add jingles to
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from . import PlaylistModifierModule, Track
|
from . import PlaylistModifierModule, Track, Path
|
||||||
|
|
||||||
class Module(PlaylistModifierModule):
|
class Module(PlaylistModifierModule):
|
||||||
def __init__(self, file: str) -> None:
|
def __init__(self, file: Path) -> None:
|
||||||
self.file = file
|
self.file = file
|
||||||
|
assert file.exists()
|
||||||
def modify(self, global_args: dict, playlist: list[Track]) -> list[Track] | None:
|
def modify(self, global_args: dict, playlist: list[Track]) -> list[Track] | None:
|
||||||
if int(global_args.get("no_jingle", 0)): return None
|
if int(global_args.get("no_jingle", 0)): return None
|
||||||
out: list[Track] = []
|
out: list[Track] = []
|
||||||
@@ -28,4 +29,4 @@ class Module(PlaylistModifierModule):
|
|||||||
del last_jingiel
|
del last_jingiel
|
||||||
return out
|
return out
|
||||||
|
|
||||||
playlistmod = (Module("/home/user/Jingiel.mp3"), 1)
|
playlistmod = (Module(Path("/home/user/Jingiel.mp3")), 1)
|
||||||
@@ -73,7 +73,7 @@ def update_rds(track_name: str):
|
|||||||
class Module(PlayerModule):
|
class Module(PlayerModule):
|
||||||
def on_new_track(self, index: int, track: Track):
|
def on_new_track(self, index: int, track: Track):
|
||||||
if track.official:
|
if track.official:
|
||||||
rds_rt, rds_rtp = update_rds(os.path.basename(track.path))
|
rds_rt, rds_rtp = update_rds(track.path.name)
|
||||||
logger.info(f"RT set to '{rds_rt}'")
|
logger.info(f"RT set to '{rds_rt}'")
|
||||||
logger.debug(f"{rds_rtp=}")
|
logger.debug(f"{rds_rtp=}")
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Module(PlayerModule):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.playlist = []
|
self.playlist = []
|
||||||
def on_new_playlist(self, playlist: list[Track]):
|
def on_new_playlist(self, playlist: list[Track]):
|
||||||
self.playlist = [t.path for t in playlist]
|
self.playlist = [str(t.path) for t in playlist]
|
||||||
def on_new_track(self, index: int, track: Track):
|
def on_new_track(self, index: int, track: Track):
|
||||||
if track.path != self.playlist[index]:
|
if track.path != self.playlist[index]:
|
||||||
# discrepancy, which means that the playing file was modified by the active modifier
|
# discrepancy, which means that the playing file was modified by the active modifier
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ def parse_playlistfile(playlist_path: Path) -> tuple[dict[str, str], list[tuple[
|
|||||||
out.append(([f for f in glob.glob(line) if os.path.isfile(f)], arguments))
|
out.append(([f for f in glob.glob(line) if os.path.isfile(f)], arguments))
|
||||||
return global_arguments, out
|
return global_arguments, out
|
||||||
|
|
||||||
def play_playlist(playlist_path, starting_index: int = 0):
|
def play_playlist(playlist_path: Path, starting_index: int = 0):
|
||||||
assert playlist_advisor
|
assert playlist_advisor
|
||||||
|
|
||||||
try: global_args, parsed = parse_playlistfile(playlist_path)
|
try: global_args, parsed = parse_playlistfile(playlist_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user