youtubedlwrapper

package module
v0.0.0-...-05be5ee Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: MIT Imports: 6 Imported by: 0

README

Project currently in alpha state, public API not guaranteed to stay the same across minor/patch versions

Youtube-DL Wrapper

Drone Build Status Go Reference Go Report Card

Type-safe Go (golang) wrapper for youtube-dl, to access youtube-dl without having to worry about directly interacting with youtube-dl using os/exec yourself

Installation

youtube-dl

Note this project uses youtube-dl using exec, so it needs to know how to access and where youtube-dl is. as there are many ways to install youtube-dl, look up instructions for your specific distro/operating system

youtubedlwrapper

Run

go get github.com/SomethingBot/youtubedlwrapper

Code Quick Start

Simple CLI application that uses youtubedlwrapper to grab a video's Metadata

package main

import (
	"flag"
	"fmt"
	"github.com/SomethingBot/youtubedlwrapper"
)

func main() {
	url := flag.String("url", "", "URL of youtube video")
	flag.Parse()
	if *url == "" {
		flag.PrintDefaults()
		return
	}
	wrapper, err := youtubedlwrapper.New(youtubedlwrapper.WrapperOptions{YoutubeDLBinary: "youtube-dl"})
	if err != nil {
		fmt.Printf("Could not setup youtubedlwrapper, error (%v).\n", err)
		return
	}
	metadata, err := wrapper.GetVideoMetadata(*url)
	if err != nil {
		fmt.Printf("Could not get video metadata, error (%v)\n", err)
		return
	}
	fmt.Printf("ID (%v), Title (%v), Views (%v), Uploader (%v)\n", metadata.ID, metadata.Title, metadata.ViewCount, metadata.Uploader)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoYoutubeDLOutput = fmt.Errorf("youtubedlwrapper: youtube-dl returned no output")

Functions

This section is empty.

Types

type AutomaticCaption

type AutomaticCaption struct {
	Ext string `json:"ext"`
	URL string `json:"url"`
}

type Chapter

type Chapter struct {
	StartTime int    `json:"start_time"`
	EndTime   int    `json:"end_time"`
	Title     string `json:"title"`
}

type DownloaderOptions

type DownloaderOptions struct {
	HTTPChunkSize int `json:"http_chunk_size"`
}

type Format

type Format struct {
	FormatID          string            `json:"format_id"`
	ManifestURL       string            `json:"manifest_url,omitempty"`
	Ext               string            `json:"ext"`
	Width             int               `json:"width"`
	Height            int               `json:"height"`
	Tbr               float64           `json:"tbr"`
	Asr               int               `json:"asr"`
	Fps               int               `json:"fps"`
	Language          string            `json:"language,omitempty"`
	FormatNote        string            `json:"format_note"`
	Filesize          int               `json:"filesize"`
	Container         string            `json:"container,omitempty"`
	Vcodec            string            `json:"vcodec"`
	Acodec            string            `json:"acodec"`
	URL               string            `json:"url"`
	FragmentBaseURL   string            `json:"fragment_base_url,omitempty"`
	Fragments         []Fragment        `json:"fragments,omitempty"`
	Protocol          string            `json:"protocol"`
	Format            string            `json:"format"`
	HTTPHeaders       HTTPHeaders       `json:"http_headers"`
	Quality           int               `json:"quality,omitempty"`
	Abr               float64           `json:"abr,omitempty"`
	DownloaderOptions DownloaderOptions `json:"downloader_options,omitempty"`
	Vbr               float64           `json:"vbr,omitempty"`
}

type Fragment

type Fragment struct {
	Path     string  `json:"path"`
	Duration float64 `json:"duration,omitempty"`
}

type HTTPHeaders

type HTTPHeaders struct {
	UserAgent      string `json:"User-Agent"`
	AcceptCharset  string `json:"Accept-Charset"`
	Accept         string `json:"Accept"`
	AcceptEncoding string `json:"Accept-Encoding"`
	AcceptLanguage string `json:"Accept-Language"`
}

type Options

type Options struct {
	Username      string
	Password      string
	Videopassword string
	Ap_mso        string
	Ap_password   string
	Usenetrc      bool
	//verbose
	//quiet
	//no_warnings
	//forceurl
	//forcetitle
	//forceid
	//forcethumbnail
	//forcedescription
	//forcefilename
	//forceduration
	//forcejson
	//Dump_single_json bool
	Simulate                bool
	Format                  string
	Outtmpl                 string
	Restrictfilenames       bool
	Ignoreerrors            bool
	Force_generic_extractor bool
	Nooverwrites            bool
	Playliststart           int
	Playlistend             int
	Playlist_items          []int
	Playlistreverse         bool
	Playlistrandom          bool
	Matchtitle              bool
	Rejecttitle             bool
	//logger
	//logtostderr
	Writedesription        bool
	Writeinfojson          bool
	Writeannotations       bool
	Writethumbnail         bool
	Write_all_thumbnails   bool
	Writesubtitles         bool
	Writeautomaticsub      bool
	Allsubtitles           bool
	Listsubtitles          bool
	Subtitlesformat        string
	Subtitleslangs         []string
	Keepvideo              bool
	Daterange              string
	Skip_download          bool
	Cachedir               string
	Noplaylist             bool
	Age_limit              int
	Min_views              int
	Max_views              int
	Download_archive       string
	Cookiefile             string
	Nocheckcertificate     bool
	Prefer_insecure        bool
	Proxy                  string
	Geo_verification_proxy string
	Socket_timeout         int
	//bidi_workaround
	//debug_printtraffic
	Include_ads    bool
	Default_search string
	Encoding       string
	Extract_flat   bool
	//postprocessors
	//progress_hooks
	Fixup              string
	Source_address     net.Addr
	Call_home          bool
	Sleep_interval     int
	Max_sleep_interval int
	//listformats
	//list_thumbnails
	//match_filter
	//no_color
	Geo_bypass         bool
	Geo_bypass_country string
	//external_downloader
	//hls_prefer_native
	//implement parameters for different downloaders?
	Prefer_ffmpeg                 bool
	Postprocessor_args            []string
	Youtube_include_dash_manifest bool
}

type PlaylistMetadata

type PlaylistMetadata struct {
	Type               string          `json:"_type"`
	Videos             []VideoMetadata `json:"entries"`
	ID                 string          `json:"id"`
	Title              string          `json:"title"`
	Uploader           string          `json:"uploader"`
	UploaderID         string          `json:"uploader_id"`
	UploaderURL        string          `json:"uploader_url"`
	Extractor          string          `json:"extractor"`
	WebpageURL         string          `json:"webpage_url"`
	WebpageURLBasename string          `json:"webpage_url_basename"`
	ExtractorKey       string          `json:"extractor_key"`
}

type Thumbnail

type Thumbnail struct {
	Height     int    `json:"height"`
	URL        string `json:"url"`
	Width      int    `json:"width"`
	Resolution string `json:"resolution"`
	ID         string `json:"id"`
}

type VideoMetadata

type VideoMetadata struct {
	ID                 string                        `json:"id"`
	Title              string                        `json:"title"`
	Formats            []Format                      `json:"formats"`
	Thumbnails         []Thumbnail                   `json:"thumbnails"`
	Description        string                        `json:"description"`
	UploadDate         string                        `json:"upload_date"`
	Uploader           string                        `json:"uploader"`
	UploaderID         string                        `json:"uploader_id"`
	UploaderURL        string                        `json:"uploader_url"`
	ChannelID          string                        `json:"channel_id"`
	ChannelURL         string                        `json:"channel_url"`
	Duration           int                           `json:"duration"`
	ViewCount          int                           `json:"view_count"`
	AverageRating      float64                       `json:"average_rating"`
	AgeLimit           int                           `json:"age_limit"`
	WebpageURL         string                        `json:"webpage_url"`
	Categories         []string                      `json:"categories"`
	Tags               []string                      `json:"tags"`
	IsLive             bool                          `json:"is_live"`
	LikeCount          int                           `json:"like_count"`
	DislikeCount       int                           `json:"dislike_count"`
	Channel            string                        `json:"channel"`
	Track              string                        `json:"track"`
	Artist             string                        `json:"artist,omitempty"`
	Album              string                        `json:"album,omitempty"`
	Creator            string                        `json:"creator,omitempty"`
	AltTitle           string                        `json:"alt_title"`
	Extractor          string                        `json:"extractor"`
	WebpageURLBasename string                        `json:"webpage_url_basename"`
	ExtractorKey       string                        `json:"extractor_key"`
	NEntries           int                           `json:"n_entries"`
	Playlist           string                        `json:"playlist"`
	PlaylistID         string                        `json:"playlist_id"`
	PlaylistTitle      string                        `json:"playlist_title"`
	PlaylistUploader   string                        `json:"playlist_uploader"`
	PlaylistUploaderID string                        `json:"playlist_uploader_id"`
	PlaylistIndex      int                           `json:"playlist_index"`
	Thumbnail          string                        `json:"thumbnail"`
	DisplayID          string                        `json:"display_id"`
	RequestedSubtitles string                        `json:"requested_subtitles"`
	RequestedFormats   []Format                      `json:"requested_formats"`
	Format             string                        `json:"format"`
	FormatID           string                        `json:"format_id"`
	Width              int                           `json:"width"`
	Height             int                           `json:"height"`
	Resolution         string                        `json:"resolution"`
	Fps                int                           `json:"fps"`
	Vcodec             string                        `json:"vcodec"`
	Vbr                float64                       `json:"vbr"`
	StretchedRatio     string                        `json:"stretched_ratio"`
	Acodec             string                        `json:"acodec"`
	Abr                float64                       `json:"abr"`
	Ext                string                        `json:"ext"`
	License            string                        `json:"license"`
	Chapters           []Chapter                     `json:"chapters"`
	AutomaticCaptions  map[string][]AutomaticCaption `json:"automatic_captions,omitempty"`
	Subtitles          map[string]string             `json:"subtitles,omitempty"`
}

type Wrapper

type Wrapper struct {
	// contains filtered or unexported fields
}

func New

func New(wrapperOptions WrapperOptions) (wrapper Wrapper, err error)

New returns a wrapper with specified WrapperOptions set

func (*Wrapper) GetPlaylistMetadata

func (wrapper *Wrapper) GetPlaylistMetadata(url string) (playlistMetadata PlaylistMetadata, err error)

GetPlaylistMetadata using wrapperOptions provided in New

func (*Wrapper) GetVideoMetadata

func (wrapper *Wrapper) GetVideoMetadata(url string) (videoMetadata VideoMetadata, err error)

type WrapperOptions

type WrapperOptions struct {
	YoutubeDLBinary string
	// contains filtered or unexported fields
}

type YoutubeDLError

type YoutubeDLError struct {
	// contains filtered or unexported fields
}

YoutubeDLError is specifically an error returned on stderr by youtube-dl

func (YoutubeDLError) Error

func (youtubeDLError YoutubeDLError) Error() string

Jump to

Keyboard shortcuts

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