Documentation ¶
Overview ¶
Package youtube implement youtube download package in go.
Index ¶
- Variables
- type Client
- func (c *Client) GetStream(video *Video, format *Format) (*http.Response, error)
- func (c *Client) GetStreamContext(ctx context.Context, video *Video, format *Format) (*http.Response, error)
- func (c *Client) GetStreamURL(video *Video, format *Format) (string, error)
- func (c *Client) GetStreamURLContext(ctx context.Context, video *Video, format *Format) (string, error)
- func (c *Client) GetVideo(url string) (*Video, error)
- func (c *Client) GetVideoContext(ctx context.Context, url string) (*Video, error)
- type ErrPlayabiltyStatus
- type ErrResponseStatus
- type ErrUnexpectedStatusCode
- type Format
- type FormatList
- type Video
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) 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) GetStreamURL ¶
GetStreamURL returns the url for a specific format
func (*Client) GetStreamURLContext ¶
func (c *Client) GetStreamURLContext(ctx context.Context, video *Video, format *Format) (string, error)
GetStreamURL returns the url for a specific format with a context
type ErrPlayabiltyStatus ¶
func (ErrPlayabiltyStatus) Error ¶
func (err ErrPlayabiltyStatus) Error() string
type ErrResponseStatus ¶
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.