Documentation
¶
Overview ¶
Package veld provides a high-performance HLS/DASH media downloader.
Basic usage:
d, err := veld.New(
veld.WithURL("https://example.com/video.m3u8"),
veld.WithOutput("video.mp4"),
)
if err != nil {
log.Fatal(err)
}
defer d.Close()
if err := d.Parse(ctx); err != nil {
log.Fatal(err)
}
if err := d.SelectTracks(); err != nil {
log.Fatal(err)
}
if err := d.Download(ctx); err != nil {
log.Fatal(err)
}
Or use the convenience function:
err := veld.DownloadURL(ctx, "https://example.com/video.m3u8", "video.mp4")
Index ¶
- func DownloadURL(ctx context.Context, url, filename string, opts ...Option) error
- type Downloader
- func (d *Downloader) Close() error
- func (d *Downloader) Download(ctx context.Context) error
- func (d *Downloader) ManifestType() string
- func (d *Downloader) Parse(ctx context.Context) error
- func (d *Downloader) Progress() <-chan ProgressUpdate
- func (d *Downloader) SelectTracks() error
- func (d *Downloader) SelectedTracks() []*Track
- func (d *Downloader) SetSelectedTracks(tracks []*Track)
- func (d *Downloader) Tracks() []*Track
- type Manager
- func (m *Manager) AddTask(id, url, filename string, opts ...Option) (*Task, error)
- func (m *Manager) CancelTask(id string) error
- func (m *Manager) GetActiveTasks() []*Task
- func (m *Manager) GetAllTasks() []*Task
- func (m *Manager) GetPendingCount() int
- func (m *Manager) GetTask(id string) *Task
- func (m *Manager) RemoveTask(id string) error
- func (m *Manager) Start()
- func (m *Manager) Stats() ManagerStats
- func (m *Manager) Stop()
- func (m *Manager) WaitAll()
- func (m *Manager) WaitForTask(id string) error
- type ManagerOption
- func WithDefaultOptions(opts ...Option) ManagerOption
- func WithMaxConcurrent(n int) ManagerOption
- func WithOnComplete(fn func(task *Task)) ManagerOption
- func WithOnError(fn func(task *Task, err error)) ManagerOption
- func WithOnProgress(fn func(task *Task)) ManagerOption
- func WithOnStateChange(fn func(task *Task)) ManagerOption
- func WithTitle(t string) ManagerOption
- type ManagerStats
- type ManagerUI
- type Option
- func WithCookies(cookies string) Option
- func WithDecryptionKeys(keys []string) Option
- func WithDir(dir string) Option
- func WithFileName(filename string) Option
- func WithFormat(format string) Option
- func WithHeader(key, value string) Option
- func WithHeaders(headers map[string]string) Option
- func WithMaxBandwidth(bytesPerSec int64) Option
- func WithParallelTracks(parallel bool) Option
- func WithThreads(n int) Option
- func WithTrackSelector(selector string) Option
- func WithURL(url string) Option
- func WithVerbose(verbose bool) Option
- type ProgressUpdate
- type Task
- type TaskProgress
- type TaskState
- type Track
- func (t *Track) Bandwidth() int64
- func (t *Track) Codec() string
- func (t *Track) Height() int
- func (t *Track) ID() string
- func (t *Track) IsAudio() bool
- func (t *Track) IsEncrypted() bool
- func (t *Track) IsSubtitle() bool
- func (t *Track) IsVideo() bool
- func (t *Track) Language() string
- func (t *Track) Name() string
- func (t *Track) QualityLabel() string
- func (t *Track) Resolution() string
- func (t *Track) SegmentCount() int
- func (t *Track) Type() TrackType
- func (t *Track) Width() int
- type TrackType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader is the main API for downloading media streams.
func New ¶
func New(opts ...Option) (*Downloader, error)
New creates a new Downloader with the given options.
func (*Downloader) Close ¶
func (d *Downloader) Close() error
Close releases all resources held by the downloader. Always call Close() when done, preferably with defer.
func (*Downloader) Download ¶
func (d *Downloader) Download(ctx context.Context) error
Download starts the download process. Blocks until complete or context is canceled.
func (*Downloader) ManifestType ¶
func (d *Downloader) ManifestType() string
ManifestType returns the type of manifest ("HLS" or "DASH"). Returns empty string if Parse() hasn't been called.
func (*Downloader) Parse ¶
func (d *Downloader) Parse(ctx context.Context) error
Parse fetches and parses the manifest from the configured URL. Must be called before Tracks(), SelectTracks(), or Download().
func (*Downloader) Progress ¶
func (d *Downloader) Progress() <-chan ProgressUpdate
Progress returns a channel for receiving download progress updates. The channel is closed when the download completes.
func (*Downloader) SelectTracks ¶
func (d *Downloader) SelectTracks() error
SelectTracks selects tracks based on the configured selector. If no selector was configured, uses "best" (best video + best audio).
func (*Downloader) SelectedTracks ¶
func (d *Downloader) SelectedTracks() []*Track
SelectedTracks returns the currently selected tracks.
func (*Downloader) SetSelectedTracks ¶
func (d *Downloader) SetSelectedTracks(tracks []*Track)
SetSelectedTracks allows manual track selection. Pass tracks obtained from Tracks().
func (*Downloader) Tracks ¶
func (d *Downloader) Tracks() []*Track
Tracks returns all available tracks after parsing. Returns nil if Parse() hasn't been called.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles queued downloads with concurrency control.
func NewManager ¶
func NewManager(opts ...ManagerOption) *Manager
NewManager creates a new download manager.
func (*Manager) CancelTask ¶
CancelTask cancels a specific task.
func (*Manager) GetActiveTasks ¶
GetActiveTasks returns currently downloading tasks.
func (*Manager) GetAllTasks ¶
GetAllTasks returns all tasks in order.
func (*Manager) GetPendingCount ¶
GetPendingCount returns the number of pending tasks.
func (*Manager) RemoveTask ¶
RemoveTask removes a completed/failed/canceled task.
func (*Manager) Stats ¶
func (m *Manager) Stats() ManagerStats
Stats returns current manager statistics.
func (*Manager) Stop ¶
func (m *Manager) Stop()
Stop gracefully stops the manager and waits for active downloads.
func (*Manager) WaitForTask ¶
WaitForTask blocks until a specific task completes.
type ManagerOption ¶
type ManagerOption func(*Manager)
ManagerOption configures the Manager.
func WithDefaultOptions ¶
func WithDefaultOptions(opts ...Option) ManagerOption
WithDefaultOptions sets default options applied to all tasks.
func WithMaxConcurrent ¶
func WithMaxConcurrent(n int) ManagerOption
WithMaxConcurrent sets the maximum number of concurrent downloads.
func WithOnComplete ¶
func WithOnComplete(fn func(task *Task)) ManagerOption
WithOnComplete sets a callback for task completion.
func WithOnError ¶
func WithOnError(fn func(task *Task, err error)) ManagerOption
WithOnError sets a callback for task errors.
func WithOnProgress ¶
func WithOnProgress(fn func(task *Task)) ManagerOption
WithOnProgress sets a callback for progress updates.
func WithOnStateChange ¶
func WithOnStateChange(fn func(task *Task)) ManagerOption
WithOnStateChange sets a callback for task state changes.
type ManagerStats ¶
ManagerStats holds manager statistics.
type ManagerUI ¶
type ManagerUI struct {
// contains filtered or unexported fields
}
ManagerUI provides a beautiful terminal UI for the download manager.
func NewManagerUI ¶
NewManagerUI creates a new manager UI.
type Option ¶
Option configures the downloader.
func WithCookies ¶
WithCookies sets cookies for HTTP requests.
func WithDecryptionKeys ¶
WithDecryptionKey sets the decryption key in "KID:KEY" format (32 hex chars each).
func WithFormat ¶
WithFormat sets the output format: "mp4", "mkv", or "ts" (default: "mp4").
func WithHeaders ¶
WithHeaders sets custom HTTP headers for requests.
func WithMaxBandwidth ¶
WithMaxBandwidth sets maximum download speed in bytes per second. Set to 0 for unlimited (default).
func WithParallelTracks ¶
WithParallelTracks enables downloading all tracks concurrently.
func WithThreads ¶
WithThreads sets the number of concurrent download threads (default: 16, max: 128).
func WithTrackSelector ¶
WithTrackSelector sets the track selection string. Examples: "best", "1080p", "720p", "all", "video:0+audio:1"
type ProgressUpdate ¶
type ProgressUpdate struct {
// SegmentIndex is the index of the segment that was processed.
SegmentIndex int
// TrackID is the ID of the track this segment belongs to.
TrackID string
// BytesLoaded is the number of bytes downloaded for this segment.
BytesLoaded int64
// Completed is true if the segment was successfully downloaded.
Completed bool
// Error is non-nil if the segment download failed.
Error error
}
ProgressUpdate represents a download progress update.
type Task ¶
type Task struct {
ID string
URL string
FileName string
Options []Option
State TaskState
Error error
Progress TaskProgress
CreatedAt time.Time
StartedAt time.Time
CompletedAt time.Time
Tracks []*Track
SelectedTracks []*Track
// contains filtered or unexported fields
}
Task represents a download task in the queue.
type TaskProgress ¶
type TaskProgress struct {
TotalSegments int
CompletedSegments int
TotalBytes int64
DownloadedBytes int64
Speed float64 // bytes per second
ETA time.Duration
CurrentTrack string
}
TaskProgress holds progress information for a task.
func (TaskProgress) Percent ¶
func (p TaskProgress) Percent() float64
Percent returns the download progress as a percentage.
type Track ¶
type Track struct {
// contains filtered or unexported fields
}
Track represents a media track (video, audio, or subtitle).
func (*Track) IsEncrypted ¶
IsEncrypted returns true if the track is encrypted.
func (*Track) IsSubtitle ¶
IsSubtitle returns true if this is a subtitle track.
func (*Track) QualityLabel ¶
QualityLabel returns a human-readable quality label (e.g., "1080p", "720p", "4K").
func (*Track) Resolution ¶
Resolution returns the resolution as "WxH" string (empty for non-video).
func (*Track) SegmentCount ¶
SegmentCount returns the number of segments in this track.
type TrackType ¶
type TrackType int
TrackType represents the type of media track.
const ( TrackVideo TrackType = TrackType(models.TrackVideo) TrackAudio TrackType = TrackType(models.TrackAudio) TrackSubtitle TrackType = TrackType(models.TrackSubtitle) )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
selector_test
command
|
|
|
veld
command
|
|
|
internal
|
|
|
config
Package config provides configuration types for the downloader.
|
Package config provides configuration types for the downloader. |
|
decryptor
Package decryptor handles decryption of encrypted DASH segments.
|
Package decryptor handles decryption of encrypted DASH segments. |
|
engine
Package engine provides the high-performance download engine.
|
Package engine provides the high-performance download engine. |
|
httpclient
Package httpclient provides a shared, optimized HTTP client for veld.
|
Package httpclient provides a shared, optimized HTTP client for veld. |
|
models
Package models defines core data structures for media streams.
|
Package models defines core data structures for media streams. |
|
parser
Package parser provides manifest parsing for HLS and DASH streams.
|
Package parser provides manifest parsing for HLS and DASH streams. |