X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=nav2beet;h=22322a60b4790275571605d92671beb43d62bd2f;hp=cc9ca15c2a11efc4dd3da37e83daeb63cbea64a5;hb=72c18f3a6a7f1ed0ca16af654a1f804ab96e1ff9;hpb=3c7dab4936f011bb91f42f7ccb1f8432b94ea040 diff --git a/nav2beet b/nav2beet index cc9ca15..22322a6 100755 --- a/nav2beet +++ b/nav2beet @@ -1,20 +1,14 @@ #!/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 -) +set -e; . /usr/local/lib/err; set +e +source /a/bin/ds/beet-data +source /b/bash_unpublished/source-semi-priv + +declare -A genre_a +for g in ${all_genres[@]}; do + genre_a[$g]=t +done # these options are mainly for debugging / developing quickly. plist_only=false @@ -39,7 +33,7 @@ done m () { printf "%s\n" "$*" >&2 - if $dry_run && [[ $1 == beet && $2 == modify ]]; then + if $dry_run; then echo "dry run: $*" else "$@" @@ -53,29 +47,22 @@ declare -A flacs declare -A navirating tmpdir=$(mktemp -d) cd $tmpdir +# the code here is duplicated later for non ssh context. 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 +/a/bin/ds/nav2beet-local 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 + /a/bin/ds/nav2beet-local fi while read -r l; do flacs[$l]=t @@ -83,10 +70,6 @@ done $tmpf while read -r path; do beetrating[$path]=$r @@ -107,8 +91,16 @@ if ! $plist_only; then for path in "${!navirating[@]}"; do r="${navirating[$path]}" + if [[ ! "${beetrating[$path]}" ]]; then + if [[ -e $path ]]; then + echo "$0: ERROR: $path exists but we have no rating for it" + exit 1 + else + echo "$0: WARNING: $path exists in navidrome but not beets" + continue + fi + fi 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 @@ -116,17 +108,50 @@ if ! $plist_only; then # 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: - +shopt -s nullglob +for path in 2genre/*/*; do + id="${path#*/}" + id="${id%/*}" + filename="${path##*/}" + tmp="${filename%%[^0-9-]*}" + genre="${filename#"$tmp"}" + if [[ ${genre_a[$genre]} ]]; then + is_genre=true + else + # Some playlists we create with random names to remind us to do something + # with these tracks later once we are at a computer. + is_genre=false + fi + while read -r path; do + flac="${path%.mp3}.flac" + if [[ ${flacs[$flac]} ]]; then + path="$flac" + fi + if $is_genre; then + m beet modify -y "path:$path" "genre=$genre" + else + m beet modify -y "path:$path" "$genre=t" + fi + done <"$path" + # how i figured this out: + # s tcpdump -i any -w /tmp/tcpdump port 4533 + # then delete a test playlist in client. + # made some sense out of it with: http://www.subsonic.org/pages/api.jsp + # open file in wireshard, right click "Hypertext Transfer Protocol", copy, as printable text, put into file /tmp/headers + # /a/opt/h2c/h2c p + # shellcheck disable=SC2016 # expected beets arg + beet ls -f '$path' $plist:t $nav_convert_query | sort | sed 's,\.flac$,.mp3,'> p while read -r path; do flac="${path%.mp3}.flac" if [[ ${flacs[$flac]} ]]; then @@ -137,7 +162,6 @@ for plist in ${plists[@]}; do 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