streamd: copyable m3u8 links + FHD/HD/SD output variants
Some checks failed
release / build-and-upload (push) Failing after 3m33s
Some checks failed
release / build-and-upload (push) Failing after 3m33s
- WebUI Copy button for absolute m3u8 URLs (no player) - Per-stream variants ladder; HD/SD live-transcoded as sibling HLS - variants_json in DB/API; supervisor spawns scaled ffmpeg packagers
This commit is contained in:
parent
ac8701b5a6
commit
3cb259c9b6
12 changed files with 913 additions and 62 deletions
|
|
@ -17,21 +17,22 @@ type Store struct {
|
|||
}
|
||||
|
||||
type Stream struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
App string `json:"app"`
|
||||
Channel string `json:"channel"`
|
||||
MPD string `json:"mpd"`
|
||||
Key string `json:"key"`
|
||||
HeadersJSON string `json:"headers_json"`
|
||||
Proxy string `json:"proxy"` // socks5:// or http:// for origin fetch (NRE)
|
||||
VideoSelect string `json:"video_select"`
|
||||
AudioSelect string `json:"audio_select"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Rewriter string `json:"rewriter"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
App string `json:"app"`
|
||||
Channel string `json:"channel"`
|
||||
MPD string `json:"mpd"`
|
||||
Key string `json:"key"`
|
||||
HeadersJSON string `json:"headers_json"`
|
||||
Proxy string `json:"proxy"` // socks5:// or http:// for origin fetch (NRE)
|
||||
VideoSelect string `json:"video_select"`
|
||||
AudioSelect string `json:"audio_select"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Rewriter string `json:"rewriter"`
|
||||
VariantsJSON string `json:"variants_json"` // FHD/HD/SD ladder config
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
|
||||
Health string `json:"health,omitempty"`
|
||||
PID int64 `json:"pid,omitempty"`
|
||||
|
|
@ -42,37 +43,44 @@ type Stream struct {
|
|||
LastError string `json:"last_error,omitempty"`
|
||||
RuntimeAt string `json:"runtime_updated_at,omitempty"`
|
||||
|
||||
// Variants is filled for API responses (play paths + optional live health).
|
||||
Variants []VariantStatus `json:"variants,omitempty"`
|
||||
|
||||
ClaimedBy string `json:"claimed_by,omitempty"`
|
||||
ClaimExp string `json:"claim_expires_at,omitempty"`
|
||||
}
|
||||
|
||||
type CreateStream struct {
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
App string `json:"app"`
|
||||
Channel string `json:"channel"`
|
||||
MPD string `json:"mpd"`
|
||||
Key string `json:"key"`
|
||||
HeadersJSON string `json:"headers_json"`
|
||||
Proxy string `json:"proxy"`
|
||||
VideoSelect string `json:"video_select"`
|
||||
AudioSelect string `json:"audio_select"`
|
||||
Rewriter string `json:"rewriter"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
App string `json:"app"`
|
||||
Channel string `json:"channel"`
|
||||
MPD string `json:"mpd"`
|
||||
Key string `json:"key"`
|
||||
HeadersJSON string `json:"headers_json"`
|
||||
Proxy string `json:"proxy"`
|
||||
VideoSelect string `json:"video_select"`
|
||||
AudioSelect string `json:"audio_select"`
|
||||
Rewriter string `json:"rewriter"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
VariantsJSON string `json:"variants_json"`
|
||||
Variants []VariantSpec `json:"variants"`
|
||||
}
|
||||
|
||||
type PatchStream struct {
|
||||
Title *string `json:"title"`
|
||||
App *string `json:"app"`
|
||||
Channel *string `json:"channel"`
|
||||
MPD *string `json:"mpd"`
|
||||
Key *string `json:"key"`
|
||||
HeadersJSON *string `json:"headers_json"`
|
||||
Proxy *string `json:"proxy"`
|
||||
VideoSelect *string `json:"video_select"`
|
||||
AudioSelect *string `json:"audio_select"`
|
||||
Rewriter *string `json:"rewriter"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
Title *string `json:"title"`
|
||||
App *string `json:"app"`
|
||||
Channel *string `json:"channel"`
|
||||
MPD *string `json:"mpd"`
|
||||
Key *string `json:"key"`
|
||||
HeadersJSON *string `json:"headers_json"`
|
||||
Proxy *string `json:"proxy"`
|
||||
VideoSelect *string `json:"video_select"`
|
||||
AudioSelect *string `json:"audio_select"`
|
||||
Rewriter *string `json:"rewriter"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
VariantsJSON *string `json:"variants_json"`
|
||||
Variants []VariantSpec `json:"variants"`
|
||||
}
|
||||
|
||||
type Credentials struct {
|
||||
|
|
@ -148,8 +156,9 @@ CREATE TABLE IF NOT EXISTS agent_claims (
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Older DBs created before proxy existed.
|
||||
// Older DBs created before proxy / variants existed.
|
||||
_, _ = s.DB.Exec(`ALTER TABLE streams ADD COLUMN proxy TEXT NOT NULL DEFAULT ''`)
|
||||
_, _ = s.DB.Exec(`ALTER TABLE streams ADD COLUMN variants_json TEXT NOT NULL DEFAULT ''`)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +186,8 @@ func slug(name string) string {
|
|||
|
||||
const streamSelect = `
|
||||
SELECT s.id, s.name, s.title, s.app, s.channel, s.mpd, s.key_kid_key, s.headers_json,
|
||||
COALESCE(s.proxy,''), s.video_select, s.audio_select, s.enabled, s.rewriter, s.created_at, s.updated_at,
|
||||
COALESCE(s.proxy,''), s.video_select, s.audio_select, s.enabled, s.rewriter,
|
||||
COALESCE(s.variants_json,''), s.created_at, s.updated_at,
|
||||
COALESCE(r.health,''), COALESCE(r.pid,0), COALESCE(r.play_path,''),
|
||||
COALESCE(r.uptime_s,0), COALESCE(r.bitrate_mbps,0), COALESCE(r.playlist_age_s,0),
|
||||
COALESCE(r.last_error,''), COALESCE(r.updated_at,''),
|
||||
|
|
@ -217,7 +227,8 @@ func scanStream(row rowScanner) (Stream, error) {
|
|||
var enabled int
|
||||
err := row.Scan(
|
||||
&st.ID, &st.Name, &st.Title, &st.App, &st.Channel, &st.MPD, &st.Key, &st.HeadersJSON,
|
||||
&st.Proxy, &st.VideoSelect, &st.AudioSelect, &enabled, &st.Rewriter, &st.CreatedAt, &st.UpdatedAt,
|
||||
&st.Proxy, &st.VideoSelect, &st.AudioSelect, &enabled, &st.Rewriter, &st.VariantsJSON,
|
||||
&st.CreatedAt, &st.UpdatedAt,
|
||||
&st.Health, &st.PID, &st.PlayPath, &st.UptimeS, &st.BitrateMbps, &st.PlaylistAgeS,
|
||||
&st.LastError, &st.RuntimeAt, &st.ClaimedBy, &st.ClaimExp,
|
||||
)
|
||||
|
|
@ -231,6 +242,7 @@ func scanStream(row rowScanner) (Stream, error) {
|
|||
if st.PlayPath == "" {
|
||||
st.PlayPath = "/hls/" + st.Name + "/index.m3u8"
|
||||
}
|
||||
st.Variants = AttachVariantStatuses(st.Name, st.VariantsJSON, st.Health, st.PlaylistAgeS)
|
||||
// Hide expired claims in API responses (ExpireClaims cleans them shortly after).
|
||||
if st.ClaimExp != "" {
|
||||
if exp, e := time.Parse(time.RFC3339, st.ClaimExp); e == nil && !exp.After(time.Now().UTC()) {
|
||||
|
|
@ -241,6 +253,30 @@ func scanStream(row rowScanner) (Stream, error) {
|
|||
return st, nil
|
||||
}
|
||||
|
||||
// AttachVariantStatuses builds the variants array for API responses.
|
||||
// Source (FHD) inherits the stream health; scaled variants stay "configured"
|
||||
// until the supervisor refreshes them via EnrichVariantHealth.
|
||||
func AttachVariantStatuses(streamName, variantsJSON, streamHealth string, playlistAge float64) []VariantStatus {
|
||||
specs := ParseVariantsJSON(variantsJSON)
|
||||
out := make([]VariantStatus, 0, len(specs))
|
||||
for _, v := range specs {
|
||||
vs := VariantStatus{
|
||||
VariantSpec: v,
|
||||
PlayPath: VariantPlayPath(streamName, v.ID, v.Height),
|
||||
}
|
||||
if !v.Enabled {
|
||||
vs.Health = "off"
|
||||
} else if v.Height <= 0 {
|
||||
vs.Health = streamHealth
|
||||
vs.PlaylistAgeS = playlistAge
|
||||
} else {
|
||||
vs.Health = "pending"
|
||||
}
|
||||
out = append(out, vs)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Store) CreateStream(in CreateStream) (Stream, error) {
|
||||
name := slug(in.Name)
|
||||
if name == "" {
|
||||
|
|
@ -258,16 +294,32 @@ func (s *Store) CreateStream(in CreateStream) (Stream, error) {
|
|||
if in.Title == "" {
|
||||
in.Title = name
|
||||
}
|
||||
variantsJSON := strings.TrimSpace(in.VariantsJSON)
|
||||
if len(in.Variants) > 0 {
|
||||
encoded, err := EncodeVariantsJSON(in.Variants)
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
variantsJSON = encoded
|
||||
} else if variantsJSON == "" {
|
||||
variantsJSON, _ = EncodeVariantsJSON(DefaultVariants())
|
||||
} else {
|
||||
encoded, err := EncodeVariantsJSON(ParseVariantsJSON(variantsJSON))
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
variantsJSON = encoded
|
||||
}
|
||||
enabled := 0
|
||||
if in.Enabled != nil && *in.Enabled {
|
||||
enabled = 1
|
||||
}
|
||||
ts := now()
|
||||
res, err := s.DB.Exec(`
|
||||
INSERT INTO streams(name,title,app,channel,mpd,key_kid_key,headers_json,proxy,video_select,audio_select,enabled,rewriter,created_at,updated_at)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
INSERT INTO streams(name,title,app,channel,mpd,key_kid_key,headers_json,proxy,video_select,audio_select,enabled,rewriter,variants_json,created_at,updated_at)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
name, in.Title, in.App, in.Channel, in.MPD, in.Key, in.HeadersJSON, strings.TrimSpace(in.Proxy),
|
||||
in.VideoSelect, in.AudioSelect, enabled, in.Rewriter, ts, ts)
|
||||
in.VideoSelect, in.AudioSelect, enabled, in.Rewriter, variantsJSON, ts, ts)
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
|
|
@ -315,6 +367,19 @@ func (s *Store) PatchStream(id int64, in PatchStream) (Stream, error) {
|
|||
if in.Rewriter != nil {
|
||||
cur.Rewriter = *in.Rewriter
|
||||
}
|
||||
if len(in.Variants) > 0 {
|
||||
encoded, err := EncodeVariantsJSON(in.Variants)
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
cur.VariantsJSON = encoded
|
||||
} else if in.VariantsJSON != nil {
|
||||
encoded, err := EncodeVariantsJSON(ParseVariantsJSON(*in.VariantsJSON))
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
cur.VariantsJSON = encoded
|
||||
}
|
||||
enabled := 0
|
||||
if cur.Enabled {
|
||||
enabled = 1
|
||||
|
|
@ -329,9 +394,9 @@ func (s *Store) PatchStream(id int64, in PatchStream) (Stream, error) {
|
|||
ts := now()
|
||||
_, err = s.DB.Exec(`
|
||||
UPDATE streams SET title=?, app=?, channel=?, mpd=?, key_kid_key=?, headers_json=?, proxy=?,
|
||||
video_select=?, audio_select=?, enabled=?, rewriter=?, updated_at=? WHERE id=?`,
|
||||
video_select=?, audio_select=?, enabled=?, rewriter=?, variants_json=?, updated_at=? WHERE id=?`,
|
||||
cur.Title, cur.App, cur.Channel, cur.MPD, cur.Key, cur.HeadersJSON, cur.Proxy,
|
||||
cur.VideoSelect, cur.AudioSelect, enabled, cur.Rewriter, ts, id)
|
||||
cur.VideoSelect, cur.AudioSelect, enabled, cur.Rewriter, cur.VariantsJSON, ts, id)
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue