A little Rust program that fetches plaintext lyrics from genius.com and dumps them to the terminal, potential successor of https://github.com/raymon-roos/lyrical-php.
Back when I used to use foobar2000, (in a deep, dark past where I used Windows...), I loved having a lyrics panel plugin. Lyrics are a large part of what I enjoy in songs.
My music player of choice these days is cmus. I haven't found a convenient lyrics program that runs in the terminal yet, so I made my own. Though as yet its features are limited.
- Rust & cargo, v1.83
- OpenSSL with headers are required on linux1 (they're already included in the Nix shell).
- Crates used:
reqwestfor sending HTTP requests,serde_jsonfor de-serialising JSON,scraperfor parsing HTML.
- Create a genius account.
- Create an API client: https://genius.com/api-clients. Just fill in some random things, it doesn't matter for this program.
- Generate an access token for your "client" and save it to
$XDG_CONFIG_HOME/lyrical/token. Maybe make the file only readable and writeable by your own user.
Try out without installing:
nix run 'github:raymon-roos/lyrical-rs' --artist 'windmills' --title 'true natural'
# See all available options:
nix run 'github:raymon-roos/lyrical-rs' --helpInstall into home-manager or system configuration using flakes:
# flake.nix:
inputs = {
lyrical.url = "github:raymon-roos/lyrical-rs";
lyrical.inputs.nixpkgs.follows = "nixpkgs";
}
# home-manager configuration:
home.packages = [
inputs.lyrical.packages.${pkgs.system}.default
];
# Alternatively, NixOS system configuration:
environment = {
systemPackages = [
inputs.lyrical.packages.${pkgs.system}.default
];- Clone this repo to a location of your choice.
- Make sure you have the OpenSSL headers installed, as per 1
- Run
cargo install --path .(make sure that$CARGO_HOME/binis in your$PATH)
lyrical-rs --help
Available options:
--help Print this help text and exit.
--title <title> (required) Title of the song to search lyrics for.
--artist <artist> (optional) Restrict search results by the name of the
song's artist.
--url <url> (optional) Rather than searching, fetch lyrics from this
genius.com url directly. If present, `--artist`,
`--title` and `--list` will be ignored.
--list [count] (optional) Print list of [count] (default 20) genius.com search
results, rather than song lyrics. Useful for
further filtering, manually or through external tools.
Example
lyrical-rs --artist 'Sleep Token' --title 'Euclid' --list
lyrical-rs --url 'https://genius.com/The-arcadian-wild-wander-wonder-lyrics'I use a bash script to get the currently playing song in cmus and to save the lyrics to a file. For inspiration, see https://github.com/raymon-roos/scripts/blob/main/lyrics_in_terminal.sh. That way I can use fd for searching files, rather than implementing my own file searching algorithm. This whole thing could be a bash script, if you can find a good way to parse HTML…
Eventually I might combine multiple sources for lyrics, support multiple music players, add time cues (karaoke mode), and make the program interactive to allow for more advanced features. We'll see…