File: playbackStart.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 (37 lines) | stat: -rw-r--r-- 884 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
34
35
36
37
package m3u8

import (
	"fmt"
	"strconv"
	"strings"
)

// PlaybackStart represents a #EXT-X-START tag and attributes
type PlaybackStart struct {
	TimeOffset float64
	Precise    *bool
}

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

	timeOffset, err := strconv.ParseFloat(attributes[TimeOffsetTag], 64)
	if err != nil {
		return nil, err
	}

	return &PlaybackStart{
		TimeOffset: timeOffset,
		Precise:    parseYesNo(attributes, PreciseTag),
	}, nil
}

func (ps *PlaybackStart) String() string {
	slice := []string{fmt.Sprintf(formatString, TimeOffsetTag, ps.TimeOffset)}
	if ps.Precise != nil {
		slice = append(slice, fmt.Sprintf(formatString, PreciseTag, formatYesNo(*ps.Precise)))
	}

	return fmt.Sprintf(`%s:%s`, PlaybackStartTag, strings.Join(slice, ","))
}