Help us shape the future of Go! Take the 2026 Go Developer Survey

m3u8

package module
v0.0.0-...-5afedeb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2019 License: MIT Imports: 8 Imported by: 1

README

m3u8-decoder

CircleCI

m3u8-decoder is a Go library base of rfc8216

Installation

$ go get github.com/poccariswet/m3u8-decoder

Usage


func main() {
  master, err := os.Open("master.m3u8")
  if err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(1)
  }

  playlist, err := m3u8.DecodeFrom(bufio.NewReader(master)) // or ReadFile
  if err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(1)
  }

  fmt.Println(playlist)
}

see

pure go m3u8 decoder

thx

Documentation

Index

Constants

View Source
const (

	// Playlist
	EXTM3U                   = `#EXTM3U`
	ExtENDList               = `#EXT-X-ENDLIST`
	ExtTargetDutation        = `#EXT-X-TARGETDURATION`
	ExtAllowCache            = `#EXT-X-ALLOW-CACHE`
	ExtDiscontinuitySequence = `#EXT-X-DISCONTINUITY-SEQUENCE`
	ExtIndependentSegments   = `#EXT-X-INDEPENDENT-SEGMENTS`
	ExtPlaylistType          = `#EXT-X-PLAYLIST-TYPE`
	ExtIFramesOnly           = `#EXT-X-I-FRAMES-ONLY`
	ExtMediaSequence         = `#EXT-X-MEDIA-SEQUENCE`
	ExtVersion               = `#EXT-X-VERSION`

	// Variant Playlist
	ExtSessionKey      = `#EXT-X-SESSION-KEY`
	ExtKey             = `#EXT-X-KEY`
	ExtDiscontinuity   = `#EXT-X-DISCONTINUITY`
	ExtProgramDateTime = `#EXT-X-PROGRAM-DATE-TIME`
	ExtDateRange       = `#EXT-X-DATERANGE`
	ExtMap             = `#EXT-X-MAP`
	ExtSessionData     = `#EXT-X-SESSION-DATA`
	EXTINF             = `#EXTINF`
	ExtByteRange       = `#EXT-X-BYTERANGE`
	ExtStart           = `#EXT-X-START`
	ExtMedia           = `#EXT-X-MEDIA`
	ExtStreamInf       = `#EXT-X-STREAM-INF`
	ExtFrameStreamInf  = `#EXT-X-I-FRAME-STREAM-INF`

	// for low-latency
	ExtServerControl   = `#EXT-X-SERVER-CONTROL`
	ExtPartInf         = `#EXT-X-PART-INF`
	ExtPart            = `#EXT-X-PART`
	ExtRenditionReport = `#EXT-X-RENDITION-REPORT`
	ExtSkip            = `#EXT-X-SKIP`

	// rendition report
	LASTMSN  = "LAST-MSN"
	LASTPART = "LAST-PART"

	// server control
	CANBLOCKRELOAD = "CAN-BLOCK-RELOAD"
	HOLDBACK       = "HOLD-BACK"
	PARTHOLDBACK   = "PART-HOLD-BACK"
	CANSKIPUNTIL   = "CAN-SKIP-UNTIL"

	// part
	PARTTARGET  = "PART-TARGET"
	INDEPENDENT = "INDEPENDENT"
	GAP         = "GAP"

	// skip
	SKIPPEDSEGMENTS = "SKIPPED-SEGMENTS"

	// Utility tag
	URI      = "URI"
	DURATION = "DURATION"

	// ByteRange
	BYTERANGE = "BYTERANGE"

	// Encrypt key
	METHOD            = "METHOD"
	IV                = "IV"
	KEYFORMAT         = "KEYFORMAT"
	KEYFORMATVERSIONS = "KEYFORMATVERSIONS"

	// DateRange
	ID              = "ID"
	CLASS           = "CLASS"
	STARTDATE       = "START-DATE"
	ENDDATE         = "END-DATE"
	PLANNEDDURATION = "PLANNED-DURATION"
	SCTE35CMD       = "SCTE35-CMD"
	SCTE35OUT       = "SCTE35-OUT"
	SCTE35IN        = "SCTE35-IN"
	ENDONNEXT       = "END-ON-NEXT"

	// Ext-Start
	TIMEOFFSET = "TIME-OFFSET"
	PRECISE    = "PRECISE"

	// Session
	DATAID = "DATA-ID"
	VALUE  = "VALUE"

	// MediaType
	TYPE            = "TYPE"
	GROUPID         = "GROUP-ID"
	LANGUAGE        = "LANGUAGE"
	ASSOCLANGUAGE   = "ASSOC-LANGUAGE"
	NAME            = "NAME"
	AUTOSELECT      = "AUTOSELECT"
	FORCED          = "FORCED"
	DEFAULT         = "DEFAULT"
	INSTREAMID      = "INSTREAM-ID"
	CHARACTERISTICS = "CHARACTERISTICS"
	CHANNELS        = "CHANNELS"

	/// Variant
	RESOLUTION       = "RESOLUTION"
	PROGRAMID        = "PROGRAM-ID"
	CODECS           = "CODECS"
	BANDWIDTH        = "BANDWIDTH"
	AVERAGEBANDWIDTH = "AVERAGE-BANDWIDTH"
	FRAMERATE        = "FRAME-RATE"
	VIDEO            = "VIDEO"
	AUDIO            = "AUDIO"
	SUBTITLES        = "SUBTITLES"
	CLOSEDCAPTIONS   = "CLOSED-CAPTIONS"
	HDCPLEVEL        = "HDCP-LEVEL"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteRangeSegment

type ByteRangeSegment struct {
	Length  int64 // the length of the sub-range in bytes
	Offset  int64 // a byte offset from the beginning of the resource
	Extflag bool  // whether EXT-BYTERANGE or BYTERANGE
}

EXT-X-BYTERANGE or BYTERANGE segment

func NewByteRange

func NewByteRange(line string) (*ByteRangeSegment, error)

func (*ByteRangeSegment) String

func (bs *ByteRangeSegment) String() string

type DateRangeSegment

type DateRangeSegment struct {
	ID              string
	Class           string
	StartDate       time.Time
	EndDate         time.Time
	Duration        float64
	PlannedDuration float64
	Scte35Cmd       string
	Scte35Out       string
	Scte35In        string
	EndOnNext       bool
}

EXT-X-DATERANGE range of time defined by a starting and ending date with a set of attribute / value pairs

func NewDateRange

func NewDateRange(line string) (*DateRangeSegment, error)

func (*DateRangeSegment) String

func (ds *DateRangeSegment) String() string

type DateTimeSegment

type DateTimeSegment struct {
	Time time.Time
}

EXT-X-PROGRAM-DATE-TIME tag segment

func NewProgramDateTime

func NewProgramDateTime(line string) (*DateTimeSegment, error)

func (*DateTimeSegment) String

func (ds *DateTimeSegment) String() string

type InfSegment

type InfSegment struct {
	Duration  float64
	URI       string
	ByteRange *ByteRangeSegment
}

EXTINF segment and, under uri

func NewExtInf

func NewExtInf(line string) (*InfSegment, error)

func (*InfSegment) String

func (is *InfSegment) String() string

type KeySegment

type KeySegment struct {
	Method            string
	IV                string // Initialization Vector
	URI               string
	KeyFormat         string
	KeyFormatVersions string
}

For decrypt media segments

func NewKey

func NewKey(line string) (*KeySegment, error)

func (*KeySegment) String

func (ks *KeySegment) String() string

type ListType

type ListType int
const (
	ERRTYPE ListType = iota
	MASTER
	MEDIA
)

type MapSegment

type MapSegment struct {
	URI       string
	ByteRange *ByteRangeSegment
}

EXT-X-MAP segment

func NewMap

func NewMap(line string) (*MapSegment, error)

func (*MapSegment) String

func (ms *MapSegment) String() string

type MediaSegment

type MediaSegment struct {
	Type            string
	GroupID         string
	Language        string
	AssocLanguage   string
	Name            string
	Autoselect      bool
	Forced          bool
	Default         bool
	URI             string
	InstreamID      string
	Characteristics string
	Channels        string
}

The EXT-X-MEDIA tag is used to relate Playlists that contain alternative renditions of the same content.

func NewMedia

func NewMedia(line string) (*MediaSegment, error)

NewMedia parse line has #EXT-X-MEDIA

func (*MediaSegment) String

func (ms *MediaSegment) String() string

type PartInfSegment

type PartInfSegment struct {
	PartTartget float64
}

func NewPartInf

func NewPartInf(line string) (*PartInfSegment, error)

func (*PartInfSegment) String

func (ps *PartInfSegment) String() string

type PartSegment

type PartSegment struct {
	Duration    float64
	URI         string
	Independent bool
	ByteRange   *ByteRangeSegment
	Gap         bool
}

func NewPart

func NewPart(line string) (*PartSegment, error)

func (*PartSegment) String

func (ps *PartSegment) String() string

type Playlist

type Playlist struct {
	Version               uint8
	PlaylistType          string
	AllowCache            bool
	MediaSequence         uint64
	DiscontinuitySequence uint64
	TargetDuration        float64
	IndependentSegments   bool
	IFrameOnly            bool // EXT-X-I-FRAMES-ONLY

	Discontinty bool // EXT-X-DISCONTINUITY encoding discontinuity between the media segment that follows it and the one that preceded it.

	Segments []PlaylistSegment
	// contains filtered or unexported fields
}

master and media platlist segment

func DecodeFrom

func DecodeFrom(r io.Reader) (*Playlist, error)

DecodeFrom read a playlist passed from the io.Reader

func NewPlaylist

func NewPlaylist() *Playlist

func ReadFile

func ReadFile(path string) (*Playlist, error)

ReadFile reads contents from filepath and return Playlist

func (*Playlist) AppendSegment

func (p *Playlist) AppendSegment(pseg PlaylistSegment)

func (*Playlist) Master

func (p *Playlist) Master() bool

func (*Playlist) String

func (p *Playlist) String() string

type PlaylistSegment

type PlaylistSegment interface {
	String() string
}

type RenditionReportSegment

type RenditionReportSegment struct {
	URI      string
	LastMSN  uint64
	LastPART uint64
}

func NewReport

func NewReport(line string) (*RenditionReportSegment, error)

func (*RenditionReportSegment) String

func (rs *RenditionReportSegment) String() string

type Resolution

type Resolution struct {
	Width  uint16
	Height uint16
}

RESOLUTION=640x360

func NewResolution

func NewResolution(item map[string]string, param string) (*Resolution, error)

func (*Resolution) String

func (r *Resolution) String() string

type ServerControlSegment

type ServerControlSegment struct {
	CanBlockReload bool
	CanSkipUntil   float64
	HoldBack       float64
	PartHoldBack   float64
}

ServerControl indicate support for features such as Blocking Playlist Reload and Playlist Delta Updates

func NewServerControl

func NewServerControl(line string) (*ServerControlSegment, error)

New server control segment

func (*ServerControlSegment) String

func (ss *ServerControlSegment) String() string

segment to string

type SessionDataSegment

type SessionDataSegment struct {
	DataID   string
	Value    string
	URI      string
	Language string
}

EXT-X-SESSION-DATA segment

func NewSessionData

func NewSessionData(line string) (*SessionDataSegment, error)

func (*SessionDataSegment) String

func (ss *SessionDataSegment) String() string

type SessionKeySegment

type SessionKeySegment struct {
	Method            string
	IV                string // Initialization Vector
	URI               string
	KeyFormat         string
	KeyFormatVersions string
}

EXT-X-SESSION-KEY segment

func NewSessionKey

func NewSessionKey(line string) (*SessionKeySegment, error)

func (*SessionKeySegment) String

func (ss *SessionKeySegment) String() string

type SkipSegment

type SkipSegment struct {
	SkippedSegments uint64
}

func NewSkip

func NewSkip(line string) (*SkipSegment, error)

func (*SkipSegment) String

func (ss *SkipSegment) String() string

type StartSegment

type StartSegment struct {
	TimeOffset float64
	Precise    bool
}

EXT-X-START segment

func NewStart

func NewStart(line string) (*StartSegment, error)

func (*StartSegment) String

func (ss *StartSegment) String() string

type States

type States struct {
	// contains filtered or unexported fields
}

state of m3u and temporary store segments, stream inf...etc

type VariantSegment

type VariantSegment struct {
	IFrame bool

	URI              string
	Bandwidth        uint32
	Name             string
	Subtitle         string
	AverageBandwidth uint32
	ProgramID        uint32
	Codecs           string
	AudioCodec       string
	Audio            string
	Video            string
	FrameRate        float64
	ClosedCaptions   string
	HDCPLevel        string
	Resolution       *Resolution
}

EXT-X-STREAM-INF or EXT-X-I-FRAME-STREAM-INF segment

func NewVariant

func NewVariant(line string) (*VariantSegment, error)

NewVariant parse line has EXT-X-STREAM-INF or EXT-X-I-FRAME-STREAM-INF

func (*VariantSegment) String

func (vs *VariantSegment) String() string

Directories

Path Synopsis
cmd command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL