ytdl

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2015 License: MIT Imports: 13 Imported by: 0

README

ytdl Build Status GoDoc


Go library for downloading YouTube videos

Documentation: https://godoc.org/github.com/otium/ytdl

Example

import (
   "github.com/otium/ytdl"
   "os"
)

vid, err := ytdl.GetVideoInfo("https://www.youtube.com/watch?v=1rZ-JorHJEY")
file, _ = os.Create(vid.Title + ".mp4")
defer file.Close()
vid.Download(file)

ytdl CLI

To install: go get -u github.com/otium/ytdl/...

Usage

ytdl [global options] [youtube url or video id]

Options
  • --help, -h - show help
  • --filter, -f - Filter out formats
    • Syntax: key:value1,value2,...,valueN
    • To exclude: !key:value1,...
    • Available keys (See format.go for available values):
      • ext - extension of video
      • res - resolution of video
      • videnc - video encoding
      • audenc - audio encoding
      • prof - youtube video profile
    • Default filters
      • ext:mp4
      • res:1080p,720p,480p,360p,240p,144p
      • !videnc:nil
      • !audenc:nil
  • --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
  • --no-progress - Disables the progress bar
  • --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

License

ytdl is released under the MIT License, see LICENSE for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FORMATS = map[int]Format{
	5: Format{
		Extension:     "flv",
		Resolution:    "240p",
		VideoEncoding: "Sorenson H.283",
		AudioEncoding: "mp3",
		Itag:          5,
	},
	6: Format{
		Extension:     "flv",
		Resolution:    "270p",
		VideoEncoding: "Sorenson H.263",
		AudioEncoding: "mp3",
		Itag:          6,
	},
	13: Format{
		Extension:     "3gp",
		Resolution:    "",
		VideoEncoding: "MPEG-4 Visual",
		AudioEncoding: "aac",
		Itag:          13,
	},
	17: Format{
		Extension:     "3gp",
		Resolution:    "144p",
		VideoEncoding: "MPEG-4 Visual",
		AudioEncoding: "aac",
		Itag:          17,
	},
	18: Format{
		Extension:     "mp4",
		Resolution:    "360p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          18,
	},
	22: Format{
		Extension:     "mp4",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          22,
	},
	34: Format{
		Extension:     "flv",
		Resolution:    "480p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          34,
	},
	35: Format{
		Extension:     "flv",
		Resolution:    "360p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          35,
	},
	36: Format{
		Extension:     "3gp",
		Resolution:    "240p",
		VideoEncoding: "MPEG-4 Visual",
		AudioEncoding: "aac",
		Itag:          36,
	},
	37: Format{
		Extension:     "mp4",
		Resolution:    "1080p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          37,
	},
	38: Format{
		Extension:     "mp4",
		Resolution:    "3072p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          38,
	},
	43: Format{
		Extension:     "webm",
		Resolution:    "360p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          43,
	},
	44: Format{
		Extension:     "webm",
		Resolution:    "480p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          44,
	},
	45: Format{
		Extension:     "webm",
		Resolution:    "720p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          45,
	},
	46: Format{
		Extension:     "webm",
		Resolution:    "1080p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          46,
	},
	82: Format{
		Extension:     "mp4",
		Resolution:    "360p",
		VideoEncoding: "H.264",
		Itag:          82,
	},
	83: Format{
		Extension:     "mp4",
		Resolution:    "240p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          83,
	},
	84: Format{
		Extension:     "mp4",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          84,
	},
	85: Format{
		Extension:     "mp4",
		Resolution:    "1080p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          85,
	},
	100: Format{
		Extension:     "webm",
		Resolution:    "360p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          100,
	},
	101: Format{
		Extension:     "webm",
		Resolution:    "360p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          101,
	},
	102: Format{
		Extension:     "webm",
		Resolution:    "720p",
		VideoEncoding: "VP8",
		AudioEncoding: "vorbis",
		Itag:          102,
	},

	133: Format{
		Extension:     "mp4",
		Resolution:    "240p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          133,
	},
	134: Format{
		Extension:     "mp4",
		Resolution:    "360p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          134,
	},
	135: Format{
		Extension:     "mp4",
		Resolution:    "480p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          135,
	},
	136: Format{
		Extension:     "mp4",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          136,
	},
	137: Format{
		Extension:     "mp4",
		Resolution:    "1080p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          137,
	},
	138: Format{
		Extension:     "mp4",
		Resolution:    "2160p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          138,
	},
	160: Format{
		Extension:     "mp4",
		Resolution:    "144p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          160,
	},
	242: Format{
		Extension:     "webm",
		Resolution:    "240p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          242,
	},
	243: Format{
		Extension:     "webm",
		Resolution:    "360p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          243,
	},
	244: Format{
		Extension:     "webm",
		Resolution:    "480p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          244,
	},
	247: Format{
		Extension:     "webm",
		Resolution:    "720p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          247,
	},
	248: Format{
		Extension:     "webm",
		Resolution:    "1080p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          248,
	},
	264: Format{
		Extension:     "mp4",
		Resolution:    "1440p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          264,
	},
	266: Format{
		Extension:     "mp4",
		Resolution:    "2160p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          266,
	},
	271: Format{
		Extension:     "webm",
		Resolution:    "1440p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          271,
	},
	272: Format{
		Extension:     "webm",
		Resolution:    "2160p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          272,
	},
	278: Format{
		Extension:     "webm",
		Resolution:    "144p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          278,
	},
	298: Format{
		Extension:     "mp4",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          298,
	},
	299: Format{
		Extension:     "mp4",
		Resolution:    "1080p",
		VideoEncoding: "H.264",
		AudioEncoding: "",
		Itag:          299,
	},
	302: Format{
		Extension:     "webm",
		Resolution:    "720p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          302,
	},
	303: Format{
		Extension:     "webm",
		Resolution:    "1080p",
		VideoEncoding: "VP9",
		AudioEncoding: "",
		Itag:          303,
	},

	139: Format{
		Extension:     "mp4",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "aac",
		Itag:          139,
	},
	140: Format{
		Extension:     "mp4",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "aac",
		Itag:          140,
	},
	141: Format{
		Extension:     "mp4",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "aac",
		Itag:          141,
	},
	171: Format{
		Extension:     "webm",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "vorbis",
		Itag:          171,
	},
	172: Format{
		Extension:     "webm",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "vorbis",
		Itag:          172,
	},
	249: Format{
		Extension:     "webm",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "opus",
		Itag:          249,
	},
	250: Format{
		Extension:     "webm",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "opus",
		Itag:          250,
	},
	251: Format{
		Extension:     "webm",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "opus",
		Itag:          251,
	},

	92: Format{
		Extension:     "ts",
		Resolution:    "240p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          92,
	},
	93: Format{
		Extension:     "ts",
		Resolution:    "480p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          93,
	},
	94: Format{
		Extension:     "ts",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          94,
	},
	95: Format{
		Extension:     "ts",
		Resolution:    "1080p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          95,
	},
	96: Format{
		Extension:     "ts",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          96,
	},
	120: Format{
		Extension:     "flv",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          120,
	},
	127: Format{
		Extension:     "ts",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "aac",
		Itag:          127,
	},
	128: Format{
		Extension:     "ts",
		Resolution:    "",
		VideoEncoding: "",
		AudioEncoding: "aac",
		Itag:          128,
	},
	132: Format{
		Extension:     "ts",
		Resolution:    "240p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          132,
	},
	151: Format{
		Extension:     "ts",
		Resolution:    "720p",
		VideoEncoding: "H.264",
		AudioEncoding: "aac",
		Itag:          151,
	},
}

