release / go (push) Successful in 2m17s
release / govulncheck (push) Successful in 26s
release / web (push) Successful in 2m4s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / integration (push) Canceled after 4m39s
release / android (push) Canceled after 2m53s
release / Build signed APK (releases and dev) (push) Canceled after 2m24s
Speakers fetch their own audio, so the phone cannot level it. A cast
token minted with level=true (and the client's asAlbum, which only the
queue holder knows) now returns GET /api/tracks/{id}/leveled.flac: the
track rendered by ffmpeg at the user's gain (volume=XdB, plus
alimiter at -1 dBFS for a limiter-mode boost), metadata stripped, FLAC
at 16 or 24 bits and at most 48 kHz. The gain is computed server-side
from the user's preference and the stored loudness, carried as
?g=<centi-dB>&lim=0|1 and signed into the token, so an edited URL does
not verify. Unity gains get the plain stream.
Renders are written beside the cache file and renamed in, keyed by the
source's size and mtime, coalesced per file (singleflight, detached
from the requesting speaker so a retry finds the render running),
started at mint time so the fetch finds them ready, and evicted least
recently used past leveled_cache_mb, a new admin setting (migration
0068, Loudness analysis card).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.2 KiB
Go
89 lines
3.2 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/library"
|
|
)
|
|
|
|
// loudnessCoverageResp is the wire shape for GET /api/admin/library/loudness
|
|
// (M464 #4995). measured + silent + unreadable + pending = total; missing
|
|
// tracks are not counted. Enabled travels with the counts because with
|
|
// analysis off, pending never shrinks, and a gauge implying progress would be
|
|
// promising work nothing is doing.
|
|
type loudnessCoverageResp struct {
|
|
Total int64 `json:"total"`
|
|
Measured int64 `json:"measured"`
|
|
Silent int64 `json:"silent"`
|
|
Unreadable int64 `json:"unreadable"`
|
|
Pending int64 `json:"pending"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
// handleGetLoudnessCoverage implements GET /api/admin/library/loudness: how
|
|
// far the loudness backfill has got. Always 200; zeros on an empty library.
|
|
func (h *handlers) handleGetLoudnessCoverage(w http.ResponseWriter, r *http.Request) {
|
|
row, err := library.LoudnessCoverage(r.Context(), h.pool)
|
|
if err != nil {
|
|
writeErrWithLog(w, h.logger, "admin: get loudness coverage", apierror.InternalMsg("lookup failed", err))
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, loudnessCoverageResp{
|
|
Total: row.Total,
|
|
Measured: row.Measured,
|
|
Silent: row.Silent,
|
|
Unreadable: row.Unreadable,
|
|
Pending: row.Pending,
|
|
Enabled: h.loudnessSettings.Get().Enabled,
|
|
})
|
|
}
|
|
|
|
// loudnessSettingsBody is the wire shape for GET and PUT
|
|
// /api/admin/library/loudness-settings.
|
|
type loudnessSettingsBody struct {
|
|
Enabled bool `json:"enabled"`
|
|
BackfillConcurrency int32 `json:"backfill_concurrency"`
|
|
LeveledCacheMB int32 `json:"leveled_cache_mb"`
|
|
}
|
|
|
|
func loudnessSettingsBodyOf(s library.LoudnessSettings) loudnessSettingsBody {
|
|
return loudnessSettingsBody{
|
|
Enabled: s.Enabled,
|
|
BackfillConcurrency: s.BackfillConcurrency,
|
|
LeveledCacheMB: s.LeveledCacheMB,
|
|
}
|
|
}
|
|
|
|
// handleGetLoudnessSettings implements GET /api/admin/library/loudness-settings.
|
|
func (h *handlers) handleGetLoudnessSettings(w http.ResponseWriter, _ *http.Request) {
|
|
writeJSON(w, http.StatusOK, loudnessSettingsBodyOf(h.loudnessSettings.Get()))
|
|
}
|
|
|
|
// handleUpdateLoudnessSettings implements PUT /api/admin/library/loudness-settings.
|
|
// A whole-row write: a body that leaves out the concurrency decodes it as zero,
|
|
// which is refused rather than saved.
|
|
func (h *handlers) handleUpdateLoudnessSettings(w http.ResponseWriter, r *http.Request) {
|
|
var req loudnessSettingsBody
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeErr(w, apierror.BadRequest("invalid_body", "malformed JSON"))
|
|
return
|
|
}
|
|
saved, err := h.loudnessSettings.Set(r.Context(), library.LoudnessSettings{
|
|
Enabled: req.Enabled,
|
|
BackfillConcurrency: req.BackfillConcurrency,
|
|
LeveledCacheMB: req.LeveledCacheMB,
|
|
})
|
|
if err != nil {
|
|
if errors.Is(err, library.ErrLoudnessSettingOutOfRange) {
|
|
writeErr(w, apierror.BadRequest("invalid_setting", err.Error()))
|
|
return
|
|
}
|
|
writeErrWithLog(w, h.logger, "admin loudness settings: update failed", apierror.Internal(err))
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, loudnessSettingsBodyOf(saved))
|
|
}
|