webapp: drop rig:playlist pipeline, source track count from mpc stats
The four overlays that read /data/playlist.js (loading, goodbye,
music-box, music/nc) only ever consumed `tracks.length` for cosmetic
"LIBRARY :: N TRACKS" / "indexed N tracks" flavor text — all live
playback signal flows through bridges/mpd-state.py over OBS WS. The
142 KB JSON, ffprobe walk, and ETag-cached route were all producing
one integer that MPD itself already knows.
RigData::playlistCount() now shells `mpc stats` and parses "Songs: N",
returning 0 on any failure (treated by callers as empty library).
Removes RigPlaylistCommand, DataController::playlist(), the
/data/playlist.js route, the per-overlay <script src> + window.__PLAYLIST
shims, and the stale storage/data/playlist.json artifact.
AudioController still consumes config('rig.music_dirs') for the HTTP
audio stream — that's orthogonal and stays.
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Throwable;
|
||||
|
||||
class RigData
|
||||
{
|
||||
private array $cache = [];
|
||||
private ?int $mpdSongCount = null;
|
||||
|
||||
public function loading(): array
|
||||
{
|
||||
@@ -23,17 +27,26 @@ class RigData
|
||||
]);
|
||||
}
|
||||
|
||||
public function playlist(): array
|
||||
{
|
||||
return $this->read('playlist.json', [
|
||||
'syncedAt' => null, 'sourceDirs' => [], 'trackCount' => 0, 'tracks' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Track count from MPD (the live library, queried via `mpc stats`).
|
||||
* Returns 0 if mpc is missing or MPD is unreachable — callers treat
|
||||
* that as "empty library" and degrade their flavor text accordingly.
|
||||
*/
|
||||
public function playlistCount(): int
|
||||
{
|
||||
$p = $this->playlist();
|
||||
return (int) ($p['trackCount'] ?? count($p['tracks'] ?? []));
|
||||
if ($this->mpdSongCount !== null) return $this->mpdSongCount;
|
||||
|
||||
try {
|
||||
$proc = new Process(['mpc', 'stats']);
|
||||
$proc->setTimeout(2);
|
||||
$proc->run();
|
||||
if ($proc->isSuccessful() && preg_match('/^Songs:\s*(\d+)/m', $proc->getOutput(), $m)) {
|
||||
return $this->mpdSongCount = (int) $m[1];
|
||||
}
|
||||
} catch (Throwable) {
|
||||
// fall through
|
||||
}
|
||||
return $this->mpdSongCount = 0;
|
||||
}
|
||||
|
||||
public function cmd(): array
|
||||
@@ -49,11 +62,6 @@ class RigData
|
||||
return $cmd;
|
||||
}
|
||||
|
||||
public function playlistPath(): string
|
||||
{
|
||||
return rtrim(config('rig.storage_data'), '/') . '/playlist.json';
|
||||
}
|
||||
|
||||
public function coverPath(): string
|
||||
{
|
||||
return (string) config('rig.cover_jpg');
|
||||
|
||||
Reference in New Issue
Block a user