youtube

package module
v0.0.0-...-66cdec9 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package youtube implement youtube download package in go.

Index

Examples

Constants

View Source
const (
	Size1Kb  = 1024
	Size1Mb  = Size1Kb * 1024
	Size10Mb = Size1Mb * 10
)
View Source
const (
	ErrCipherNotFound             = constError("cipher not found")
	ErrSignatureTimestampNotFound = constError("signature timestamp not found")
	ErrInvalidCharactersInVideoID = constError("invalid characters in video id")
	ErrVideoIDMinLength           = constError("the video id must be at least 10 characters long")
	ErrReadOnClosedResBody        = constError("http: read on closed response body")
	ErrNotPlayableInEmbed         = constError("embedding of this video has been disabled")
	ErrLoginRequired              = constError("login required to confirm your age")
	ErrVideoPrivate               = constError("user restricted access to this video")
	ErrInvalidPlaylist            = constError("no playlist detected or invalid playlist ID")
)

Variables

View Source
var (
	// WebClient, better to use Android client but go ahead.
	WebClient = clientInfo{
				// contains filtered or unexported fields
	}

	// AndroidClient, download go brrrrrr.
	AndroidClient = clientInfo{
					// contains filtered or unexported fields
	}

	// EmbeddedClient, not really tested.
	EmbeddedClient = clientInfo{
					// contains filtered or unexported fields
	}
)
View Source
var DefaultClient = AndroidClient

DefaultClient type to use. No reason to change but you could if you wanted to.

View Source
var (
	ErrNoFormat = errors.New("no video format provided")
)

Functions

This section is empty.

Types

type Client

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

	// MaxRoutines to use when downloading a video.
	MaxRoutines int

	// ChunkSize to use when downloading videos in chunks. Default is Size10Mb.
	ChunkSize int64
	// contains filtered or unexported fields
}

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

formats := video.Formats.WithAudioChannels() // only get videos with audio
stream, _, err := client.GetStream(video, &formats[0])
if err != nil {
	panic(err)
}
defer stream.Close()

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

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

func (*Client) GetPlaylist

func (c *Client) GetPlaylist(url string) (*Playlist, error)

GetPlaylist fetches playlist metadata

func (*Client) GetPlaylistContext

func (c *Client) GetPlaylistContext(ctx context.Context, url string) (*Playlist, error)

GetPlaylistContext fetches playlist metadata, with a context, along with a list of Videos, and some basic information for these videos. Playlist entries cannot be downloaded, as they lack all the required metadata, but can be used to enumerate all IDs, Authors, Titles, etc.

func (*Client) GetStream

func (c *Client) GetStream(video *Video, format *Format) (io.ReadCloser, int64, error)

GetStream returns the stream and the total size for a specific format

func (*Client) GetStreamContext

func (c *Client) GetStreamContext(ctx context.Context, video *Video, format *Format) (io.ReadCloser, int64, error)

GetStreamContext returns the stream and the total size for a specific format with a context.

func (*Client) GetStreamURL

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

GetStreamURL returns the url for a specific format

func (*Client) GetStreamURLContext

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

GetStreamURLContext returns the url 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

func (*Client) VideoFromPlaylistEntry

func (c *Client) VideoFromPlaylistEntry(entry *PlaylistEntry) (*Video, error)

func (*Client) VideoFromPlaylistEntryContext

func (c *Client) VideoFromPlaylistEntryContext(ctx context.Context, entry *PlaylistEntry) (*Video, error)

type DecipherOperation

type DecipherOperation func([]byte) []byte

type ErrPlayabiltyStatus

type ErrPlayabiltyStatus struct {
	Status string
	Reason string
}

func (ErrPlayabiltyStatus) Error

func (err ErrPlayabiltyStatus) Error() string

type ErrPlaylistStatus

type ErrPlaylistStatus struct {
	Reason string
}

func (ErrPlaylistStatus) Error

func (err ErrPlaylistStatus) Error() string

type ErrUnexpectedStatusCode

type ErrUnexpectedStatusCode int

ErrUnexpectedStatusCode is returned on unexpected HTTP status codes

func (ErrUnexpectedStatusCode) Error

func (err ErrUnexpectedStatusCode) Error() string

type FormatList

type FormatList []Format

func (FormatList) AudioChannels

func (list FormatList) AudioChannels(n int) FormatList

AudioChannels returns a new FormatList filtered by the matching AudioChannels

func (FormatList) Itag

func (list FormatList) Itag(itagNo int) FormatList

Type returns a new FormatList filtered by itag

func (FormatList) Language

func (list FormatList) Language(displayName string) FormatList

Type returns a new FormatList filtered by display name

func (FormatList) Quality

func (list FormatList) Quality(quality string) FormatList

Quality returns a new FormatList filtered by quality, quality label or itag, but not audio quality

func (FormatList) Select

func (list FormatList) Select(f func(Format) bool) (result FormatList)

Type returns a new FormatList filtered by itag

func (FormatList) Sort

func (list FormatList) Sort()

Sort sorts all formats fields

func (FormatList) Type

func (list FormatList) Type(value string) FormatList

Type returns a new FormatList filtered by mime type

func (FormatList) WithAudioChannels

func (list FormatList) WithAudioChannels() FormatList

AudioChannels returns a new FormatList filtered by the matching AudioChannels

Jump to

Keyboard shortcuts

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