about summary refs log tree commit diff
path: root/users/Profpatsch
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch')
-rw-r--r--users/Profpatsch/lyric.nix45
-rw-r--r--users/Profpatsch/nix-home/default.nix5
2 files changed, 49 insertions, 1 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"
+]
diff --git a/users/Profpatsch/nix-home/default.nix b/users/Profpatsch/nix-home/default.nix
index ee154c549a6b..72c77122fc9b 100644
--- a/users/Profpatsch/nix-home/default.nix
+++ b/users/Profpatsch/nix-home/default.nix
@@ -158,7 +158,10 @@ let
               name = "scripts/lw";
               path = depot.users.Profpatsch.lorri-wait-for-eval;
             }
-
+            {
+              name = "scripts/lyric";
+              path = depot.users.Profpatsch.lyric;
+            }
           ]
           ++
           (lib.pipe depot.users.Profpatsch.aliases [