Documentation
¶
Overview ¶
Package video provides a pure Go video download engine supporting YouTube and other video platforms. It is designed as a reusable library that can be imported by external Go projects.
The package follows a layered architecture:
- types/errors: Core data structures and error types
- utils: Filename sanitization, HTML parsing, URL manipulation, duration parsing
- nethttp: HTTP client with cookie jar, proxy, retries, custom UA
- cache: Filesystem-based cache using XDG paths
- jsinterp: JavaScript execution via goja (for YouTube signature decryption)
- m3u8: HLS manifest parser
- format: Format sorting and selection
- downloader: HTTP and HLS download engines with resume support
- extractor: Site-specific video metadata extractors
Basic usage:
client := video.New(video.WithFormat("best"))
info, err := client.Extract(ctx, "https://www.youtube.com/watch?v=...")
if err != nil {
log.Fatal(err)
}
err = client.Download(ctx, info)
Index ¶
- func ListExtractors() []string
- type AgeRestrictedError
- type Chapter
- type Client
- type DownloadError
- type ExtractorError
- type Format
- type Fragment
- type GeoRestrictedError
- type Option
- func WithCacheDir(dir string) Option
- func WithContinue() Option
- func WithCookieFile(path string) Option
- func WithFormat(f string) Option
- func WithHeaders(headers map[string]string) Option
- func WithNoPart() Option
- func WithNoPlaylist() Option
- func WithNoProgress() Option
- func WithOutput(tmpl string) Option
- func WithProgress(fn ProgressFunc) Option
- func WithProxy(proxy string) Option
- func WithQuiet() Option
- func WithRateLimit(bytesPerSec int64) Option
- func WithRetries(n int) Option
- func WithVerbose() Option
- func WithWriteInfo() Option
- func WithWriteSubs() Option
- type Options
- type ProgressFunc
- type ProgressInfo
- type Subtitle
- type Thumbnail
- type UnsupportedError
- type VideoInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListExtractors ¶
func ListExtractors() []string
ListExtractors returns the names of all registered extractors.
Types ¶
type AgeRestrictedError ¶
type AgeRestrictedError struct {
Message string
}
AgeRestrictedError is returned when age verification is required.
func (*AgeRestrictedError) Error ¶
func (e *AgeRestrictedError) Error() string
type Chapter ¶
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main video download orchestrator.
func (*Client) DownloadInfo ¶
DownloadInfo downloads a video from previously extracted info.
type DownloadError ¶
DownloadError is returned when a download fails.
func (*DownloadError) Error ¶
func (e *DownloadError) Error() string
func (*DownloadError) Unwrap ¶
func (e *DownloadError) Unwrap() error
type ExtractorError ¶
type ExtractorError = types.ExtractorError
Re-export error types from the types sub-package.
type Format ¶
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type Fragment ¶
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type GeoRestrictedError ¶
type GeoRestrictedError = types.GeoRestrictedError
Re-export error types from the types sub-package.
type Option ¶
type Option func(*Options)
Option is a functional option for configuring the client.
func WithCookieFile ¶
WithCookieFile sets the cookie file path.
func WithHeaders ¶
WithHeaders adds custom HTTP headers.
func WithProgress ¶
func WithProgress(fn ProgressFunc) Option
WithProgress sets the progress callback.
func WithRateLimit ¶
WithRateLimit sets the download rate limit in bytes per second.
type Options ¶
type Options struct {
Format string // Format selector (e.g., "best", "worst", "bestvideo")
Output string // Output filename template
Quiet bool // Suppress progress output
NoProgress bool // Disable progress bar
RateLimit int64 // Rate limit in bytes/sec
Retries int // Number of download retries
Continue bool // Resume partial downloads
NoPart bool // Don't use .part files
CookieFile string // Path to cookies.txt
Proxy string // HTTP/SOCKS proxy URL
UserAgent string // Custom User-Agent
Headers map[string]string // Additional HTTP headers
WriteInfo bool // Write .info.json alongside video
WriteSubs bool // Write subtitles
NoPlaylist bool // Don't download playlists
PlaylistStart int // Playlist start index (1-based)
PlaylistEnd int // Playlist end index
Verbose bool // Verbose logging
CacheDir string // Cache directory
Progress ProgressFunc // Progress callback
}
Options configures the video download client.
type ProgressFunc ¶
type ProgressFunc = types.ProgressFunc
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type ProgressInfo ¶
type ProgressInfo = types.ProgressInfo
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type Subtitle ¶
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type Thumbnail ¶
Re-export types from the types sub-package for convenience. External consumers can import either pkg/video or pkg/video/types.
type UnsupportedError ¶
type UnsupportedError = types.UnsupportedError
Re-export error types from the types sub-package.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cache provides a filesystem-based cache using XDG directory conventions for storing and retrieving JSON-serialized data across video download sessions.
|
Package cache provides a filesystem-based cache using XDG directory conventions for storing and retrieving JSON-serialized data across video download sessions. |
|
Package downloader provides video download engines for HTTP/HTTPS and HLS (M3U8) protocols with resume, retry, rate limiting, and progress tracking support.
|
Package downloader provides video download engines for HTTP/HTTPS and HLS (M3U8) protocols with resume, retry, rate limiting, and progress tracking support. |
|
Package extractor defines the Extractor interface and provides a global registry for site-specific video metadata extractors.
|
Package extractor defines the Extractor interface and provides a global registry for site-specific video metadata extractors. |
|
all
Package all imports all extractor packages to register them.
|
Package all imports all extractor packages to register them. |
|
Package format provides video format sorting by quality and a selector that parses format specification strings like "best", "worst", "bestvideo", and filter expressions like "best[height<=720]".
|
Package format provides video format sorting by quality and a selector that parses format specification strings like "best", "worst", "bestvideo", and filter expressions like "best[height<=720]". |
|
Package jsinterp provides a JavaScript execution environment using the goja runtime for decrypting YouTube video signatures and throttling parameters (nsig).
|
Package jsinterp provides a JavaScript execution environment using the goja runtime for decrypting YouTube video signatures and throttling parameters (nsig). |
|
Package m3u8 provides an HLS manifest parser that handles both master and media playlists, including segment durations, encryption keys (EXT-X-KEY), and variant stream selection.
|
Package m3u8 provides an HLS manifest parser that handles both master and media playlists, including segment durations, encryption keys (EXT-X-KEY), and variant stream selection. |
|
Package nethttp provides an HTTP client wrapper with cookie jar support, proxy configuration, custom headers, user-agent, and automatic retries for the video download engine.
|
Package nethttp provides an HTTP client wrapper with cookie jar support, proxy configuration, custom headers, user-agent, and automatic retries for the video download engine. |
|
Package types defines shared data structures for the video download engine including VideoInfo, Format, Fragment, Thumbnail, Subtitle, Chapter, and error types.
|
Package types defines shared data structures for the video download engine including VideoInfo, Format, Fragment, Thumbnail, Subtitle, Chapter, and error types. |
|
Package utils provides shared utility functions for the video download engine including filename sanitization, HTML metadata extraction, URL manipulation, duration/filesize parsing, and nested JSON traversal.
|
Package utils provides shared utility functions for the video download engine including filename sanitization, HTML metadata extraction, URL manipulation, duration/filesize parsing, and nested JSON traversal. |