commit 129d26cc2c31a77ef88feb3850ba3e363dadac99
parent 80c44981faf3320c9bcfe60ce32ce789e39d6be6
Author: Oliver Lowe <o@olowe.co>
Date: Thu, 23 May 2024 18:01:50 +1000
m3u8: only write some tags if they're set
Otherwise we write invalid, zero values to players.
Diffstat:
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/m3u8/m3u8.go b/m3u8/m3u8.go
@@ -126,7 +126,8 @@ type DateRange struct {
type PlaylistType uint8
const (
- PlaylistEvent PlaylistType = 0 + iota
+ PlaylistNone PlaylistType = iota
+ PlaylistEvent
PlaylistVOD
)
diff --git a/m3u8/write.go b/m3u8/write.go
@@ -12,9 +12,15 @@ import (
func Encode(w io.Writer, p *Playlist) error {
fmt.Fprintln(w, "#EXTM3U")
- fmt.Fprintf(w, "%s:%d\n", tagVersion, p.Version)
- fmt.Fprintf(w, "%s:%s\n", tagPlaylistType, p.Type)
- fmt.Fprintf(w, "%s:%d\n", tagTargetDuration, p.TargetDuration/time.Second)
+ if p.Version > 0 {
+ fmt.Fprintf(w, "%s:%d\n", tagVersion, p.Version)
+ }
+ if p.Type != PlaylistNone {
+ fmt.Fprintf(w, "%s:%s\n", tagPlaylistType, p.Type)
+ }
+ if p.TargetDuration > 0 {
+ fmt.Fprintf(w, "%s:%d\n", tagTargetDuration, p.TargetDuration/time.Second)
+ }
for _, seg := range p.Segments {
if seg.Discontinuity {
fmt.Fprintln(w, tagDiscontinuity)
@@ -29,6 +35,7 @@ func Encode(w io.Writer, p *Playlist) error {
fmt.Fprintf(w, "%s:%.03f\n", tagSegmentDuration, float32(us)/1e6)
fmt.Fprintln(w, seg.URI)
}
+
if p.End {
fmt.Fprintln(w, tagEndList)
}