scripts / get_cover.conf /
Sébastien MARQUE publie config
a0a93ce a year ago
1 contributor
60 lines | 2.41kb
medias=/media/musique
navidrome=/var/lib/navidrome
pre_get_cover () {
    if test ${SCAN:-3} -eq 2 -o ${SCAN:-3} -eq 3; then
        local nouveautes=$(mktemp --dry-run /dev/shm/XXXXXXXX)
        find $medias -name 'lost+found' -prune -o -type d -links 2 -print > $nouveautes
        sqlite3 $navidrome/navidrome.db <<< "select path from media_file" | sed -r 's,/[^/]+$,,' | sort -u >> $nouveautes
        sed -ri "/^${medias//\//\\\/}\/?$/d" $nouveautes
        local IFS=$'\n'
        for d in $(sort $nouveautes | uniq -u); do
            compgen -G "$d/cover.*" > /dev/null \
            || test -e "$d/.no_cover" \
            || albums[${#albums[@]}]=":$d"
        done
        rm $nouveautes
    fi
    if test ${SCAN:-3} -eq 1 -o ${SCAN:-3} -gt 3; then
        echo sync
        sync
        if test ${SCAN:-3} -gt 3; then
            echo scan complet
            local full="-f"
            local _files=15571 # automatiquement mis à jour
            local _eta=1780    # automatiquement mis à jour
            local files=$(find $medias -type f -printf x 2>/dev/null | wc -m)
            local eta=$(( files * _eta / _files ))
            (
                while test $eta -gt 0; do
                    printf "\r\033[Kfin scan complet prévue dans %d:%d" $((eta/60)) $((eta%60))
                    sleep 1
                    let eta--
                done
                printf "\r\033[K"
            )&
            local pid_tc=$!
            _eta=$(date +%s)
        else
            echo scan simple
        fi
        sudo -u navidrome ~navidrome/navidrome -c $navidrome/navidrome.toml --datafolder $navidrome/ -n --musicfolder $medias scan $full
    fi
    if test ${SCAN:-3} -gt 4; then
        _eta=$(( $(date +%s) - $_eta ))
        sed -ri "s/^(\s*local\s+_eta=)[0-9]+/\1$_eta/; s/^(\s*local\s+_files=)[0-9]+/\1$files/" ${BASH_SOURCE[0]}
        if test -e /proc/$pid_tc/stat && stat=($(</proc/$pid_tc/stat)) && test ${stat[3]} -eq $$; then
            kill $pid_tc
            printf "\r\033[K"
        fi
        sudo mount -o remount,ro $medias
        exit
    fi
    sudo mount -o remount,rw $medias
}
post_get_cover () {
    sudo mount -o remount,ro $medias
    if test ${SCAN:-3} -eq 2 -o ${SCAN:-3} -eq 3; then
        echo scan de fin
        sudo -u navidrome ~navidrome/navidrome -c $navidrome/navidrome.toml --datafolder $navidrome/ -n --musicfolder $medias scan
    fi
}