You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
modularize playlist change
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class PlayerModule:
|
class PlayerModule:
|
||||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool]]):
|
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
pass
|
pass
|
||||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
||||||
pass
|
pass
|
||||||
|
|||||||
13
modules/shuffler.py
Normal file
13
modules/shuffler.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
class PlaylistModifierModule:
|
||||||
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
|
return playlist
|
||||||
|
|
||||||
|
class Module(PlaylistModifierModule):
|
||||||
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
|
if int(global_args.get("no_shuffle", 0)) == 0:
|
||||||
|
random.shuffle(playlist)
|
||||||
|
return playlist
|
||||||
|
|
||||||
|
playlistmod = (Module(), 0)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
class PlayerModule:
|
class PlayerModule:
|
||||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool]]):
|
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
pass
|
pass
|
||||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
||||||
pass
|
pass
|
||||||
@@ -7,7 +7,7 @@ class PlayerModule:
|
|||||||
class Module(PlayerModule):
|
class Module(PlayerModule):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.playlist = []
|
self.playlist = []
|
||||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool]]):
|
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
self.playlist = [t[0] for t in playlist]
|
self.playlist = [t[0] for t in playlist]
|
||||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
||||||
lines = self.playlist[:index] + [f"> {self.playlist[index]}"] + self.playlist[index+1:]
|
lines = self.playlist[:index] + [f"> {self.playlist[index]}"] + self.playlist[index+1:]
|
||||||
|
|||||||
@@ -10,12 +10,16 @@ import log95, copy
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
class PlayerModule:
|
class PlayerModule:
|
||||||
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool]]):
|
def on_new_playlist(self, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
pass
|
pass
|
||||||
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
def on_new_track(self, index: int, track: str, to_fade_in: bool, to_fade_out: bool, official: bool):
|
||||||
pass
|
pass
|
||||||
|
class PlaylistModifierModule:
|
||||||
|
def modify(self, global_args: dict, playlist: list[tuple[str, bool, bool, bool, dict]]):
|
||||||
|
return playlist
|
||||||
|
|
||||||
simple_modules: list[PlayerModule] = []
|
simple_modules: list[PlayerModule] = []
|
||||||
|
playlist_modifier_modules: list[PlaylistModifierModule] = []
|
||||||
|
|
||||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||||
MODULES_DIR = SCRIPT_DIR / "modules"
|
MODULES_DIR = SCRIPT_DIR / "modules"
|
||||||
@@ -222,34 +226,33 @@ def play_playlist(playlist_path, custom_playlist: bool=False):
|
|||||||
logger.info(f"Exception while parsing playlist, retrying in 15 seconds...")
|
logger.info(f"Exception while parsing playlist, retrying in 15 seconds...")
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
return
|
return
|
||||||
lines_args = copy.deepcopy(parsed)
|
|
||||||
lines = []
|
playlist: list[tuple[str, bool, bool, bool, dict]] = [] # name, fade in, fade out, official, args
|
||||||
for (lns, args) in lines_args:
|
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 i in range(int(args.get("multiplier", 1))): lines.extend(lns)
|
for module in playlist_modifier_modules: playlist = module.modify(global_args, playlist)
|
||||||
|
|
||||||
cross_fade = int(global_args.get("crossfade", 5))
|
# last_jingiel = True
|
||||||
if int(global_args.get("no_shuffle", 0)) == 0: random.shuffle(lines)
|
# for line in lines:
|
||||||
|
# if not last_jingiel and random.choice([False, True, False, False]) and JINGIEL_FILE:
|
||||||
playlist: list[tuple[str, bool, bool, bool]] = [] # name, fade in, fade out, official
|
# playlist.append((line, True, False, True))
|
||||||
last_jingiel = True
|
# playlist.append((JINGIEL_FILE, False, False, False))
|
||||||
for line in lines:
|
# last_jingiel = True
|
||||||
if not last_jingiel and random.choice([False, True, False, False]) and JINGIEL_FILE:
|
# else:
|
||||||
playlist.append((line, True, False, True))
|
# playlist.append((line, True, True, True))
|
||||||
playlist.append((JINGIEL_FILE, False, False, False))
|
# last_jingiel = False
|
||||||
last_jingiel = True
|
# del last_jingiel
|
||||||
else:
|
|
||||||
playlist.append((line, True, True, True))
|
|
||||||
last_jingiel = False
|
|
||||||
del last_jingiel
|
|
||||||
|
|
||||||
for module in simple_modules: module.on_new_playlist(playlist)
|
for module in simple_modules: module.on_new_playlist(playlist)
|
||||||
|
|
||||||
return_pending = False
|
return_pending = False
|
||||||
|
|
||||||
for i, (track, to_fade_in, to_fade_out, official) in enumerate(playlist):
|
cross_fade = int(global_args.get("crossfade", 5))
|
||||||
|
|
||||||
|
for i, (track, to_fade_in, to_fade_out, official, args) in enumerate(playlist):
|
||||||
if return_pending:
|
if return_pending:
|
||||||
logger.info("Return reached, next song will reload the playlist.")
|
logger.info("Return reached, next song will reload the playlist.")
|
||||||
procman.wait_all()
|
procman.wait_all()
|
||||||
@@ -332,6 +335,11 @@ def main():
|
|||||||
|
|
||||||
if md := getattr(module, "module", None):
|
if md := getattr(module, "module", None):
|
||||||
simple_modules.append(md)
|
simple_modules.append(md)
|
||||||
|
elif md := getattr(module, "playlistmod", None):
|
||||||
|
if isinstance(md, tuple):
|
||||||
|
md, index = md
|
||||||
|
playlist_modifier_modules.insert(index, md)
|
||||||
|
else: playlist_modifier_modules.append(md)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -14,7 +14,3 @@ Each lines starting with `@` is taken as a import, meaning after the `@` a file
|
|||||||
Lines which start with `;` are considered comments and will not be processed
|
Lines which start with `;` are considered comments and will not be processed
|
||||||
Lines containing `|` will be split into two parts, the first part will be treated as the file itself, and the argument part will be treated as arguments for that file, if the file name is empty then those arguments will be treated as global
|
Lines containing `|` will be split into two parts, the first part will be treated as the file itself, and the argument part will be treated as arguments for that file, if the file name is empty then those arguments will be treated as global
|
||||||
The arguments shall have a `a=b` format, multiple arguments are seperated with a `;`, example: `a=b;c=d`
|
The arguments shall have a `a=b` format, multiple arguments are seperated with a `;`, example: `a=b;c=d`
|
||||||
|
|
||||||
As of now these arguments are defined:
|
|
||||||
`no_shuffle` - Global argument, does not shuffle the playlist if it is 0
|
|
||||||
`multiplier` - File argument, integer which duplicates the file(s)
|
|
||||||
Reference in New Issue
Block a user