From 2cb78f61b98bca13bbaba05758fef1641d58b236 Mon Sep 17 00:00:00 2001 From: Kuba <132459354+KubaPro010@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:37:15 +0200 Subject: [PATCH] jingle --- modules/jingle.py | 24 ++++++++++++++++++++++++ radioPlayer.py | 16 +--------------- 2 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 modules/jingle.py diff --git a/modules/jingle.py b/modules/jingle.py new file mode 100644 index 0000000..c8ec914 --- /dev/null +++ b/modules/jingle.py @@ -0,0 +1,24 @@ +import random + +JINGIEL_FILE = "/home/user/Jingiel.mp3" + +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_jingle", 0)): return playlist + out: list[tuple[str, bool, bool, bool, dict]] = [] + last_jingiel = True + 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: + out.append((track, True, False, True, args)) + out.append((JINGIEL_FILE, False, False, False, args)) + last_jingiel = True + else: + out.append((track, True, True, True, args)) + last_jingiel = False + del last_jingiel + +playlistmod = (Module(), 1) \ No newline at end of file diff --git a/radioPlayer.py b/radioPlayer.py index e1ea5d1..84d6ec0 100644 --- a/radioPlayer.py +++ b/radioPlayer.py @@ -4,9 +4,8 @@ import time, datetime import os, subprocess, importlib.util import sys, signal, threading, glob import unidecode -import random from dataclasses import dataclass -import log95, copy +import log95 from pathlib import Path class PlayerModule: @@ -54,8 +53,6 @@ DAY_END = 19 LATE_NIGHT_START = 0 LATE_NIGHT_END = 5 -JINGIEL_FILE = "/home/user/Jingiel.mp3" - playlist_dir = "/home/user/playlists" logger_level = log95.log95Levels.DEBUG if DEBUG else log95.log95Levels.CRITICAL_ERROR @@ -235,17 +232,6 @@ def play_playlist(playlist_path, custom_playlist: bool=False): for module in playlist_modifier_modules: playlist = module.modify(global_args, playlist) - # last_jingiel = True - # for line in lines: - # if not last_jingiel and random.choice([False, True, False, False]) and JINGIEL_FILE: - # playlist.append((line, True, False, True)) - # playlist.append((JINGIEL_FILE, False, False, False)) - # last_jingiel = True - # else: - # playlist.append((line, True, True, True)) - # last_jingiel = False - # del last_jingiel - for module in simple_modules: module.on_new_playlist(playlist) return_pending = False