youtubesearch

package
v0.0.0-...-e878a9f Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type YoutubeApiHandler

type YoutubeApiHandler struct {
	ApiKey string      // The Api Key used
	Logger *log.Logger // Logger to write diagnostics to
	// contains filtered or unexported fields
}

func New

func New(apiKey string, logger *log.Logger) *YoutubeApiHandler

New creates a new YoutubeApiHandler and sets up the caching facilities

func (*YoutubeApiHandler) Close

func (yt *YoutubeApiHandler) Close()

Close terminates the YoutubeApiHandler

func (*YoutubeApiHandler) GetRandomVid

func (yt *YoutubeApiHandler) GetRandomVid(query string) (string, error)

GetRandomVid queries youtube and returns a random value from the results

func (*YoutubeApiHandler) MakeQuery

func (yt *YoutubeApiHandler) MakeQuery(query string) YoutubeApiResponse

MakeQuery searches to see for results, it also uses Local Caching to reduce bandwidth/api use :)

type YoutubeApiResponse

type YoutubeApiResponse struct {
	Kind          string             `json:"kind"`          // The Kind of response from the API
	Etag          string             `json:"etag"`          // The Etag of the video (for caching :) )
	NextPageToken string             `json:"nextPageToken"` // Token for next page
	RegionCode    string             `json:"regionCode"`    // The Region of the search
	PageInfo      YoutubePageInfo    `json:"pageInfo"`      // Info related to the query
	Items         []YoutubeVideoData `json:"items"`         // The items returned
}

type YoutubePageInfo

type YoutubePageInfo struct {
	TotalResults   int `json:"totalResults"`   // Number of results in total from the query
	ResultsPerPage int `json:"resultsPerPage"` // Amount of results returned by the search
}

type YoutubeSearchCacheItem

type YoutubeSearchCacheItem struct {
	Date  time.Time          `json:"Date"`
	Query string             `json:"Query"`
	Body  YoutubeApiResponse `json:"Body"`
}

type YoutubeVideoData

type YoutubeVideoData struct {
	Kind    string              `json:"kind"`    // type of content returned
	Etag    string              `json:"etag"`    // for replayability
	Id      YoutubeVideoId      `json:"id"`      // The information related directly to the video
	Snippet YoutubeVideoSnippet `json:"snippet"` // The data related to the video I.E thumbs and shit
}

type YoutubeVideoId

type YoutubeVideoId struct {
	Kind    string `json:"kind"`    // The type of data provided
	VideoId string `json:"videoId"` // The ID of the video
}

type YoutubeVideoSnippet

type YoutubeVideoSnippet struct {
	PublishedAt          string                        `json:"publishedAt"`          // UTC timestamp of time of video being published
	ChannelId            string                        `json:"channelId"`            // The ID of the channel that uploaded the video
	Title                string                        `json:"title"`                // The Title of the video uploaded
	Description          string                        `json:"string"`               // The description of the video
	Thumbnails           map[string]YoutubeVideoThumbs `json:"thumbnails"`           // Information related to the thumbnails of the videos
	ChannelTitle         string                        `json:"channelTitle"`         // The name of the channel that uploaded the video
	LiveBroadcastContent string                        `json:"liveBroadcastContent"` // Live broadcast content (I don't actually know what this means)
	PublishTime          string                        `json:"publishTime"`          // The time the video was published
}

type YoutubeVideoThumbs

type YoutubeVideoThumbs struct {
	Url    string `json:"url"`    // The URL of the thumbnail
	Width  int    `json:"width"`  // width of the thumbnail in px
	Height int    `json:"Height"` // Height of the thumbnail in px
}

Jump to

Keyboard shortcuts

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