Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Append Args if playlist already has query params #31

Merged
merged 1 commit into from
Oct 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"fmt"
"math"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -208,7 +209,11 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteRune('\n')
p.buf.WriteString(pl.URI)
if p.Args != "" {
p.buf.WriteRune('?')
if strings.Contains(pl.URI, "?") {
p.buf.WriteRune('&')
} else {
p.buf.WriteRune('?')
}
p.buf.WriteString(p.Args)
}
p.buf.WriteRune('\n')
Expand Down
23 changes: 23 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package m3u8

import (
"fmt"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -427,6 +428,28 @@ func TestNewMasterPlaylistWithParams(t *testing.T) {
m.Append("chunklist1.m3u8", p, VariantParams{ProgramId: 123, Bandwidth: 1500000, Resolution: "576x480"})
}

// Create new master playlist
// Add media playlist with existing query params in URI
// Append more query params and ensure it encodes correctly
func TestEncodeMasterPlaylistWithExistingQuery(t *testing.T) {
m := NewMasterPlaylist()
p, e := NewMediaPlaylist(3, 5)
if e != nil {
t.Fatalf("Create media playlist failed: %s", e)
}
for i := 0; i < 5; i++ {
e = p.Append(fmt.Sprintf("test%d.ts", i), 5.0, "")
if e != nil {
t.Errorf("Add segment #%d to a media playlist failed: %s", i, e)
}
}
m.Append("chunklist1.m3u8?k1=v1&k2=v2", p, VariantParams{ProgramId: 123, Bandwidth: 1500000, Resolution: "576x480"})
m.Args = "k3=v3"
if !strings.Contains(m.String(), "chunklist1.m3u8?k1=v1&k2=v2&k3=v3\n") {
t.Errorf("Encode master with existing args failed")
}
}

// Create new master playlist
// Add media playlist
// Encode structures to HLS
Expand Down