youtube

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 9 Imported by: 1

README

youtube

YouTube api client for the command line

Sample usage

Please see the content in file example_test.go for runnable, copy-pastable examples.

Environment variables to set

Variable Default Required Purpose
YOUTUBE_API_KEY True Required when you initialize a client using New() to read your API Key from the environment

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New() (*Client, error)

New returns a client with an API Key derived from the environment, set as YOUTUBE_API_KEY.

func NewWithHTTPClient

func NewWithHTTPClient(hc *http.Client) (*Client, error)

func NewWithKey

func NewWithKey(apiKey string) (*Client, error)

NewWithKey creates a client with the provided API Key.

func (*Client) ById

func (c *Client) ById(ctx context.Context, ids ...string) (chan *ResultsPage, error)

func (*Client) MostPopular

func (c *Client) MostPopular(ctx context.Context, param *SearchParam) (chan *ResultsPage, error)

MostPopular returns the currently most popular videos. Specifying MaxPage, MaxResultsPerPage help control how many items should be retrieved.

func (*Client) Search

func (c *Client) Search(ctx context.Context, param *SearchParam) (chan *SearchPage, error)

type ResultsPage

type ResultsPage struct {
	Index uint64
	Err   error
	Items []*youtube.Video
}

type SearchPage

type SearchPage struct {
	Index uint64

	Err   error
	Items []*youtube.SearchResult
}

type SearchParam

type SearchParam struct {
	PageToken string `json:"page_token"`

	// Query is the content to search for.
	Query string `json:"query"`

	// MaxPage is the maximum number of
	// pages of items that you want returned
	MaxPage uint64 `json:"max_page"`

	// MaxResultsPerPage is the maximum number of
	// items to be returned per pagination/page fetch.
	MaxResultsPerPage uint64 `json:"max_results_per_page"`

	// MaxRequestedItems is the threshold for the number
	// of items that you'd like to stop the search after.
	MaxRequestedItems uint64 `json:"max_requested_items"`

	// RelatedToVideoId is the id for whose
	// related videos you'd like returned
	RelatedToVideoId string `json:"related_to_video_id"`
}

Jump to

Keyboard shortcuts

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