feat: lyrics support readme and examples

This commit is contained in:
2025-10-15 09:11:54 +02:00
parent 4343521a46
commit d13436b963
4 changed files with 67 additions and 8 deletions

25
share/lyrics/example.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/sh
# Example script for `fuzic` to display the lyrics of a track. This script
# reads from stdin a JSON string and stores it in the variable `j`. The
# variable `tj` contains the JSON string of the track.
j="$(cat)"
tj="$(echo "$j" | jq -r '.trackid as $tid | .release.media[].tracks[] | select(.id == $tid)')"
# The following four variables are self-explanatory:
track_name="$(echo "$tj" | jq -r '.title')"
artist_name="$(echo "$tj" | jq -r '."artist-credit" | map([.name, .joinphrase] | join("")) | join("")')"
album_name="$(echo "$j" | jq -r '.release.title')"
duration="$(echo "$tj" | jq -r '.length / 1000 | round')"
# Now, you may call an API to fetch the lyrics for this track,
#
# curl \
# --get \
# --silent \
# --data-urlencode "track_name=$track_name" \
# --data-urlencode "artist_name=$artist_name" \
# --data-urlencode "album_name=$album_name" \
# --data-urlencode "duration=$duration" \
# "$URL"
#
# or simply print a template to write the lyrics yourself:
printf "Lyrics '%s' by '%s' (album: %s, duration: %s seconds)\n" "$track_name" "$artist_name" "$album_name" "$duration"