0) exec(SUDO."kill -15 $pid"); @unlink(PIDFILE); } exec(SUDO.'pkill -15 -f "/usr/bin/mpv"'); usleep(300000); exec(SUDO.'pkill -9 -f "/usr/bin/mpv"'); @unlink(MPV_SOCKET); } /* ---- Read title via mpv IPC ---- */ function getCurrentTitle(): string { if (!file_exists(MPV_SOCKET)) { return ''; } // Helfunktion: skicka IPC‑kommando till mpv och returnera svar som array $send = function (string $prop) { $fp = @fsockopen('unix://' . MPV_SOCKET, $errno, $errstr, 0.2); if (!$fp) { return null; } fwrite($fp, json_encode(['command' => ['get_property', $prop]]) . " "); $raw = fgets($fp, 2048); fclose($fp); return json_decode($raw, true); }; // 1) icy‑title från metadata om det finns $meta = $send('metadata'); if (isset($meta['data']['icy-title']) && $meta['data']['icy-title'] !== '') { return $meta['data']['icy-title']; } // 2) fallback: media-title $media = $send('media-title'); return $media['data'] ?? ''; } /* ---- AJAX endpoints ---- */ if(isset($_GET['ajax'])){ header('Content-Type:text/plain'); $a=$_GET['action'] ?? ''; if($a==='play' && isset($_GET['station'])){ $i=(int)$_GET['station']; if(isset($stations[$i])){ stopMpv(); @unlink(MPV_SOCKET); $url=escapeshellarg($stations[$i]['url']); $pid=(int)shell_exec(SUDO.MPV_BIN." --no-video --quiet --input-ipc-server=".MPV_SOCKET." $url > /dev/null 2>&1 & echo $!"); if($pid>0) file_put_contents(PIDFILE,$pid); echo 'OK';exit; } } if($a==='stop'){stopMpv();echo 'OK';exit;} if($a==='title'){echo getCurrentTitle();exit;} http_response_code(400);echo 'ERR';exit; } ?> Klocka & Radio
--:--:--