Skip to content

Commit

Permalink
Merge pull request #31 from bradleyfalzon/existing-query
Browse files Browse the repository at this point in the history
Append Args if playlist already has query params
  • Loading branch information
grafov committed Oct 17, 2015
2 parents 535475c + 76df961 commit c84e6d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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 @@ -213,7 +214,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
22 changes: 22 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,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

0 comments on commit c84e6d9

Please sign in to comment.