nix-config/pkgs/lyrics/default.nix
Greg Burd f3fd89af54
A fork of Misterio77 and his standard template.
Many thangs to the hard work and generous availability of:
git@github.com:Misterio77/nix-config.git
2023-09-15 10:53:38 -04:00

37 lines
1.1 KiB
Nix

# Fetches current playing song lyrics from makeitpersonal.co
{ lib, writeShellApplication, curl, less, playerctl, gnused }: (writeShellApplication {
name = "lyrics";
runtimeInputs = [ playerctl curl less gnused ];
text = /* bash */ ''
# Exit the script if not playing
playerctl -s status > /dev/null
artist="$(playerctl metadata artist)"
title="$(playerctl metadata title)"
prefix="$artist - "
title="''${title#"$prefix"}"
suffix=" - $artist"
title="''${title%"$suffix"}"
# Cleanup featurings
title="$(echo "$title" | sed -E 's/ ?\(fe?a?t\.?[^\)]*\)//')"
artist="$(echo "$artist" | sed -E 's/ ?\(fe?a?t\.?[^\)]*\)//')"
content="$(curl -f -s --get "https://makeitpersonal.co/lyrics" \
--data-urlencode "artist=$artist" --data-urlencode "title=$title")"
echo -e "$artist - $title\n$content" | less
'';
}) // {
meta = with lib; {
description = "Lyrics fetcher script";
license = licenses.mit;
platforms = platforms.all;
# The makeitpersonal API stopped working :(
# TODO: look for alternatives
broken = true;
};
}