youtube

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package youtube implement youtube download package in go.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrCipherNotFound             = errors.New("cipher not found")
	ErrInvalidCharactersInVideoID = errors.New("invalid characters in video id")
	ErrVideoIDMinLength           = errors.New("the video id must be at least 10 characters long")
	ErrReadOnClosedResBody        = errors.New("http: read on closed response body")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// Debug enables debugging output through log package
	Debug bool

	// HTTPClient can be used to set a custom HTTP client.
	// If not set, http.DefaultClient will be used
	HTTPClient *http.Client
}

Client offers methods to download video metadata and video streams.

Example

ExampleDownload : Example code for how to use this package for download video.

videoID := "BaW_jenozKc"
client := youtube.Client{}

video, err := client.GetVideo(videoID)
if err != nil {
	panic(err)
}

resp, err := client.GetStream(video, &video.Formats[0])
if err != nil {
	panic(err)
}
defer resp.Body.Close()

file, err := os.Create("video.mp4")
if err != nil {
	panic(err)
}
defer file.Close()

_, err = io.Copy(file, resp.Body)
if err != nil {
	panic(err)
}
Output:

func (*Client) GetStream

func (c *Client) GetStream(video *Video, format *Format) (*http.Response, error)

GetStream returns the HTTP response for a specific format

func (*Client) GetStreamContext

func (c *Client) GetStreamContext(ctx context.Context, video *Video, format *Format) (*http.Response, error)

GetStreamContext returns the HTTP response for a specific format with a context

func (*Client) GetVideo

func (c *Client) GetVideo(url string) (*Video, error)

GetVideo fetches video metadata

func (*Client) GetVideoContext

func (c *Client) GetVideoContext(ctx context.Context, url string) (*Video, error)

GetVideoContext fetches video metadata with a context

type ErrPlayabiltyStatus

type ErrPlayabiltyStatus struct {
	Status string
	Reason string
}

func (ErrPlayabiltyStatus) Error

func (err ErrPlayabiltyStatus) Error() string

type ErrResponseStatus

type ErrResponseStatus struct {
	Status string
	Reason string
}

func (ErrResponseStatus) Error

func (err ErrResponseStatus) Error() string

type ErrUnexpectedStatusCode

type ErrUnexpectedStatusCode int

ErrUnexpectedStatusCode is returned on unexpected HTTP status codes

func (ErrUnexpectedStatusCode) Error

func (err ErrUnexpectedStatusCode) Error() string

type Format

type Format struct {
	ItagNo           int    `json:"itag"`
	URL              string `json:"url"`
	MimeType         string `json:"mimeType"`
	Quality          string `json:"quality"`
	Cipher           string `json:"signatureCipher"`
	Bitrate          int    `json:"bitrate"`
	FPS              int    `json:"fps"`
	Width            int    `json:"width"`
	Height           int    `json:"height"`
	LastModified     string `json:"lastModified"`
	ContentLength    string `json:"contentLength"`
	QualityLabel     string `json:"qualityLabel"`
	ProjectionType   string `json:"projectionType"`
	AverageBitrate   int    `json:"averageBitrate"`
	AudioQuality     string `json:"audioQuality"`
	ApproxDurationMs string `json:"approxDurationMs"`
	AudioSampleRate  string `json:"audioSampleRate"`
	AudioChannels    int    `json:"audioChannels"`

	// InitRange is only available for adaptive formats
	InitRange *struct {
		Start string `json:"start"`
		End   string `json:"end"`
	} `json:"initRange"`

	// IndexRange is only available for adaptive formats
	IndexRange *struct {
		Start string `json:"start"`
		End   string `json:"end"`
	} `json:"indexRange"`
}

type FormatList

type FormatList []Format

func (FormatList) FindByItag

func (list FormatList) FindByItag(itagNo int) *Format

func (FormatList) FindByQuality

func (list FormatList) FindByQuality(quality string) *Format

type Video

type Video struct {
	ID       string
	Title    string
	Author   string
	Duration time.Duration
	Formats  FormatList
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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