# README
ytdl
Go library for downloading YouTube videos
Example
package main
import (
"context"
"os"
"github.com/rylio/ytdl"
)
func main() {
ctx := context.Background()
client := ytdl.DefaultClient
videoInfo, err := client.GetVideoInfo(ctx, "https://www.youtube.com/watch?v=WkVvG4QTO9M")
if err != nil {
panic(err)
}
file, err := os.Create(videoInfo.Title + ".mp4")
if err != nil {
panic(err)
}
defer file.Close()
err = client.Download(ctx, videoInfo, videoInfo.Formats[0], file)
if err != nil {
panic(err)
}
}
ytdl CLI
-
To install:
go get -u github.com/rylio/ytdl/...
-
Or use Docker image
docker pull brucewangno1/ytdl:1.0
Usage
ytdl [global options] [youtube url or video id]
- Or using Docker:
docker run -it --rm -v /directory/you/want/to/save/the/download/:/ytdl/ brucewangno1/ytdl:1.0 [global options] "[youtube url or video id]"
Options
--help, -h
- show help--filter, -f
- Filter out formats- Syntax:
-f key:value1,value2,...,valueN
- Shortcuts for best/worst(e.g.
-f best
)best
/worst
- best/worst video and audiobest-video
/worst-video
- best/worst videobest-fps
/worst-fps
- best/worst video with fps as the first prioritybest-audio
/worst-audio
- best/worst audio
- Shortcuts for best/worst(e.g.
- To exclude: -f !key:value1,...
- Available keys (See format.go for available values):
ext
- extension of videores
- resolution of videovidenc
- video encodingaudenc
- audio encodingprof
- youtube video profileaudbr
- audio bitrate
- Default filters
ext:mp4
!videnc:
!audenc:
best
- Syntax:
--output, -o
- Output to specific path- Supports templates, ex: {{.Title}}.{{.Ext}}
- Defaults to
{{.Title}}.{{.Ext}}
- Supported template variables are Title, Ext, DatePublished, Resolution
- Pass - to output to stdout, former stdout output is redirected to stderr
--info, -i
- Just gets video info, outputs to stdout--silent, -s
- Disables all output, except for fatal errors--debug, -d
- Output debug logs--append, -a
- append to output file, instead of truncating--range, -r
- specify a range of bytes, placed in http range header, ex: 0-100--download-url, -u
- just print download url to, don't do anything else--version, -v
- print out ytdl cli version--start-offset
- offset the beginning of the video by a duration of time(e.g. 20s or 1m)--download-option, -p
- Print video and audio download options and accept input interactively
Examples
Download content based on itag
ytdl -f itag:22 'https://www.youtube.com/watch?v=9bZkp7q19f0'
Download content with the best fps
ytdl -f best-fps 'https://www.youtube.com/watch?v=9bZkp7q19f0'
Get all download formats (Requires jq to be installed)
./ytdl -j 'http://youtube.com/watch?v=9bZkp7q19f0' | jq ".formats"
Extract title of the video (Requires jq to be installed)
ytdl -j 'http://youtube.com/watch?v=9bZkp7q19f0' | jq ".title"
Print download url without downloading the content
ytdl -f itag:22 --download-url 'https://www.youtube.com/watch?v=9bZkp7q19f0'
Print video and audio download options and accept input interactively
ytdl -p 'https://www.youtube.com/watch?v=9bZkp7q19f0'
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
ytdl is released under the MIT License, see LICENSE for more details.
# Functions
GetVideoInfo fetches info from a url string, url object, or a url string.
# Constants
Available format Keys.
Available format Keys.
Available format Keys.
Available format Keys.
Available format Keys.
Available format Keys.
Available format Keys.
ThumbnailQualityDefault is the default quality thumbnail jpg.
ThumbnailQualityHigh is the high quality thumbnail jpg.
ThumbnailQualityMaxRes is the maximum resolution quality jpg.
ThumbnailQualityMedium is the medium quality thumbnail jpg.
ThumbnailQualitySD is the standard def quality thumbnail jpg.
# Type aliases
FormatKey is a string type containing a key in a video format map.
FormatList is a slice of formats with filtering functionality.
ThumbnailQuality is a youtube thumbnail quality option.