-
Notifications
You must be signed in to change notification settings - Fork 330
Add CLOSED-CAPTIONS= to writer for (STREAM-INF) #79
Conversation
Would you be able to add reader support and tests? EDIT: sorry, there is reader support already, but can you add a test for both reader and writer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extra tests, I've added some feedback, we should be able to simplify some of these and still achieve a decent test.
reader_test.go
Outdated
} | ||
|
||
for i, v := range p.Variants { | ||
//spew.Dump(p.Variants) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment can be removed
reader_test.go
Outdated
if i == 0 && len(v.Alternatives) != 5 { | ||
t.Fatalf("not all alternatives from #EXT-X-MEDIA parsed (has %d but should be 5", len(v.Alternatives)) | ||
} | ||
if i > 0 && len(v.Alternatives) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither of these if
blocks belong here, looks like they were from the previous test testing Alternatives, feel free to just have the one if v.Captions ~!= ...
, that's all you need to test for.
reader_test.go
Outdated
@@ -96,7 +96,40 @@ func TestDecodeMasterPlaylistWithAlternatives(t *testing.T) { | |||
t.Fatal("should not be alternatives for this variant") | |||
} | |||
} | |||
// fmt.Println(p.Encode().String()) | |||
//fmt.Println(p.Encode().String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line probably didn't need to be changed. We can remove it in another cleanup.
reader_test.go
Outdated
t.Fatal("variant field for CLOSED-CAPTIONS should be equal to NONE but it equals", v.Captions) | ||
} | ||
} | ||
//fmt.Println(p.Encode().String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed, it appears to have just come from a copy/paste.
} | ||
|
||
// Create new master playlist supporting closed-caption=none | ||
func TestNewMasterPlaylistWithClosedCaptionEqNone(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very comprehensive test, but I don't think it really needs to be. Can the same writing test be achieved by just having a single master playlist, with one variant setting the Alternative Closed Captions to none?
And then the test can be a straight forward strings.Contains, such as
Lines 192 to 221 in f55aa7a
func TestSetSCTEForMediaPlaylist(t *testing.T) { | |
tests := []struct { | |
Cue string | |
ID string | |
Time float64 | |
Expected string | |
}{ | |
{"CueData1", "", 0, `#EXT-SCTE35:CUE="CueData1"` + "\n"}, | |
{"CueData2", "ID2", 0, `#EXT-SCTE35:CUE="CueData2",ID="ID2"` + "\n"}, | |
{"CueData3", "ID3", 3.141, `#EXT-SCTE35:CUE="CueData3",ID="ID3",TIME=3.141` + "\n"}, | |
{"CueData4", "", 3.1, `#EXT-SCTE35:CUE="CueData4",TIME=3.1` + "\n"}, | |
{"CueData5", "", 3.0, `#EXT-SCTE35:CUE="CueData5",TIME=3` + "\n"}, | |
} | |
for _, test := range tests { | |
p, e := NewMediaPlaylist(1, 1) | |
if e != nil { | |
t.Fatalf("Create media playlist failed: %s", e) | |
} | |
if e = p.Append("test01.ts", 5.0, ""); e != nil { | |
t.Errorf("Add 1st segment to a media playlist failed: %s", e) | |
} | |
if e := p.SetSCTE(test.Cue, test.ID, test.Time); e != nil { | |
t.Errorf("SetSCTE to a media playlist failed: %s", e) | |
} | |
if !strings.Contains(p.String(), test.Expected) { | |
t.Errorf("Test %+v did not contain: %q, playlist: %v", test, test.Expected, p.String()) | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will do.
writer_test.go
Outdated
if m.ver != 4 { | ||
t.Fatalf("Expected version 4, actual, %d", m.ver) | ||
} | ||
// diff with master file using reader. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on test, but I don't think this test needs to be any more complicated than a strings.Contains.
If we do want this comprehensive test (@grafov thoughts?), then this test should be renamed to something like TestNewMasterPlaylistWithAlternates
and a simpler string comparison should be made instead of bringing in difflib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as the library code is simple and doesn't need external deps so the tests should avoid external deps too.
I can see more commits, and they're looking good, but you haven't stated you're finished, so I'll await your confirmation before reviewing. |
I think that's it, let me know if I've missed anything. |
writer_test.go
Outdated
// Create new master playlist supporting closed-caption=none | ||
func TestNewMasterPlaylistWithClosedCaptionEqNone(t *testing.T) { | ||
m := NewMasterPlaylist() | ||
var alts = []*Alternative{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing, is this still required? If it's just to test for captions == none, I don't think we need an alternative for it? I'm not familiar with alternative or captions myself in m3u8 spec, so if an Alternative is required to set Captions to none then I'm OK with leaving it in, but if it's not required, then I think we can remove this from here too.
This is fine, one minor comment, but then I think we can merge. |
Thanks yes looks like don't need set up Alts, so have removed it. |
You're a champion, thanks for the time, looks good to me but the CI failure seems to be a gofmt issue, did you not have a chance to run that - could you? |
apologies no idea why Gogland IDE didn't do that, cli way works fine. |
Thanks for the contribution @mbowBC |
No description provided.