lyrics

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lyrics finds the lyrics of the playing track on LRCLIB (lrclib.net) and caches them, misses included, on disk: synced lyrics as timed lines, plain lyrics as untimed ones.

Index

Constants

View Source
const Endpoint = "https://lrclib.net/api/get"

Endpoint is LRCLIB's lookup by signature.

Variables

This section is empty.

Functions

This section is empty.

Types

type Line

type Line struct {
	At   time.Duration `json:"at"`
	Text string        `json:"text"`
}

Line is one lyric line; At is when it starts, zero for plain lyrics.

func ParseLRC

func ParseLRC(text string) []Line

ParseLRC reads LRC text into lines ordered by time: every [mm:ss.xx] tag on a line times a copy of its text, [offset:±ms] shifts them all (positive is earlier), and metadata tags and untimed lines are dropped.

type Lyrics

type Lyrics struct {
	Lines  []Line `json:"lines"`
	Synced bool   `json:"synced"`
}

Lyrics is a track's lyrics: no lines when the track has none, timed lines when Synced.

func (Lyrics) Current

func (l Lyrics) Current(pos time.Duration) int

Current is the index of the line sung at pos: -1 before the first line and for plain lyrics.

func (Lyrics) Found

func (l Lyrics) Found() bool

Found reports whether there are lyrics to show.

type Service

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

Service looks lyrics up, once per track: a result, a miss included, is kept in memory and in the cache directory, and concurrent asks for one track share a request.

func New

func New(endpoint, dir string) *Service

New looks lyrics up at endpoint (Endpoint, or a test server) and caches them in dir.

func (*Service) Get

func (s *Service) Get(ctx context.Context, t Track) (Lyrics, error)

Get returns the track's lyrics; a track without an artist or title has none and asks nothing. A failed request is an error and is not cached, so the next Get asks again.

type Track

type Track struct {
	Artist string
	Title  string
	Album  string
	Length time.Duration
}

Track is what LRCLIB matches lyrics on: the MPRIS xesam fields and mpris:length.

Jump to

Keyboard shortcuts

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