You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
new custom playlist processing
This commit is contained in:
@@ -11,7 +11,7 @@ DAY_END = 18
|
|||||||
LATE_NIGHT_START = 0
|
LATE_NIGHT_START = 0
|
||||||
LATE_NIGHT_END = 5
|
LATE_NIGHT_END = 5
|
||||||
|
|
||||||
playlist_dir = "/home/user/playlists"
|
playlist_dir = Path("/home/user/playlists")
|
||||||
|
|
||||||
class Time:
|
class Time:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -19,12 +19,12 @@ class Time:
|
|||||||
try: return os.path.getmtime(playlist_path)
|
try: return os.path.getmtime(playlist_path)
|
||||||
except OSError: return 0
|
except OSError: return 0
|
||||||
|
|
||||||
def check_if_playlist_modifed(playlist_path: str) -> bool:
|
def check_if_playlist_modifed(playlist_path: Path) -> bool:
|
||||||
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
|
||||||
morning_playlist_path = os.path.join(playlist_dir, current_day, 'morning')
|
morning_playlist_path = Path(playlist_dir, current_day, "morning").absolute()
|
||||||
day_playlist_path = os.path.join(playlist_dir, current_day, 'day')
|
day_playlist_path = Path(playlist_dir, current_day, "day").absolute()
|
||||||
night_playlist_path = os.path.join(playlist_dir, current_day, 'night')
|
night_playlist_path = Path(playlist_dir, current_day, "night").absolute()
|
||||||
late_night_playlist_path = os.path.join(playlist_dir, current_day, 'late_night')
|
late_night_playlist_path = Path(playlist_dir, current_day, "late_night").absolute()
|
||||||
|
|
||||||
if DAY_START <= current_hour < DAY_END:
|
if DAY_START <= current_hour < DAY_END:
|
||||||
if playlist_path != day_playlist_path:
|
if playlist_path != day_playlist_path:
|
||||||
@@ -48,57 +48,60 @@ class Module(PlaylistAdvisor):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.last_mod_time = 0
|
self.last_mod_time = 0
|
||||||
self.last_playlist = None
|
self.last_playlist = None
|
||||||
self.custom_playlist = None
|
|
||||||
self.class_imc = None
|
self.class_imc = None
|
||||||
|
self.custom_playlist = None
|
||||||
def advise(self, arguments: str | None) -> Path:
|
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:"):
|
|
||||||
self.custom_playlist = Path(arguments.removeprefix("list:"))
|
custom_playlist = Path("/tmp/radioPlayer_list")
|
||||||
assert self.custom_playlist.exists()
|
if custom_playlist.exists():
|
||||||
logger.info(f"The list {arguments.split(';')[0]} will be played instead of the daily section lists.")
|
self.last_playlist = custom_playlist
|
||||||
|
self.custom_playlist = self.last_playlist
|
||||||
return self.custom_playlist
|
return self.custom_playlist
|
||||||
|
elif self.custom_playlist: self.custom_playlist = None
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
morning_playlist = os.path.join(playlist_dir, current_day, 'morning')
|
morning_playlist = Path(playlist_dir, current_day, "morning").absolute()
|
||||||
day_playlist = os.path.join(playlist_dir, current_day, 'day')
|
day_playlist = Path(playlist_dir, current_day, "day").absolute()
|
||||||
night_playlist = os.path.join(playlist_dir, current_day, 'night')
|
night_playlist = Path(playlist_dir, current_day, "night").absolute()
|
||||||
late_night_playlist = os.path.join(playlist_dir, current_day, 'late_night')
|
late_night_playlist = Path(playlist_dir, current_day, "late_night").absolute()
|
||||||
|
|
||||||
morning_dir = os.path.dirname(morning_playlist)
|
morning_dir = morning_playlist.parent
|
||||||
day_dir = os.path.dirname(day_playlist)
|
day_dir = day_playlist.parent
|
||||||
night_dir = os.path.dirname(night_playlist)
|
night_dir = night_playlist.parent
|
||||||
late_night_dir = os.path.dirname(late_night_playlist)
|
late_night_dir = late_night_playlist.parent
|
||||||
|
|
||||||
for dir_path in [morning_dir, day_dir, night_dir, late_night_dir]:
|
for dir_path in [morning_dir, day_dir, night_dir, late_night_dir]:
|
||||||
if not os.path.exists(dir_path):
|
if not dir_path.exists():
|
||||||
logger.info(f"Creating directory: {dir_path}")
|
logger.info(f"Creating directory: {dir_path}")
|
||||||
os.makedirs(dir_path, exist_ok=True)
|
dir_path.mkdir(exist_ok=True)
|
||||||
|
|
||||||
for playlist_path in [morning_playlist, day_playlist, night_playlist, late_night_playlist]:
|
for playlist_path in [morning_playlist, day_playlist, night_playlist, late_night_playlist]:
|
||||||
if not os.path.exists(playlist_path):
|
if not playlist_path.exists():
|
||||||
logger.info(f"Creating empty playlist: {playlist_path}")
|
logger.info(f"Creating empty playlist: {playlist_path}")
|
||||||
with open(playlist_path, 'w'): pass
|
playlist_path.touch()
|
||||||
|
|
||||||
if DAY_START <= current_hour < DAY_END:
|
if DAY_START <= current_hour < DAY_END:
|
||||||
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 Path(day_playlist)
|
return 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 Path(morning_playlist)
|
return 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 Path(late_night_playlist)
|
return 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 Path(night_playlist)
|
return 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
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import libcache
|
|||||||
from modules import *
|
from modules import *
|
||||||
|
|
||||||
def prefetch(path):
|
def prefetch(path):
|
||||||
if os.name == "nt": return
|
if os.name != "posix": return
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
fd = f.fileno()
|
fd = f.fileno()
|
||||||
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL)
|
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL)
|
||||||
|
|||||||
Reference in New Issue
Block a user