0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-27 06:03:52 +01:00

cache durations

This commit is contained in:
Kuba
2025-10-31 18:11:32 +01:00
parent e91a437093
commit 68a843d5a2

View File

@@ -5,7 +5,7 @@ import os, subprocess, importlib.util, types
import sys, signal, threading, glob import sys, signal, threading, glob
import unidecode import unidecode
from dataclasses import dataclass from dataclasses import dataclass
import log95 import log95, libcache
from pathlib import Path from pathlib import Path
from modules import * from modules import *
@@ -56,9 +56,16 @@ class ProcessManager:
def __init__(self) -> None: def __init__(self) -> None:
self.lock = threading.Lock() self.lock = threading.Lock()
self.processes: list[Process] = [] self.processes: list[Process] = []
self.duration_cache = libcache.Cache()
def _get_audio_duration(self, file_path): def _get_audio_duration(self, file_path):
if result := self.duration_cache.getElement(file_path, False):
return result
result = subprocess.run(['ffprobe', '-v', 'quiet', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', file_path], capture_output=True, text=True) 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()) if result.returncode == 0:
result = float(result.stdout.strip())
self.duration_cache.saveElement(file_path, result, (60*60))
return result
return None return None
def play(self, track_path: str, fade_in: bool=False, fade_out: bool=False, fade_time: int = 5) -> Process: def play(self, track_path: str, fade_in: bool=False, fade_out: bool=False, fade_time: int = 5) -> Process:
cmd = ['ffplay', '-nodisp', '-hide_banner', '-autoexit', '-loglevel', 'quiet'] cmd = ['ffplay', '-nodisp', '-hide_banner', '-autoexit', '-loglevel', 'quiet']