Documentation ¶
Overview ¶
Package hls provides functions to download HLS streams.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrHLSForbidden is returned when the HLS download is stopped with a forbidden error. ErrHLSForbidden = errors.New("hls download stopped with forbidden error") )
Functions ¶
This section is empty.
Types ¶
type Checkpoint ¶ added in v1.7.0
type Checkpoint struct { LastFragmentName string LastFragmentTime time.Time UseTimeBasedSorting bool }
Checkpoint is used to resume the download from the last fragment.
func DefaultCheckpoint ¶ added in v1.7.0
func DefaultCheckpoint() Checkpoint
DefaultCheckpoint returns a default checkpoint.
type Downloader ¶
Downloader is used to download HLS streams.
func NewDownloader ¶
func NewDownloader( client *http.Client, log *zerolog.Logger, packetLossMax int, url string, ) *Downloader
NewDownloader creates a new HLS downloader.
func (*Downloader) GetFragmentURLs ¶
func (hls *Downloader) GetFragmentURLs(ctx context.Context) ([]string, error)
GetFragmentURLs fetches the fragment URLs from the HLS manifest.
func (*Downloader) Probe ¶ added in v1.7.0
func (hls *Downloader) Probe(ctx context.Context) (bool, error)
Probe checks if the stream is ready to be downloaded.
func (*Downloader) Read ¶
func (hls *Downloader) Read( ctx context.Context, writer io.Writer, checkpoint Checkpoint, ) (newCheckpoint Checkpoint, err error)
Read reads the HLS stream and sends the data to the writer.
Read runs two threads:
- A goroutine will continuously fetch the fragment URLs and send them to the urlsChan.
- The main thread will download the fragments and write them to the writer.
The function will return when the context is canceled or when the stream ends.
Click to show internal directories.
Click to hide internal directories.