lots of fixes, new music stuff
[distro-setup] / navidrome-playlist-export
diff --git a/navidrome-playlist-export b/navidrome-playlist-export
new file mode 100755 (executable)
index 0000000..c4c824c
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+f=/usr/local/lib/err;test -r $f || { echo "error: $0 no $f" >&2;exit 1;}; . $f
+
+
+
+# begin star rating import from navidrome to beets:
+declare -A navirating
+for r in 1 2 3 4 5; do
+  while read -r path; do
+    beetpath="/i/m${path#/i/converted}"
+    navirating[$beetpath]=$r
+  done < <(sqlite3 /i/navidrome/navidrome.db "select path from annotation inner join media_file on item_id = id where rating = $r;")
+done
+declare -A beetrating
+for r in 1 2 3 4 5; do
+  while read -r path; do
+    beetrating[$path]=$r
+  done < <(beet ls -f '$path' rating:$r)
+done
+
+for path in "${!navirating[@]}"; do
+  r="${navirating[$path]}"
+  if [[ $r != "${beetrating[$path]}" ]]; then
+    # note: this assumes there are no cases like filea.mp3 filea.mp3.mp3, which would affect both files.
+    echo "$r != ${beetrating[$path]}, beet modify -y path:$path rating=$r"
+    beet modify -y "path:$path" "rating=$r"
+  fi
+done
+# end star rating import from navidrome to beets:
+
+
+beet subsonicplaylist
+
+while read -r id plists; do
+  plists="${plists#;}"
+  e beet modify -y "id:$id" ${plists//;/=t }
+done < <(beet ls -f '$id $subsonic_playlist' subsonic_playlist::.)