File: mapItem.go

package info (click to toggle)
golang-github-etherlabsio-go-m3u8 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: makefile: 3
file content (33 lines) | stat: -rw-r--r-- 739 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package m3u8

import "fmt"

// MapItem represents a EXT-X-MAP tag which specifies how to obtain the Media
// Initialization Section
type MapItem struct {
	URI       string
	ByteRange *ByteRange
}

// NewMapItem parses a text line and returns a *MapItem
func NewMapItem(text string) (*MapItem, error) {
	attributes := ParseAttributes(text)

	br, err := NewByteRange(attributes[ByteRangeTag])
	if err != nil {
		return nil, err
	}

	return &MapItem{
		URI:       attributes[URITag],
		ByteRange: br,
	}, nil
}

func (mi *MapItem) String() string {
	if mi.ByteRange == nil {
		return fmt.Sprintf(`%s:%s="%s"`, MapItemTag, URITag, mi.URI)
	}

	return fmt.Sprintf(`%s:%s="%s",%s="%v"`, MapItemTag, URITag, mi.URI, ByteRangeTag, mi.ByteRange)
}