lyrics

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 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 a song's words, and when they're sung: from a .lrc file next to the song, from the song's own tags, or (only when an admin turns it on) from LRCLIB, a free and open lyrics database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finder

type Finder struct {
	Prober probe.Prober
	// Online looks songs up on LRCLIB; nil never does.
	Online *LRCLIB
}

Finder finds songs' words.

func (*Finder) Find

func (f *Finder) Find(ctx context.Context, song Song, online bool) (Lyrics, error)

Find returns the song's words: timed ones from next to the song or its tags first, then (with online) from LRCLIB, then untimed ones. It returns empty Lyrics when there are none anywhere.

type LRCLIB

type LRCLIB struct {
	// Base is the API; empty is https://lrclib.net/api.
	Base      string
	Client    *http.Client
	UserAgent string
	Dir       string
}

LRCLIB looks up songs' words on LRCLIB (lrclib.net), a free, open database of lyrics that needs no account or key. The server asks it directly; nothing goes through anyone else. Answers, including "not there", are kept in Dir so each song is asked about once in a while.

func (*LRCLIB) Find

func (c *LRCLIB) Find(ctx context.Context, song Song) (Lyrics, error)

Find looks the song up: first exactly (artist, title, album and length), then by searching for the artist and title and taking a result about as long as the song.

type Line

type Line struct {
	Ms   *int64 `json:"ms,omitempty"`
	Text string `json:"text"`
}

Line is one line of a song's words. Ms is when it's sung, in milliseconds from the start; it's nil when the words aren't timed.

type Lyrics

type Lyrics struct {
	Synced bool   `json:"synced"`
	Lines  []Line `json:"lines"`
	// Source says where they came from: file (a .lrc or .txt next to the
	// song), embedded (the song's tags) or online (LRCLIB). Empty when
	// there are none.
	Source string `json:"source,omitempty"`
	// Instrumental means the song has no words at all.
	Instrumental bool `json:"instrumental,omitempty"`
}

Lyrics are a song's words. Synced means every line has its time.

func Embedded

func Embedded(tags map[string]string) Lyrics

Embedded reads the words in a song's tags (keys lower-cased, as probe gives them): ID3's USLT shows up as lyrics-eng and the like, MP4's as lyrics, Vorbis comments as lyrics or unsyncedlyrics. Many taggers put timed LRC text in them; timed words win over untimed ones.

func Parse

func Parse(text string) Lyrics

Parse reads LRC text, or plain text when no line is timed. Times are moved by the file's [offset:], so they're when the words are sung.

func (Lyrics) Empty

func (l Lyrics) Empty() bool

Empty is true when there's nothing to show.

type Song

type Song struct {
	Path       string
	Artist     string
	Title      string
	Album      string
	DurationMs int64
}

Song is what the finder needs to know about a song.

Jump to

Keyboard shortcuts

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