FFmpeg -> MediaMTX -> HLS relay with runtime-configurable modes: - PLAYBACK_MODE: standard (mpegts), fmp4 (HEVC), llhls - INGEST_MODE: rtmp, rtsp - INGEST_AUDIO_MODE: aac, copy - Hourly playlist auto-refresh from upstream URL - Fullscreen video UI with collapsible sidebar, upstream-down banner - Same-origin HLS proxy for HTTPS deployments Tagged as the last HLS-based version before the mpegts.js (v2) rework.
36 lines
870 B
Go
36 lines
870 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// FetchPlaylist downloads a playlist from url and writes it to destPath.
|
|
func FetchPlaylist(url, destPath string) error {
|
|
log.Printf("[playlist] fetching from %s", url)
|
|
resp, err := http.Get(url) //nolint:gosec
|
|
if err != nil {
|
|
return fmt.Errorf("fetch playlist: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
return fmt.Errorf("fetch playlist: server returned %s", resp.Status)
|
|
}
|
|
if err := os.MkdirAll("/data", 0o755); err != nil {
|
|
return fmt.Errorf("mkdir /data: %w", err)
|
|
}
|
|
f, err := os.Create(destPath)
|
|
if err != nil {
|
|
return fmt.Errorf("create playlist file: %w", err)
|
|
}
|
|
defer f.Close()
|
|
if _, err := io.Copy(f, resp.Body); err != nil {
|
|
return fmt.Errorf("write playlist file: %w", err)
|
|
}
|
|
log.Printf("[playlist] saved to %s", destPath)
|
|
return nil
|
|
}
|