Documentation
¶
Overview ¶
Package vidpickr is the official Go SDK for the VidPickr API.
Quick start:
import "github.com/vidpickr/sdk-go"
vp := vidpickr.New(os.Getenv("VIDPICKR_API_KEY"))
err := vp.Download(ctx, "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
vidpickr.Out("video.mp4"),
vidpickr.Quality(1080),
)
One call: resolve, split, stream both tracks in parallel, mux locally with a pure-Go MP4 muxer (no ffmpeg dependency), write to disk.
Index ¶
- Constants
- type APIError
- type AudioFormat
- type Client
- func (c *Client) Info(ctx context.Context, target string) (*VideoInfo, error)
- func (c *Client) OpenStream(ctx context.Context, token string) (*http.Response, error)
- func (c *Client) SplitToken(ctx context.Context, mergeToken string) (*SplitTokenResult, error)
- func (c *Client) StreamToFile(ctx context.Context, token, path string) (int64, error)
- func (c *Client) Subtitle(ctx context.Context, token, format string) (string, error)
- type DownloadOption
- type MuxError
- type NoFormatError
- type Option
- type Progress
- type Resolution
- type SplitTokenResult
- type SubtitleTrack
- type VidPickr
- type VideoFormat
- type VideoInfo
Constants ¶
const DefaultBaseURL = "https://api.vidpickr.com/v1"
DefaultBaseURL is the production API host. Override via WithBaseURL for self-hosted deployments or local dev.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Code string
Message string
Status int
RetryAfter int // seconds; 0 when not provided
}
APIError mirrors the {"error": {"code", "message"}} JSON the API returns on 4xx/5xx. Branch on Code rather than Message for stable behaviour across API versions.
type AudioFormat ¶
type AudioFormat struct {
Ext string `json:"ext"`
ACodec string `json:"acodec"`
Bitrate int `json:"bitrate"`
SizeMB float64 `json:"size_mb"`
DownloadToken string `json:"download_token"`
Endpoint string `json:"endpoint"`
}
AudioFormat is a standalone audio track.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the low-level HTTP client. Most callers use the higher-level VidPickr type, which embeds a Client. Reach for Client directly when you need fine-grained control (custom retry policies, piping bytes into your own pipeline, etc.).
func (*Client) OpenStream ¶
OpenStream returns a response whose body streams the requested track. Caller MUST close res.Body. Use this when piping bytes directly into another consumer; for "stream to file" use StreamToFile.
func (*Client) SplitToken ¶
SplitToken exchanges a merge token (bundled video+audio) for two single-source tokens you can stream separately.
func (*Client) StreamToFile ¶
StreamToFile downloads a single track to disk. Returns total bytes written and any error.
type DownloadOption ¶
type DownloadOption func(*downloadConfig)
DownloadOption configures a single Download call.
func Codec ¶
func Codec(name string) DownloadOption
Codec picks a preferred video codec when multiple variants exist at the same height. One of: "av1", "vp9", "avc", "hevc".
func OnProgress ¶
func OnProgress(fn func(Progress)) DownloadOption
OnProgress wires a callback invoked between phases.
func Quality ¶
func Quality(q any) DownloadOption
Quality selects the target video height. Accepts:
"best", "highest" → top available resolution "lowest" → smallest available int (e.g. 1080) → exact match, fall back to next-lower
type MuxError ¶
type MuxError struct{ Reason string }
MuxError wraps a failure from the local MP4 mux step.
type NoFormatError ¶
type NoFormatError struct{ Reason string }
NoFormatError is returned when the caller requested a quality / codec combination that doesn't exist in the /info response.
func (*NoFormatError) Error ¶
func (e *NoFormatError) Error() string
type Option ¶
type Option func(*config)
Option tweaks the Client at construction.
func WithBaseURL ¶
WithBaseURL overrides the default API host. Useful for staging, self-hosted deployments, or pointing at a local Go server in dev.
func WithHTTPClient ¶
WithHTTPClient lets the caller supply a custom *http.Client (custom transport, retries, instrumentation, etc.).
type Progress ¶
type Progress struct {
Phase string // "resolving" | "fetching" | "muxing" | "finalizing" | "done"
VideoBytes int64
AudioBytes int64
VideoTotal int64
AudioTotal int64
}
Progress reports state during a Download call.
type Resolution ¶
type Resolution struct {
Height int `json:"height"`
QualityLabel string `json:"quality_label"`
SizeMB float64 `json:"size_mb"`
IsProgressive bool `json:"is_progressive"`
DownloadToken string `json:"download_token"`
Endpoint string `json:"endpoint"`
Filename string `json:"filename"`
VideoOnly []VideoFormat `json:"video_only,omitempty"`
}
Resolution is one available video height with its codec options.
type SplitTokenResult ¶
type SplitTokenResult struct {
VideoToken string `json:"video_token"`
AudioToken string `json:"audio_token"`
}
SplitTokenResult is what /v1/split_token returns for a merge token.
type SubtitleTrack ¶
type SubtitleTrack struct {
Code string `json:"code"`
Name string `json:"name"`
IsAuto bool `json:"is_auto"`
DownloadToken string `json:"download_token"`
Filename string `json:"filename"`
}
SubtitleTrack is one caption track (manual or auto-generated).
type VidPickr ¶
type VidPickr struct {
// contains filtered or unexported fields
}
VidPickr is the high-level SDK. Construct one, call Download per URL.
func New ¶
New constructs a VidPickr backed by a low-level Client. Pass Option values (WithBaseURL, WithHTTPClient) to tune transport behaviour.
type VideoFormat ¶
type VideoFormat struct {
Ext string `json:"ext"`
VCodec string `json:"vcodec"`
SizeMB float64 `json:"size_mb"`
DownloadToken string `json:"download_token"`
Bitrate int `json:"bitrate"`
}
VideoFormat is one codec variant at a given resolution height.
type VideoInfo ¶
type VideoInfo struct {
Title string `json:"title"`
Thumbnail string `json:"thumbnail"`
Platform string `json:"platform"`
DurationSec int `json:"duration_sec"`
Resolutions []Resolution `json:"resolutions"`
AudioOnly []AudioFormat `json:"audio_only"`
Subtitles []SubtitleTrack `json:"subtitles"`
}
VideoInfo is the full /v1/info response shape.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vidpickr
command
vidpickr CLI — wraps the Go SDK as a single-binary command.
|
vidpickr CLI — wraps the Go SDK as a single-binary command. |
|
examples
|
|
|
basic
command
Basic example.
|
Basic example. |
|
internal
|
|
|
mp4mux
Package mp4mux performs the local "join video.mp4 + audio.m4a into out.mp4" step using a pure-Go MP4 box rewrite.
|
Package mp4mux performs the local "join video.mp4 + audio.m4a into out.mp4" step using a pure-Go MP4 box rewrite. |