FORMATS is a map of all itags and their formats

Functions

This section is empty.

Types

type Format

type Format struct {
	Itag          int    `json:"itag"`
	Extension     string `json: "extension"`
	Resolution    string `json: "resolution"`
	VideoEncoding string `json: "videoEncoding"`
	AudioEncoding string `json: "audioEncoding"`
	// contains filtered or unexported fields
}

func FilterFormats

func FilterFormats(formats []Format, key FormatKey, values []string) []Format

FilterFormats filters out all formats whose key doesn't contain any of values. Formats are ordered by values

func FilterFormatsExclude

func FilterFormatsExclude(formats []Format, key FormatKey, values []string) []Format

FilterFormatsExclude excludes all formats whose passed key contains any of the passed values

func FilterFormatsExtremes added in v0.4.0

func FilterFormatsExtremes(formats []Format, key FormatKey, high bool) Format

func (Format) ValueForKey added in v0.4.0

func (f Format) ValueForKey(key FormatKey) interface{}

type FormatKey

type FormatKey string

FormatKey is a string type containg a key in a video format map

const (
	FormatExtensionKey     FormatKey = "ext"
	FormatResolutionKey    FormatKey = "res"
	FormatVideoEncodingKey FormatKey = "videnc"
	FormatAudioEncodingKey FormatKey = "audenc"
	FormatItagKey          FormatKey = "itag"
)

