#!/bin/bash f=/usr/local/lib/err;test -r $f || { echo "error: $0 no $f" >&2;exit 1;}; . $f plists=( # these are useful tags expl gimicky sad # these are normal playlists love pump1 pumprap rend run ) # these options are mainly for debugging / developing quickly. plist_only=false dry_run=false while (( $# )); do case $1 in plist) plist_only=true shift ;; dry) dry_run=true shift ;; *) echo "error. unexpected arg read script" exit 1 ;; esac done m () { printf "%s\n" "$*" >&2 if $dry_run && [[ $1 == beet && $2 == modify ]]; then echo "dry run: $*" else "$@" fi } tmpf=$(mktemp) declare -A flacs declare -A navirating tmpdir=$(mktemp -d) cd $tmpdir if [[ $HOSTNAME != kd ]]; then ssh b8.nz bash -s <flacs for plist in ${plists[@]}; do sqlite3 /i/navidrome/navidrome.db "select path from media_file inner join playlist_tracks on media_file.id = media_file_id where playlist_id = (select id from playlist where name = '\$plist');" | sed 's,^/i/converted,/i/m,' | sort >\$plist done tar cz -C /tmp nav2beet EOF cd nav2beet else for r in 1 2 3 4 5; do sqlite3 /i/navidrome/navidrome.db ".output $r" "select path from annotation inner join media_file on item_id = id where rating = $r;" done find /i/m -type f -name '*.flac' >flacs for plist in ${plists[@]}; do sqlite3 /i/navidrome/navidrome.db "select path from media_file inner join playlist_tracks on media_file.id = media_file_id where playlist_id = (select id from playlist where name = '$plist');" | sed 's,^/i/converted,/i/m,' | sort >$plist done fi while read -r l; do flacs[$l]=t done $tmpf while read -r path; do beetrating[$path]=$r done <$tmpf 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: fi echo begin import navidrome playlists as flexible attribute with value t. # These are only the playlists listed in the beets config.yaml # "subsonicplaylist:" and then duplicated here: for plist in ${plists[@]}; do echo "processing $plist" beet ls -f '$path' $plist:t ^genre:spoken-w ^genre:skit ^rating:1 | sort | sed 's,\.flac$,.mp3,'> p while read -r path; do flac="${path%.mp3}.flac" if [[ ${flacs[$flac]} ]]; then path="$flac" fi m beet modify -y "path:$path" "$plist!" # files unique to tmpf are in beets not navidrome done < <(comm -23 p $plist) while read -r path; do flac="${path%.mp3}.flac" echo "flac=$flac path=$path ${flacs[$flac]} ${flacs[flac]}" if [[ ${flacs[$flac]} ]]; then path="$flac" fi m beet modify -y "path:$path" $plist=t # files unique to plist are in navidrome not beets done < <(comm -13 p $plist) done cd rm -rf $tmpdir