diff options
author | Profpatsch <mail@profpatsch.de> | 2024-09-13T17·12+0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2024-10-05T13·49+0000 |
commit | ffdcb3bb5e8d7689254c82260a29f5d6b2a09281 (patch) | |
tree | 270fb01f12d3e355fb041d62043d1ffa9bf0babe /users/Profpatsch/lyric/default.nix | |
parent | 7fedfe1cde1d1b021c50f3cbd4f620027c85a7ce (diff) |
feat(users/Profpatsch/lyrics): integrate into an mpv extension r/8757
Slop it together! The mpv script is entirely generated by ChatGPT. Whoooooooooo Change-Id: Ic284d142c2f1fd6d407af6b3571db0e815604051 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12478 Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
Diffstat (limited to 'users/Profpatsch/lyric/default.nix')
-rw-r--r-- | users/Profpatsch/lyric/default.nix | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/users/Profpatsch/lyric/default.nix b/users/Profpatsch/lyric/default.nix new file mode 100644 index 000000000000..c20f28b18742 --- /dev/null +++ b/users/Profpatsch/lyric/default.nix @@ -0,0 +1,92 @@ +{ pkgs, depot, lib, ... }: + +let + bins = depot.nix.getBins pkgs.sqlite-utils [ "sqlite-utils" ] + // depot.nix.getBins pkgs.jq [ "jq" ]; + + mpv-script = pkgs.writeTextFile { + name = "lyric.lua"; + text = + lib.replaceStrings + [ "@get_subtitles_command@" ] + [ (toString lyric-to-temp-file) ] + (builtins.readFile ./lyric-mpv-script.lua); + derivationArgs.passthru.scriptName = "lyric.lua"; + }; + + lyric-to-temp-file = depot.nix.writeExecline "lyric-to-temp-file" { readNArgs = 1; } [ + "backtick" + "-E" + "cache" + [ depot.users.Profpatsch.xdg-cache-home ] + "if" + [ "mkdir" "-p" "\${cache}/lyric/as-files" ] + "if" + [ + "redirfd" + "-w" + "1" + "\${cache}/lyric/as-files/\${1}.lrc" + lyric + "$1" + ] + "printf" + "\${cache}/lyric/as-files/\${1}.lrc" + ]; + + # Display lyrics for the given search string; + # search string can contain a substring of band name, album name, song title + # + # Use the database dump from https://lrclib.net/db-dumps and place it in ~/.cache/lyric/lrclib-db-dump.sqlite3 + lyric = + + (depot.nix.writeExecline "lyric" { readNArgs = 1; } [ + "backtick" + "-E" + "cache" + [ depot.users.Profpatsch.xdg-cache-home ] + "pipeline" + [ + bins.sqlite-utils + "query" + "\${cache}/lyric/lrclib-db-dump.sqlite3" + '' + select + synced_lyrics, + has_synced_lyrics, + plain_lyrics + from + tracks_fts(:searchstring) tf + join tracks t on t.rowid = tf.rowid + join lyrics l on t.rowid = l.track_id + order by + has_synced_lyrics desc, t.id + limit + 1 + '' + "--param" + "searchstring" + "$1" + ] + bins.jq + "-r" + '' + if .[0] == null + then "" + else + .[0] + | if .has_synced_lyrics == 1 + then .synced_lyrics + else .plain_lyrics + end + end + '' + ]); + + +in +{ + inherit + lyric + mpv-script; +} |