about summary refs log tree commit diff
path: root/users/Profpatsch/lyric.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2024-09-13T13·08+0200
committerProfpatsch <mail@profpatsch.de>2024-09-13T13·44+0000
commite826ffb19ca50b0de25cf3ec4003309758828156 (patch)
tree40f2d0d4fd7ced05acdb6a5e596b0a4045410ec4 /users/Profpatsch/lyric.nix
parent5c57529675b0656bb460cfe8cae5d610067fe105 (diff)
feat(users/Profpatsch): add lyric r/8687
Change-Id: I3171d19f1cd550ef22a3a7e851f9d27d3bf34949
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12476
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/Profpatsch/lyric.nix')
-rw-r--r--users/Profpatsch/lyric.nix45
1 files changed, 45 insertions, 0 deletions
diff --git a/users/Profpatsch/lyric.nix b/users/Profpatsch/lyric.nix
new file mode 100644
index 000000000000..962a62721a6c
--- /dev/null
+++ b/users/Profpatsch/lyric.nix
@@ -0,0 +1,45 @@
+# 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
+
+{ depot, pkgs, lib, ... }:
+
+let
+  bins = depot.nix.getBins pkgs.sqlite-utils [ "sqlite-utils" ]
+    // depot.nix.getBins pkgs.jq [ "jq" ];
+
+in
+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,
+          source,
+          t.name,
+          t.artist_name
+      from
+          tracks_fts(:searchstring) tf
+          join tracks t on t.rowid = tf.rowid
+          join lyrics l on t.rowid = l.track_id
+      order by
+          t.id
+      limit
+          1
+    ''
+    "--param"
+    "searchstring"
+    "$1"
+  ]
+  bins.jq
+  "-r"
+  ".[0].synced_lyrics"
+]