Available format Keys

type ThumbnailQuality

type ThumbnailQuality string

ThumbnailQuality is a youtube thumbnail quality option

const ThumbnailQualityDefault ThumbnailQuality = "default"

ThumbnailQualityDefault is the default quality thumbnail jpg

const ThumbnailQualityHigh ThumbnailQuality = "hqdefault"

ThumbnailQualityHigh is the high quality thumbnail jpg

const ThumbnailQualityMaxRes ThumbnailQuality = "maxresdefault"

ThumbnailQualityMaxRes is the maximum resolution quality jpg

const ThumbnailQualityMedium ThumbnailQuality = "mqdefault"

ThumbnailQualityMedium is the medium quality thumbnail jpg

const ThumbnailQualitySD ThumbnailQuality = "sddefault"

ThumbnailQualitySD is the standard def quality thumbnail jpg

type VideoInfo added in v0.3.0

type VideoInfo struct {
	// The video ID
	ID string `json:"id"`
	// The video title
	Title string `json:"title"`
	// The video description
	Description string `json:"description"`
	// The date the video was published
	DatePublished time.Time `json:"datePublished"`
	// Formats the video is available in
	Formats []Format `json:"formats"`
	// List of keywords associated with the video
	Keywords []string `json:"keywords"`
	// Author of the video
	Author string `json:"author"`
	// Duration of the video
	Duration time.Duration
	// contains filtered or unexported fields
}

VideoInfo contains the info a youtube video

func GetVideoInfo added in v0.3.0

func GetVideoInfo(value interface{}) (*VideoInfo, error)

GetVideoInfo fetches info from a url string, url object, or a url string

func GetVideoInfoFromID added in v0.3.0

func GetVideoInfoFromID(id string) (*VideoInfo, error)

GetVideoInfoFromID fetches video info from a youtube video id

func GetVideoInfoFromURL added in v0.3.0

func GetVideoInfoFromURL(u *url.URL) (*VideoInfo, error)

GetVideoInfoFromURL fetches video info from a youtube url

func (*VideoInfo) Download added in v0.3.0

func (info *VideoInfo) Download(format Format, dest io.Writer) error

Download is a convenience method to download a format to an io.Writer

func (*VideoInfo) GetDownloadURL added in v0.3.0

func (info *VideoInfo) GetDownloadURL(format Format) (*url.URL, error)

GetDownloadURL gets the download url for a format

func (*VideoInfo) GetThumbnailURL added in v0.3.0

func (info *VideoInfo) GetThumbnailURL(quality ThumbnailQuality) *url.URL

GetThumbnailURL returns a url for the thumbnail image with the given quality

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL