lrstanley/go-ytdlp
关于
yt-dlp cli bindings for Go
开发工具可以做什么
- CLI bindings for yt-dlp -- including all flags/commands.
- Worry less about making sure yt-dlp is installed wherever go-ytdlp is running from!
- Carried over help documentation for all functions/methods.
- Flags with arguments have type mappings according to what the actual flags expect.
实测星标增长
- 24小时
- +1
- 7天
- +2
- 15天
- +2
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文:link: Table of Contents
- Features
- Usage
- Examples
- Install Function(s) & Binary Management
- FlagConfig: JSON to/from Flags Conversion & Usage
- Support & Assistance
- Contributing
- License
:sparkles: Features
- CLI bindings for yt-dlp -- including all flags/commands.
- Optional
Install*helpers to auto-download the latest supported version of yt-dlp, ffmpeg, ffprobe and bun, including proper checksum validation for secure downloads (yt-dlp only).- Worry less about making sure yt-dlp is installed wherever go-ytdlp is running from!
- Carried over help documentation for all functions/methods.
- Flags with arguments have type mappings according to what the actual flags expect.
- Completely generated, ensuring it's easy to update to future yt-dlp versions.
- Deprecated flags are marked as deprecated in a way that should be caught by most IDEs/linters.
- Stdout/Stderr parsing, with timestamps, and optional JSON post-processing.
:sparkles: Help Documentation Example

