api

package
v0.0.0-...-c928bda Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TrackType is the type name of track response.
	TrackType = "track"
)

Variables

View Source
var (
	ErrEIDNotFound       = errors.New("eid was not found")
	ErrNoExtractorForURI = errors.New("no extractor for uri found")
)
View Source
var (
	ErrLyricsNotFound = errors.New("lyrics not found")
)

Functions

func WithCore

func WithCore(ctx context.Context, core *Core) context.Context

WithCore adds a Core to a context.

Types

type AudioSourceResp

type AudioSourceResp struct {
	Source      string  `json:"source"`
	Identifier  string  `json:"identifier"`
	URI         string  `json:"uri"`
	StartOffset float64 `json:"start_offset"`
	EndOffset   float64 `json:"end_offset"`

	IsLive bool `json:"is_live"`
}

AudioSourceResp represents an audio source response.

func AudioSourceRespFromTrackSource

func AudioSourceRespFromTrackSource(trackSource edb.TrackSource, uri string) AudioSourceResp

AudioSourceRespFromTrackSource builds an AudioSourceResp from a edb.TrackSource. The track source is expected to have the audio source loaded.

type Core

type Core struct {
	DB             *gorm.DB
	LyricsSearcher search.Searcher

	ExtractorPool     *infoextract.ExtractorPool
	TrackSourceFinder *audiosrc.Finder
}

Core contains important data shared between the handlers.

func CoreFromContext

func CoreFromContext(ctx context.Context) *Core

CoreFromContext extracts the Core from a context.

func (*Core) AddServices

func (c *Core) AddServices(services ...service.Identifier)

AddServices uses the given services to create the extractor pool and track source finder. It will panic if either of them is already set, no database is set, or an invalid service type is passed.

func (*Core) Close

func (c *Core) Close() error

Close closes the core.

func (*Core) GetTrack

func (c *Core) GetTrack(eid string) (edb.Track, error)

func (*Core) GetTrackLyrics

func (c *Core) GetTrackLyrics(ctx context.Context, eid string) (edb.Lyrics, error)

GetTrackLyrics retrieves lyrics for the track with the given EID. The context must contain the api core.

func (*Core) GetTrackSource

func (c *Core) GetTrackSource(ctx context.Context, eid string) (AudioSourceResp, error)

func (*Core) ResolveURI

func (c *Core) ResolveURI(ctx context.Context, uri string) (interface{}, error)

type Handler

type Handler interface {
	// Start starts the handler. The handler should start responding to
	// requests after being started.
	Start() error

	// Stop closes the handler. The handler should no longer respond to
	// requests after being closed.
	Stop() error

	// Done returns a channel which is closed when the handler is done.
	Done() <-chan struct{}
}

Handler defines the interface for an API request handler.

func CollectHandlers

func CollectHandlers(handlers ...Handler) Handler

CollectHandlers creates a new handler from the given handlers.

type ResolveResp

type ResolveResp struct {
	Type string   `json:"type"`
	EIDs []string `json:"eids"`
}

ResolveResp represents the response given to resolve requests.

func CreateResolveResponse

func CreateResolveResponse(v interface{}) (resp ResolveResp, err error)

CreateResolveResponse returns a SimpleResolveResp instance for the given value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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