]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Music database creator
authorSergey Matveev <stargrave@stargrave.org>
Sun, 22 Jan 2023 17:00:39 +0000 (20:00 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 22 Jan 2023 20:21:26 +0000 (23:21 +0300)
bin/bin/music-indexer [new file with mode: 0755]

diff --git a/bin/bin/music-indexer b/bin/bin/music-indexer
new file mode 100755 (executable)
index 0000000..9c1d5d1
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env zsh
+
+cat <<EOF
+%rec: Album
+%mandatory: Artist Album
+%allowed: Year Collection Lossless
+%type: Year int
+%type: Lossless bool
+
+EOF
+
+setopt EXTENDED_GLOB
+COLS=()
+for col (cols/*) COLS=($COLS $col:t)
+for name (*~cols) {
+    ts=(${(s/-/)name})
+    year=""
+    for (( i=2 ; i <= $#ts ; i++ )) {
+        [[ ${ts[$i]} =~ "^[0-9][0-9][0-9][0-9]$" ]] && {
+            year=${ts[$i]}
+            break
+        }
+    }
+    [[ -n $year ]] && {
+        artist=(${ts[1,$i-1]})
+        album=(${ts[$i+1,-1]})
+    } || {
+        artist=${ts[1]}
+        album=(${ts[2,-1]})
+    }
+    lossless=""
+    [[ -d $name ]] && {
+        wvs=($name/**/*.wv(N))
+        [[ ${#wvs} -gt 0 ]] && lossless=1
+    } || {
+        [[ $name:e = wv ]] && lossless=1
+    }
+    cols=()
+    for col ($COLS) [[ -e cols/$col/$name ]] && cols=($cols $col)
+
+    print "Artist: ${(j/-/)artist:gs/_/ /}"
+    [[ -n $year ]] && print "Year: $year"
+    print "Album: ${(j/-/)album:gs/_/ /}"
+    [[ -n $lossless ]] && print "Lossless: yes"
+    for col ($cols) print "Collection: $col"
+    [[ ${#cols} -eq 0 ]] && print "Collection: unsorted"
+    print
+}