ytparser

package module
v0.0.0-...-1f71918 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: ISC Imports: 11 Imported by: 0

README

ytparser

ytparser is a library for searching youtube. As the name indicates, this library parses youtube's html in order to get the search results. As a result, ytparser doesn't use the youtube API.

Contributing

Send patches to ~ark/ytparser@lists.sr.ht

Subscribe to the mailing list here: https://lists.sr.ht/~ark/ytparser

Tracker for discussing various issues related to ytparser: https://todo.sr.ht/~ark/ytparser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintItems

func PrintItems(items []Item, format string)

Prints an array of Item based on a given template format.

The format should follow go's text/template format. For example: "{{.Title}}" would print the titles of each item.

Types

type Item

type Item struct {
	Id           string
	Title        string
	Url          string // The url of the video
	ThumbUrl     string // The thumbnail url
	ChannelId    string
	ChannelTitle string
	ChannelUrl   string
	Published    string // The published date provided by youtube as is.
	LengthText   string // The length of the video rendered as text by youtube.
	AtomUrl      string
	ViewCount    string
}

A Item represents a youtube video, or more precisely its metadata (title, url...).

func Search(query string, page int, lang string, order string) ([]Item, error)

Launch a search on the given query, page, language and order and return an array of items and/or an error.

The lang parameter must be a youtube supported language code ("en", "fr", "de"...) and allows getting certain information such as the published date in the selected language. If empty, youtube should detect the language based on location.

The order parameter can be any of the following: relevance, date, views, rating. The default value is relevance.

This function may return items even if there is an error, allowing the search to be considered partially successful. If this is the case it most likely means there was an error during the parse, but some items were still successfully parsed before the error.

func (Item) Format

func (item Item) Format(t *template.Template) string

Executes a given template on an item and returns the resulting string.

The item is passed directly to the template execution. For example: "title: {{.Title}}" would return the item's title prefixed with "title: ".

func (Item) String

func (item Item) String() string

Jump to

Keyboard shortcuts

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