ytdl

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 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"
)

info, err := ytdl.GetInfo("https://www.youtube.com/watch?v=1rZ-JorHJEY")
file, _ = os.Create(info.Title + ".mp4")
defer file.Close()
info.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 - just print download url to, don't do anything else
  • --verion, -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",
	},
	6: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "270p",
		FormatVideoEncodingKey: "Sorenson H.263",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "mp3",
	},
	13: {
		FormatExtensionKey:     "3gp",
		FormatResolutionKey:    nil,
		FormatVideoEncodingKey: "MPEG-4 Visual",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "aac",
	},
	17: {
		FormatExtensionKey:     "3gp",
		FormatResolutionKey:    "144p",
		FormatVideoEncodingKey: "MPEG-4 Visual",
		FormatAudioEncodingKey: "aac",
		FormatProfileKey:       nil,
	},
	18: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "baseline",
		FormatAudioEncodingKey: "aac",
	},
	22: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: "aac",
	},
	34: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
	},
	35: {
		FormatExtensionKey:     "flv",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "main",
		FormatAudioEncodingKey: "aac",
	},
	36: {
		FormatExtensionKey:     "3gp",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "MPEG-4 Visual",
		FormatProfileKey:       "simple",
		FormatAudioEncodingKey: "aac",
	},
	37: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: "aac",
	},
	38: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "3072p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "high",
		FormatAudioEncodingKey: "aac",
	},
	43: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
	},
	44: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "480p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
	},
	45: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
	},
	46: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       nil,
		FormatAudioEncodingKey: "vorbis",
	},
	82: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
	},
	83: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "240p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "aac",
	},
	84: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "aac",
	},
	85: {
		FormatExtensionKey:     "mp4",
		FormatResolutionKey:    "1080p",
		FormatVideoEncodingKey: "H.264",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "aac",
	},
	100: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "vorbis",
	},
	101: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "360p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "vorbis",
	},
	102: {
		FormatExtensionKey:     "webm",
		FormatResolutionKey:    "720p",
		FormatVideoEncodingKey: "VP8",
		FormatProfileKey:       "3d",
		FormatAudioEncodingKey: "vorbis",
	},

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

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

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

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"
)

Available format Keys

type Info

type Info 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
}

Info contains the info a youtube video

func GetInfo

func GetInfo(value interface{}) (*Info, error)

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

func GetInfoFromID

func GetInfoFromID(id string) (*Info, error)

GetInfoFromID fetches video info from a youtube video id

func GetInfoFromURL

func GetInfoFromURL(u *url.URL) (*Info, error)

GetInfoFromURL fetches video info from a youtube url

func (*Info) Download

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

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

func (*Info) GetDownloadURL

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

GetDownloadURL gets the download url for a format

func (*Info) GetThumbnailURL

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

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

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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