- Features
- Usage
- Examples
- Install Function(s) & Binary Management
- FlagConfig: JSON to/from Flags Conversion & Usage
- Support & Assistance
- Contributing
- License
- CLI bindings for yt-dlp -- including all flags/commands.
- Optional
Install*
helpers to auto-download the latest supported version of yt-dlp, ffmpeg and ffprobe, 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.
go get -u github.com/lrstanley/go-ytdlp@latest
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)
}
}
This example shows how to use go-ytdlp and BubbleTea to create a fancy, though relatively simple, UI for downloading videos.
Source: bubble-dl
The Install*
function helpers in go-ytdlp allow you to automatically download and cache the
required binaries (yt-dlp
, ffmpeg
, and ffprobe
) 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
andffprobe
is only supported on a handful of platforms. It is still recommended to install them via other means if your platform is not listed below.
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 |
OS/Arch | ffmpeg/ffprobe Download Source |
---|---|
darwin_amd64 | https://evermeet.cx/ffmpeg/ |
linux_amd64 | https://github.com/yt-dlp/FFmpeg-Builds |
linux_arm64 | https://github.com/yt-dlp/FFmpeg-Builds |
windows_amd64 | https://github.com/yt-dlp/FFmpeg-Builds |
windows_arm | https://github.com/yt-dlp/FFmpeg-Builds |
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.SetFlagConfig
andCommand.GetFlagConfig
to 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.
- JSON Schema: The schema (available via the
optiondata.JSONSchema
variable 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). Always validate after loading from storage.
- If validation fails, clear the invalid values in the JSON before retrying (e.g. using the
ErrMultipleJSONParsingFlags
andErrJSONParsingFlag
error 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
generic
or another fallback. - Intended Usage:
FlagConfig
is 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.
You can find an example of how to use the FlagConfig
type for HTTP server integration in the
_examples/http-server
directory.
- β€οΈ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
- πββοΈ Take a look at the support document on guidelines for tips on how to ask the right questions.
- π For all features/bugs/issues/questions/etc, head over here.
- β€οΈ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
- π Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
- ποΈ For anything security related, please review this repositories security policy.
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