youtubeapi

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

youtubeapi

GitHub release (latest by date) GitHub tag (latest by date) Go Report Card

YouTube REST API v3 client for Go. For searching and getting details of YouTube videos, channels and playlists.

Currently implemented

  • Video details
  • Channel details
  • Search
  • Playlists

Example

yt := youtubeapi.New(httpc, apiKey)
item, err := yt.GetVideo(`dQw4w9WgXcQ`)
if err != nil {
	panic(err)
}

fmt.Printf(`%v %v %v`, item.Snippet.ChannelID, item.Snippet.PublishedAt, item.Snippet.Title)

ch, err := yt.GetChannel(`UCuAXFkgsw1L7xaCfnd5JJOw`)
if err != nil {
	panic(err)
}

fmt.Printf(`%v %v %v`, ch.Snippet.PublishedAt, ch.Snippet.Title, ch.Snippet.Description)

custom := map[string]string{
	`regionCode`:        `US`,
	`relevanceLanguage`: `en`,
}

res, err := yt.Search(`never gonna give you up`, custom)
if err != nil {
	panic(err)
}

fmt.Printf(`%v`, res)

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type YoutubeAPI

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

YoutubeAPI is REST client for YouTube REST API v3 See [internal](internal) directory for implementation details See https://console.cloud.google.com/apis/api/youtube.googleapis.com/quotas

func New

func New(cl *http.Client, apikey string) *YoutubeAPI

New creates a new YouTube HTTP REST API v3 client

You can use caching in http.Client .Transport http.RoundTripper:

httpc := http.DefaultClient
httpc.Transport = myCachingRoundTripper
ytc := New(httpc, `...`)

func (YoutubeAPI) GetChannel

func (api YoutubeAPI) GetChannel(channelId string) (*channel.Item, error)

GetChannel fetches channel information from YouTube REST API, see internal/channel for more details

func (YoutubeAPI) GetChannelAllVideos added in v1.5.0

func (api YoutubeAPI) GetChannelAllVideos(channelId string, custom map[string]string) ([]playlistitem.Item, error)

GetChannelAllVideos fetches all videos listed by given channelId

func (YoutubeAPI) GetChannelAllVideosPlaylist added in v1.5.0

func (api YoutubeAPI) GetChannelAllVideosPlaylist(channelId string) (*playlist.Item, error)

GetChannelAllVideosPlaylist fetches first channel information containing playlist ID and then fetches playlist meta information. Then you can iterate videos with GetPlaylistVideos()

func (YoutubeAPI) GetChannelIdFromName added in v1.4.0

func (api YoutubeAPI) GetChannelIdFromName(channelName string) (*string, error)

GetChannelIdFromName returns channel Id from given channel name (@foobarVideos) -> channel ID "abcdefgh". This might fail so try with Search(channelName, search.TypeChannel, ...) also

func (YoutubeAPI) GetChannelPlaylists added in v1.3.0

func (api YoutubeAPI) GetChannelPlaylists(channelId string, customParameters map[string]string) ([]playlist.Item, *shared.Meta, error)

GetChannelPlaylists fetches playlists meta information (no videos) from given channel ID

func (YoutubeAPI) GetChannelStats added in v1.3.0

func (api YoutubeAPI) GetChannelStats(channelId string) (*channel.Item, error)

GetChannelStats fetches statistics of given channel ID from YouTube REST API, see internal/channel for more details

func (YoutubeAPI) GetChannelStatsMany added in v1.3.0

func (api YoutubeAPI) GetChannelStatsMany(channelIds []string) ([]channel.Item, error)

GetChannelStatsMany fetches statistics of given channel ID(s) from YouTube REST API, see internal/channel for more details

func (YoutubeAPI) GetChannels added in v1.1.0

func (api YoutubeAPI) GetChannels(channelIds []string) ([]channel.Item, error)

GetChannels fetches multiple channel information from YouTube REST API, see internal/channel for more details

func (YoutubeAPI) GetPlaylist added in v1.2.0

func (api YoutubeAPI) GetPlaylist(playlistId string) (*playlist.Item, error)

GetPlaylist fetches given playlists' meta information (no videos)

func (YoutubeAPI) GetPlaylistVideoItems added in v1.3.0

func (api YoutubeAPI) GetPlaylistVideoItems(plItemIds []string, customParameters map[string]string) ([]playlistitem.Item, error)

GetPlaylistVideoItems fetches items (videos) which are *in* some playlist

func (YoutubeAPI) GetPlaylistVideos added in v1.3.0

func (api YoutubeAPI) GetPlaylistVideos(playlistId string, customParameters map[string]string) ([]playlistitem.Item, *shared.Meta, error)

GetPlaylistVideos fetches given playlists' videos

func (YoutubeAPI) GetPlaylists added in v1.3.0

func (api YoutubeAPI) GetPlaylists(playlistIds []string) ([]playlist.Item, error)

GetPlaylists fetches given list of playlists' meta information such as video count, but no videos

func (YoutubeAPI) GetVideo

func (api YoutubeAPI) GetVideo(videoId string) (*video.Item, error)

GetVideo fetches video information from YouTube REST API, see internal/video for more details

func (YoutubeAPI) GetVideoStats added in v1.2.0

func (api YoutubeAPI) GetVideoStats(videoId string) (*video.Item, error)

GetVideoStats fetches video statistics from YouTube REST API, see internal/video for more details

func (YoutubeAPI) GetVideos added in v1.1.0

func (api YoutubeAPI) GetVideos(videoIds []string) ([]video.Item, error)

GetVideos fetches multiple video information from YouTube REST API, see internal/video for more details

func (YoutubeAPI) GetVideosStats added in v1.2.0

func (api YoutubeAPI) GetVideosStats(videoIds []string) ([]video.Item, error)

GetVideosStats fetches multiple video information from YouTube REST API, see internal/video for more details

func (YoutubeAPI) Search

func (api YoutubeAPI) Search(query string, searchType search.TypeParam, customParameters map[string]string) (*search.Result, error)

Search searches YouTube REST API with given query, see internal/search for more details Note: the search consumes more API quota See https://developers.google.com/youtube/v3/docs/search/list

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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