ytdl

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 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: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "Sorenson H.283",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "mp3",
		FormatItagKey:          5,
	},
	6: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "270p",
		FormatVideoEncodingKey: "Sorenson H.263",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "mp3",
		FormatItagKey:          6,
	},
	13: {
		FormatExtensionKey:     "3gp",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: "MPEG-4 Visual",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          13,
	},
	17: {
		FormatExtensionKey:     "3gp",
		FormatResolutionKey:    "144p",
		FormatVideoEncodingKey: "MPEG-4 Visual",
		FormatAudioEncodingKey: "aac",
		FormatProfileKey:       nil,
		FormatItagKey:          17,
	},
	18: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "baseline",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          18,
	},
	22: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          22,
	},
	34: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          34,
	},
	35: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          35,
	},
	36: {
		FormatExtensionKey:     "3gp",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "MPEG-4 Visual",
		FormatProfileKey:       "simple",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          36,
	},
	37: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          37,
	},
	38: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "3072p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          38,
	},
	43: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          43,
	},
	44: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          44,
	},
	45: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          45,
	},
	46: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          46,
	},
	82: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatItagKey:          82,
	},
	83: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          83,
	},
	84: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          84,
	},
	85: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          85,
	},
	100: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          100,
	},
	101: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          101,
	},
	102: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          102,
	},

	133: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          133,
	},
	134: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          134,
	},
	135: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          135,
	},
	136: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          136,
	},
	137: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          137,
	},
	138: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "2160p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          138,
	},
	160: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "144p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          160,
	},
	242: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          242,
	},
	243: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          243,
	},
	244: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          244,
	},
	247: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          247,
	},
	248: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          248,
	},
	264: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1440p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          264,
	},
	266: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "2160p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          266,
	},
	271: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "1440p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          271,
	},
	272: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "2160p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          272,
	},
	278: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "144p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          278,
	},
	298: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          298,
	},
	299: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: nil,
		FormatItagKey:          299,
	},
	302: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          302,
	},
	303: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "VP9",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: nil,
		FormatItagKey:          303,
	},

	139: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          139,
	},
	140: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          140,
	},
	141: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          141,
	},
	171: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          171,
	},
	172: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
		FormatItagKey:          172,
	},
	249: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "opus",
		FormatItagKey:          249,
	},
	250: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "opus",
		FormatItagKey:          250,
	},
	251: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "opus",
		FormatItagKey:          251,
	},

	92: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          92,
	},
	93: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          93,
	},
	94: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          94,
	},
	95: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          95,
	},
	96: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          96,
	},
	120: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "Main@L3.1",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          120,
	},
	127: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          127,
	},
	128: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: nil,
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          128,
	},
	132: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "baseline",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          132,
	},
	151: {
		FormatExtensionKey:     "ts",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "baseline",
		FormatAudioEncodingKey: "aac",
		FormatItagKey:          151,
	},
}

FORMATS is a map of all itags and their formats

Functions

This section is empty.

Types

type Format

type Format map[FormatKey]interface{}

Format is a map type for formats

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

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"
	FormatProfileKey       FormatKey = "prof"
	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