:gear: Usage
go get -u github.com/lrstanley/go-ytdlp@latest
:clap: Examples
Simple
See also _examples/simple/main.go, which includes writing results (stdout/stderr/etc) as JSON.
package main
import (
"context"
"github.com/lrstanley/go-ytdlp"
)
func main() {
// If yt-dlp isn't installed yet, download and cache it for further use.
ytdlp.MustInstall(context.TODO(), nil)
dl := ytdlp.New().
FormatSort("res,ext:mp4:m4a").
RecodeVideo("mp4").
Output("%(extractor)s - %(title)s.%(ext)s")
_, err := dl.Run(context.TODO(), "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
if err != nil {
panic(err)
}
}
Untrusted input
Command.Run, Command.BuildCommand and Command.ExtractInfo always pass URLs to yt-dlp after
-- (end of options), so a URL like --exec=... is treated as a URL, not a flag. This makes it safe
to pass user-provided URLs, and also allows video IDs which start with -.
Command.RunRaw and Command.BuildCommandRaw pass arguments as-is, which is useful for flags that
don't have a builder method yet. Never pass untrusted input to them, as yt-dlp flags like --exec
can run arbitrary commands.
The same applies to flags set from untrusted input (e.g. FlagConfig JSON in an HTTP API). Use
FlagConfig.ValidateUntrusted instead of FlagConfig.Validate to also reject flags which are known
to be unsafe, such as flags which run commands, load config files or plugins, read or write arbitrary
files, or redirect network traffic. This is a best-effort deny-list, which may not cover flags added
in newer yt-dlp versions, so prefer only accepting an allow-listed set of flags where possible.
Environment variables (Command.SetEnvVar) should never be set from untrusted input.
Fancy UI using BubbleTea
This example shows how to use go-ytdlp and BubbleTea to create a fancy, though relatively simple, UI for downloading videos.

Source: bubble-dl
:package: Install Function(s) & Binary Management
The Install* function helpers in go-ytdlp allow you to automatically download and cache the
required binaries (yt-dlp, ffmpeg, ffprobe and bun) for your platform. This makes it easy to get
started without manually installing these dependencies, and ensures the correct versions are used.
Note: Download/installation of
ffmpeg,ffprobeandbunis only supported on a handful of platforms. It is still recommended to install them via other means if your platform is not listed below.
yt-dlp
| OS/Arch | Download Source |
|---|---|
| darwin_amd64 | https://github.com/yt-dlp/yt-dlp |
| darwin_arm64 | https://github.com/yt-dlp/yt-dlp |
| linux_amd64 | https://github.com/yt-dlp/yt-dlp |
| linux_arm64 | https://github.com/yt-dlp/yt-dlp |
| linux_armv7l | https://github.com/yt-dlp/yt-dlp |
| windows_amd64 | https://github.com/yt-dlp/yt-dlp |
ffmpeg & ffprobe
| OS/Arch | ffmpeg/ffprobe Download Source |
|---|---|
| darwin_amd64 | https://evermeet.cx/ffmpeg/ |
| darwin_arm64 | https://www.osxexperts.net/ |
| linux_amd64 | https://github.com/BtbN/FFmpeg-Builds/ |
| linux_arm64 | https://github.com/BtbN/FFmpeg-Builds/ |
| windows_amd64 | https://github.com/BtbN/FFmpeg-Builds/ |
| windows_arm | https://github.com/BtbN/FFmpeg-Builds/ |
bun
| OS/Arch | bun Download Source |
|---|---|
| darwin_amd64 | https://github.com/oven-sh/bun |
| darwin_arm64 | https://github.com/oven-sh/bun |
| linux_amd64 | https://github.com/oven-sh/bun |
| linux_arm64 | https://github.com/oven-sh/bun |
| windows_amd64 | https://github.com/oven-sh/bun |
Using a different JS runtime
Multiple JavaScript runtimes are supported by yt-dlp, in the same way that yt-dlp itself handles
multiple runtimes. However, when using [Must]InstallAll (or [Must]InstallBun), it will automatically
enable Bun by default (and explicitly disable other runtimes). yt-dlp prefers
Deno over Bun, however, Deno still doesn't support musl-based linux distros (like
Alpine Linux uses) yet.
Refer to the official documentation for more information.
FlagConfig: JSON to/from Flags Conversion & Usage
The FlagConfig type in go-ytdlp enables conversion between JSON and yt-dlp command-line flags.
This is useful for scenarios such as HTTP APIs, web UIs, or persisting flag configurations in a database.
- Bidirectional Conversion: Easily marshal and unmarshal yt-dlp flags to and from JSON. Use
Command.SetFlagConfigandCommand.GetFlagConfigto set/get the flag config. - Validation: Use the provided validation functions and JSON schema to ensure correctness. The JSON body allows duplicate flags (unless using the provided json schema), so always validate before use.
- Compatible Decoding: When loading persisted or client-supplied configurations that may use
older flag names or value types, call
FlagConfig.UnmarshalJSONWithWarningsfirst. Review or log its warnings, then callFlagConfig.Validate; valid flags are retained even when other members are unknown or incompatible. Use ordinaryjson.Unmarshalwhen strict decoding is required. - JSON Schema: The schema (available via the
optiondata.JSONSchemavariable and also located here) can be used for type generation in other languages (e.g. TypeScript) and for client-side validation (e.g. using something like json-schema-to-zod when working with a web UI). - Persistence: If storing flag configs in a database, note that yt-dlp flags can change or be removed
at any time (in correlation to updates of go-ytdlp). Use compatibility decoding and handle its
warnings before validating after loading from storage.
- If validation fails, clear the invalid values in the JSON before retrying (e.g. using the
ErrMultipleJSONParsingFlagsandErrJSONParsingFlagerror types, which include the path in the JSON where the issue occurred).
- If validation fails, clear the invalid values in the JSON before retrying (e.g. using the
- SupportedExtractors: If persisting the values from this generated type, remember that extractors
can be changed or removed by yt-dlp at any time (in correlation to updates of go-ytdlp). If a
user requests a retry and the extractor is missing, consider defaulting to
genericor another fallback. - Intended Usage:
FlagConfigis designed for JSON marshalling/unmarshalling only. It is not intended for direct use in Go code unless you are building HTTP servers, persisting configs, or similar use cases. The builder pattern should be used in all other cases.
Example: HTTP Server which Invokes go-ytdlp
You can find an example of how to use the FlagConfig type for HTTP server integration in the
_examples/http-server directory.
:raising_hand_man: Support & Assistance
- :heart: Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
- :raising_hand_man: Take a look at the support document on guidelines for tips on how to ask the right questions.
- :lady_beetle: For all features/bugs/issues/questions/etc, head over here.
:handshake: Contributing
- :heart: Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
- :clipboard: Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
- :old_key: For anything security related, please review this repositories security policy.
:balance_scale: License
MIT License
Copyright (c) 2023 Liam Stanley <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Also located here
探索相关项目
加载中…