You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
reforms!
This commit is contained in:
29
modules/__init__.py
Normal file
29
modules/__init__.py
Normal file
@@ -0,0 +1,29 @@
|
||||
class PlayerModule:
|
||||
"""
|
||||
Simple passive observer, this allows you to send the current track the your RDS encoder, or to your website
|
||||
"""
|
||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict[str, str]]]):
|
||||
"""Tuple consists of the track path, to fade out, fade in, official, and args"""
|
||||
pass
|
||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool): pass
|
||||
class PlaylistModifierModule:
|
||||
"""
|
||||
Playlist modifier, this type of module allows you to shuffle, or put jingles into your playlist
|
||||
"""
|
||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict[str, str]]]): return playlist
|
||||
class PlaylistAdvisor:
|
||||
"""
|
||||
Only one of a playlist advisor can be loaded. This module picks the playlist file to play, this can be a scheduler or just a static file
|
||||
"""
|
||||
def advise(self, arguments: str | None) -> str: return "/path/to/playlist.txt"
|
||||
def new_playlist(self) -> int:
|
||||
"""
|
||||
Whether to play a new playlist, if this is 1, then the player will refresh, if this is two then the player will refresh quietly
|
||||
"""
|
||||
return 0
|
||||
class ActiveModifier:
|
||||
"""
|
||||
This changes the next song to be played live, which means that this picks the next song, not the playlist, but this is affected by the playlist
|
||||
"""
|
||||
def play(self, index:int, track: tuple[str, bool, bool, bool, dict[str, str]]) -> tuple[tuple[str, bool, bool, bool, dict[str, str]], bool] | tuple[None, None]: return track, False
|
||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict[str, str]]]): pass
|
||||
@@ -1,12 +1,14 @@
|
||||
class ActiveModifier:
|
||||
"""
|
||||
This changes the next song to be played live, which means that this picks the next song, not the playlist, but this is affected by the playlist
|
||||
"""
|
||||
"""Tuple consists of the track path, to fade out, fade in, official, and args"""
|
||||
def play(self, index: int, track: tuple[str, bool, bool, bool, dict[str, str]]): return track, False
|
||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict[str, str]]]): pass
|
||||
|
||||
from . import ActiveModifier
|
||||
import os, log95
|
||||
import subprocess
|
||||
import datetime
|
||||
|
||||
from .advisor import MORNING_START, DAY_END
|
||||
|
||||
def get_audio_duration(file_path):
|
||||
result = subprocess.run(['ffprobe', '-v', 'quiet', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', file_path], capture_output=True, text=True)
|
||||
if result.returncode == 0: return float(result.stdout.strip())
|
||||
return None
|
||||
|
||||
logger = log95.log95("AC-MOD")
|
||||
|
||||
@@ -50,6 +52,18 @@ class Module(ActiveModifier):
|
||||
return self.last_track, True
|
||||
elif len(self.originals): self.last_track = self.originals.pop(0)
|
||||
else: self.last_track = track
|
||||
|
||||
if last_track_duration := get_audio_duration(self.last_track[0]):
|
||||
now = datetime.datetime.now()
|
||||
timestamp = now.timestamp() + last_track_duration
|
||||
future = datetime.datetime.fromtimestamp(timestamp)
|
||||
if now.hour < MORNING_START and future.hour > MORNING_START:
|
||||
return None, None
|
||||
elif now.hour < DAY_END and future.hour > DAY_END:
|
||||
return None, None
|
||||
elif future.day > now.day: # late night goes mid day, as it starts at midnight
|
||||
return None, None
|
||||
|
||||
return self.last_track, False
|
||||
|
||||
activemod = Module()
|
||||
@@ -1,14 +1,4 @@
|
||||
class PlaylistAdvisor:
|
||||
"""
|
||||
Only one of a playlist advisor can be loaded. This module picks the playlist file to play, this can be a scheduler or just a static file
|
||||
"""
|
||||
def advise(self, arguments: str | None) -> str: return "/path/to/playlist.txt"
|
||||
def new_playlist(self) -> int:
|
||||
"""
|
||||
Whether to play a new playlist, if this is 1, then the player will refresh, if this is two then the player will refresh quietly
|
||||
"""
|
||||
return 0
|
||||
|
||||
from . import PlaylistAdvisor
|
||||
import os, datetime, log95
|
||||
|
||||
logger = log95.log95("ADVISOR")
|
||||
|
||||
@@ -8,9 +8,7 @@ Reacts to the 'no_jingle' argument, for global usage it does not add jingles to
|
||||
|
||||
import random
|
||||
|
||||
class PlaylistModifierModule:
|
||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||
return playlist
|
||||
from . import PlaylistModifierModule
|
||||
|
||||
class Module(PlaylistModifierModule):
|
||||
def __init__(self, file: str) -> None:
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
class PlayerModule:
|
||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||
pass
|
||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
||||
pass
|
||||
|
||||
from . import PlayerModule
|
||||
import socket, re, log95, os
|
||||
|
||||
name_table_path = "/home/user/mixes/name_table.txt"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import random
|
||||
|
||||
class PlaylistModifierModule:
|
||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||
return playlist
|
||||
from . import PlaylistModifierModule
|
||||
|
||||
class Module(PlaylistModifierModule):
|
||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
class PlayerModule:
|
||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||
pass
|
||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
||||
pass
|
||||
from . import PlayerModule
|
||||
|
||||
class Module(PlayerModule):
|
||||
def __init__(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user