youtube: github.com/kkdai/youtube Index | Examples | Files | Directories

package youtube

import "github.com/kkdai/youtube"

Package youtube implement youtube download package in go.

Index

Examples

Package Files

client.go decipher.go decipher_operations.go decipher_operations_cache.go doc.go errors.go format_list.go response_data.go video.go video_id.go

Variables

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

type Client Uses

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
    // contains filtered or unexported fields
}

Client offers methods to download video metadata and video streams.

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

Code:

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

func (*Client) GetStream Uses

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

GetStream returns the HTTP response for a specific format

func (*Client) GetStreamContext Uses

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) GetStreamURL Uses

func (c *Client) GetStreamURL(video *Video, format *Format) (string, error)

GetStreamURL returns the url for a specific format

func (*Client) GetStreamURLContext Uses

func (c *Client) GetStreamURLContext(ctx context.Context, video *Video, format *Format) (string, error)

GetStreamURL returns the url for a specific format with a context

func (*Client) GetVideo Uses

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

GetVideo fetches video metadata

func (*Client) GetVideoContext Uses

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

GetVideoContext fetches video metadata with a context

type DecipherOperation Uses

type DecipherOperation func([]byte) []byte

type DecipherOperationsCache Uses

type DecipherOperationsCache interface {
    Get(videoID string) []DecipherOperation
    Set(video string, operations []DecipherOperation)
}

type ErrPlayabiltyStatus Uses

type ErrPlayabiltyStatus struct {
    Status string
    Reason string
}

func (ErrPlayabiltyStatus) Error Uses

func (err ErrPlayabiltyStatus) Error() string

type ErrResponseStatus Uses

type ErrResponseStatus struct {
    Status string
    Reason string
}

func (ErrResponseStatus) Error Uses

func (err ErrResponseStatus) Error() string

type ErrUnexpectedStatusCode Uses

type ErrUnexpectedStatusCode int

ErrUnexpectedStatusCode is returned on unexpected HTTP status codes

func (ErrUnexpectedStatusCode) Error Uses

func (err ErrUnexpectedStatusCode) Error() string

type Format Uses

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 Uses

type FormatList []Format

func (FormatList) FindByItag Uses

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

func (FormatList) FindByQuality Uses

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

type SimpleCache Uses

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

func NewSimpleCache Uses

func NewSimpleCache() *SimpleCache

func (SimpleCache) Get Uses

func (s SimpleCache) Get(videoID string) []DecipherOperation

Get : get cache when it has same video id and not expired

func (SimpleCache) GetCacheBefore Uses

func (s SimpleCache) GetCacheBefore(videoID string, time time.Time) []DecipherOperation

GetCacheBefore : can pass time for testing

func (*SimpleCache) Set Uses

func (s *SimpleCache) Set(videoID string, operations []DecipherOperation)

Set : set cache with default expiration

type Video Uses

type Video struct {
    ID              string
    Title           string
    Description     string
    Author          string
    Duration        time.Duration
    Formats         FormatList
    DASHManifestURL string // URI of the DASH manifest file
    HLSManifestURL  string // URI of the HLS manifest file
}

Directories

PathSynopsis
downloader

Package youtube imports 12 packages (graph) and is imported by 1 packages. Updated 2021-01-11. Refresh now. Tools for package owners.