provider

package
v0.0.0-...-f539960 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// YouTubeVideoPrefix : YouTube video prefix
	YouTubeVideoPrefix = "https://www.youtube.com"
	// YouTubeQueryURL : YouTube query URL
	YouTubeQueryURL = YouTubeVideoPrefix + "/results"
	// YouTubeQueryPattern : YouTube query URL parseable with *printf functions
	YouTubeQueryPattern = YouTubeQueryURL + "?q=%s"
	// YouTubeHTMLVideoSelector : YouTube entry video selector
	YouTubeHTMLVideoSelector = ".yt-uix-tile-link"
	// YouTubeHTMLDescSelector : YouTube entry description selector
	YouTubeHTMLDescSelector = ".yt-lockup-byline"
	// YouTubeHTMLDurationSelector : YouTube entry duration selector
	YouTubeHTMLDurationSelector = ".accessible-description"
)
View Source
const (
	// DurationTolerance : max result duration difference tolerance
	DurationTolerance = 20 // second(s)
)

Variables

This section is empty.

Functions

func IDFromURL

func IDFromURL(url string) string

IDFromURL : extract YouTube entry ID from input URL

Types

type Entry

type Entry struct {
	ID       string
	URL      string
	Title    string
	User     string
	Duration int
}

Entry : single search result struct

func (*Entry) Empty

func (e *Entry) Empty() bool

Empty returns true if entry does not have a URL and it's unusable, then

func (*Entry) Repr

func (e *Entry) Repr() string

Repr returns a human readable representation of the entry

type Provider

type Provider interface {
	Name() string
	Query(*track.Track) ([]*Entry, error)
	Match(*Entry, *track.Track) error
	Download(*Entry, string) error
	ValidateURL(url string) error
}

Provider defines the generic interface on which every download provider should be basing its logic

func All

func All() []Provider

All return the array of usable providers

func For

func For(URL string) (Provider, error)

For returns a provider for a given URL

type Scorable

type Scorable interface {
	Score(*Entry, *track.Track) int
}

Scorable defines the functions needed to apply a score over results

type Scorer

type Scorer struct {
	Scorable
}

Scorer provides a basic Scorable implementation

func (Scorer) Score

func (s Scorer) Score(e *Entry, t *track.Track) int

Score implements a basic scoring logic usable by any Provider

type YouTubeProvider

type YouTubeProvider struct {
	Provider
	Scorer
}

YouTubeProvider is the provider implementation which uses as source YouTube videos.

func (YouTubeProvider) Download

func (p YouTubeProvider) Download(e *Entry, fname string) error

Download : delegate youtube-dl call to download entry

func (YouTubeProvider) Match

func (p YouTubeProvider) Match(e *Entry, t *track.Track) error

Match : return nil error if YouTube entry is matching with track

func (YouTubeProvider) Name

func (p YouTubeProvider) Name() string

Name returns a human readable name for the provider

func (YouTubeProvider) Query

func (p YouTubeProvider) Query(track *track.Track) ([]*Entry, error)

Query : query provider for entries related to track

func (YouTubeProvider) ValidateURL

func (p YouTubeProvider) ValidateURL(url string) error

ValidateURL : return nil error if input URL is a valid YouTube URL

Jump to

Keyboard shortcuts

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