mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-31 00:09:16 +02:00
some changes
This commit is contained in:
+16
-5
@@ -1,24 +1,35 @@
|
|||||||
import random
|
"""
|
||||||
|
Jingle genarator module
|
||||||
|
|
||||||
JINGIEL_FILE = "/home/user/Jingiel.mp3"
|
Takes an file argument to initialize, which is the absolute path to the jingle file
|
||||||
|
|
||||||
|
Reacts to the 'no_jingle' argument, for global usage it does not add jingles to the playlist, and for file usage it does not add the jingle after the file
|
||||||
|
"""
|
||||||
|
|
||||||
|
import random, log95
|
||||||
|
|
||||||
|
logger = log95.log95("JINGLE-GEN")
|
||||||
|
|
||||||
class PlaylistModifierModule:
|
class PlaylistModifierModule:
|
||||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
class Module(PlaylistModifierModule):
|
class Module(PlaylistModifierModule):
|
||||||
|
def __init__(self, file: str) -> None:
|
||||||
|
logger.info("Generating jingles with the following random state:", repr(random.getstate()))
|
||||||
|
self.file = file
|
||||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
if int(global_args.get("no_jingle", 0)): return playlist
|
if int(global_args.get("no_jingle", 0)): return playlist
|
||||||
out: list[tuple[str, bool, bool, bool, dict]] = []
|
out: list[tuple[str, bool, bool, bool, dict]] = []
|
||||||
last_jingiel = True
|
last_jingiel = True
|
||||||
for (track, _, _, _, args) in playlist:
|
for (track, _, _, _, args) in playlist:
|
||||||
if not last_jingiel and random.choice([False, True, False, False]) and JINGIEL_FILE and int(args.get("no_jingle", 0)) == 0:
|
if not last_jingiel and random.choice([False, True, False, False]) and self.file and int(args.get("no_jingle", 0)) == 0:
|
||||||
out.append((track, True, False, True, args))
|
out.append((track, True, False, True, args))
|
||||||
out.append((JINGIEL_FILE, False, False, False, args))
|
out.append((self.file, False, False, False, args))
|
||||||
last_jingiel = True
|
last_jingiel = True
|
||||||
else:
|
else:
|
||||||
out.append((track, True, True, True, args))
|
out.append((track, True, True, True, args))
|
||||||
last_jingiel = False
|
last_jingiel = False
|
||||||
del last_jingiel
|
del last_jingiel
|
||||||
|
|
||||||
playlistmod = (Module(), 1)
|
playlistmod = (Module("/home/user/Jingiel.mp3"), 1)
|
||||||
+5
-1
@@ -1,10 +1,14 @@
|
|||||||
import random
|
import random, log95
|
||||||
|
|
||||||
|
logger = log95.log95("SHUFFLER")
|
||||||
|
|
||||||
class PlaylistModifierModule:
|
class PlaylistModifierModule:
|
||||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
class Module(PlaylistModifierModule):
|
class Module(PlaylistModifierModule):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
logger.info("Shuffling with the following random state:", repr(random.getstate()))
|
||||||
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
if int(global_args.get("no_shuffle", 0)) == 0:
|
if int(global_args.get("no_shuffle", 0)) == 0:
|
||||||
random.shuffle(playlist)
|
random.shuffle(playlist)
|
||||||
|
|||||||
+2
-3
@@ -103,8 +103,7 @@ class ProcessManager:
|
|||||||
return pr
|
return pr
|
||||||
def anything_playing(self) -> bool:
|
def anything_playing(self) -> bool:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
for process in self.processes:
|
self.processes = [p for p in self.processes if p.process.poll() is None]
|
||||||
if process.process.poll() is not None: self.processes.remove(process)
|
|
||||||
return bool(self.processes)
|
return bool(self.processes)
|
||||||
def stop_all(self, timeout: float | None = None) -> None:
|
def stop_all(self, timeout: float | None = None) -> None:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
@@ -228,7 +227,7 @@ def play_playlist(playlist_path, custom_playlist: bool=False):
|
|||||||
for (lns, args) in parsed:
|
for (lns, args) in parsed:
|
||||||
lns: list[str]
|
lns: list[str]
|
||||||
args: dict[str, str]
|
args: dict[str, str]
|
||||||
for line in lns: playlist.append((line, True, True, True, args))
|
for line in lns: playlist.append((line, True, True, True, args)) # simple entry, just to convert to a format taken by the modules
|
||||||
|
|
||||||
for module in playlist_modifier_modules: playlist = module.modify(global_args, playlist)
|
for module in playlist_modifier_modules: playlist = module.modify(global_args, playlist)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user