m3u8

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 22 Imported by: 0

README

m3u8

m3u8文件解析及下载视频到本地

Documentation

Index

Constants

View Source
const (
	ModelMerged       = 0
	ModelConvertToMP4 = 1
)
View Source
const (
	CryptMethodAES  = "AES-128"
	CryptMethodNONE = "NONE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllM3u8

type AllM3u8 struct {
	MastPlay *M3u8
	Common   *M3u8
}

type EncryptMeta

type EncryptMeta struct {
	SecretKeyUrl string
	IV           string
	Method       string
	SecretKey    string
}

type Event

type Event struct {
	*Segment
	Merged         *bool
	MergedFilePath string
	MergeErr       string // 仅在Merged不为nil且*Merged为false时不为nil
	ConvToMP4      *bool
	ConvToMP4Err   string // 仅在ConvToMP4不为nil且*ConvToMP4为false时不为nil
	MP4FilePath    string
}

Segment, Merger和ConvToMP4中有且只有一个为非nil

type M3u8

type M3u8 struct {
	Segments     []Segment
	MastPlayList []PlayInfo
	PlayListType string
	EndList      bool
}

func Parse

func Parse(content []byte, m3u8Url string) (*M3u8, error)

注意Parse不会填充SecretKey

func (*M3u8) Copy

func (m *M3u8) Copy() *M3u8

type Model

type Model int

type Option

type Option struct {
	M3u8Url             string
	Model               Model
	Qps                 int
	WorkerCnt           int
	ChooseStream        func(infos []PlayInfo) PlayInfo
	RemoveSubTs         bool
	FileDir             string
	TsFilePrefix        string
	HttpRequestCallback func(r *http.Request) error
}

func NewDefaultOption

func NewDefaultOption(m3u8Url string, model Model, fileDir string, tsFilePrefix string, workerCnt int) Option

type PlayInfo

type PlayInfo struct {
	M3u8Url    string
	ProgramId  int64
	BandWidth  int64
	Resolution Resolution
}

type Resolution

type Resolution struct {
	Width int64
	High  int64
}

type Result

type Result struct {
	Segments       []Segment
	Merged         bool
	MergeErr       string
	MergedFilePath string
	ConvToMP4      bool
	ConvToMP4Err   string
	MP4FilePath    string
}

func Download

func Download(ctx context.Context, m3u8Url string, model Model, fileDir string, tsFilePrefix string, workerCnt int, withBar bool) (*Result, error)

func GenResult

func GenResult(status Status, withBar bool) (ret *Result)

type Segment

type Segment struct {
	Idx         int
	Url         string
	Duration    time.Duration
	Sequence    int64
	EncryptMeta EncryptMeta
	ErrMsg      string
}

func (Segment) IsEncrypted

func (s Segment) IsEncrypted() bool

type Status

type Status interface {
	TsTotal() int    // 任务总数
	TsComplete() int // 已经完成的任务数(包含失败和成功的任务)
	Done() <-chan struct{}
	M3u8() AllM3u8
	Event() <-chan Event // 每完成一个任务向此chan中写入
	Shutdown()           // 强制终止下载
}

func DownloadWithOpt

func DownloadWithOpt(ctx context.Context, opt Option) (Status, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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