grafov / m3u8

Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. :cinema:
http://tools.ietf.org/html/draft-pantos-http-live-streaming
BSD 3-Clause "New" or "Revised" License
1.23k stars 313 forks source link

Feature Request: m3u8.MediaSegment implements fmt.Stringer #98

Open keizo042 opened 6 years ago

keizo042 commented 6 years ago

hello dev. Thanks you for your great work. the library is very useful :-)

I'd like to implement (m MediaSegment) String()string for testing like below. When failing test, I'd like to report as m3u8 text.

package something

import (
    "github.com/grafov/m3u8"
    "testing"
)

func TestXXX(t *testing.T) {
    var expected, actual m3u8.MediaSegment

        actual = do_something()
    if expected.SeqId != actual.SeqId {
        t.Fatalf("expected:%s,  but actual:%s\n", expected.String(), actual.String())
    }
}

there are already (p *MediaPlaylist) String() string and it converts m3u8.MeidaSegment to string. We can use the procedure to implement function I request.

If you agree to the issue but don't have enough time, I'd like to send PR.

bradleyfalzon commented 6 years ago

This sounds reasonable, but there's a lot to output, what do you think it would show?

If you agree to the issue but don't have enough time, I'd like to send PR.

This would be great, thanks.

keizo042 commented 6 years ago

It would be good it is same result to media segment part of (p *m3u8.MediaPlaylist) String() string

When all m3u8.MediaSegment field is presense, (p *m3u8.MediaPlaylist) Decode()(byte.Buffer, error) and (p *m3u8.MediaPlaylist) String() string dump like this .

#EXT-SCTE35:CUE="base64==",ID="identify",TIME=30
#EXT-X-KEY:METHOD=,URI="http://example.com/key",IV=iv
#EXT-X-DISCONTINUITY
#EXT-X-MAP:URI="http;//url",BYTERANGE=10@0
#EXT-X-BYTERANGE:10@0
#EXTINF:10.000,hogehoge
http://example.com/media.ts

I suppose it is not so a lot.

bradleyfalzon commented 6 years ago

That looks good to me.

bradleyfalzon commented 6 years ago

@grafov thoughts?

grafov commented 6 years ago

@bradleyfalzon I think it is ok to implement such method. @keizo042 would you create PR?