Showing 11 changed files with 303 additions and 111 deletions
+6 -6
flightgear/fgaddon
... ...
@@ -377,18 +377,18 @@ if test -e $database; then
377 377
     cp $database $in_ram_database
378 378
 
379 379
     sql_cols=$(sqlite_request "pragma table_info(setxml)" \
380
-             | cut --delimiter="|" --fields=2,3 --output-delimiter=" " \
381
-             | sort \
382
-             | md5sum)
380
+             | awk -F'|' '{print $2 " " tolower($3)}' \
381
+             | sort)
383 382
     datatypes[file]=text
384 383
     datatypes[variantof]=integer
385 384
     datatypes[installed]=integer
386 385
     script_cols=$(for col in ${!datatypes[@]}; do echo "$col ${datatypes["$col"]%% *}"; done \
387
-                | sort \
388
-                | md5sum)
386
+                | sort)
389 387
     unset datatypes[file] datatypes[variantof] datatypes[installed]
390
-    if test "$sql_cols" != "$script_cols"; then
388
+    if test "$(md5sum <<< $sql_cols)" != "$(md5sum <<< $script_cols)"; then
391 389
         echo "ALERT: datbase version mismatch !"
390
+        echo "DB:     $sql_cols"
391
+        echo "script: $script_cols"
392 392
         exit 1
393 393
     fi
394 394
     if sqlite_request '.tables' | grep -q 'recover_'; then
+1 -1
flightgear/fgaddon.d/fgmembers.hangar
... ...
@@ -89,7 +89,7 @@ function parse_repo_history () {
89 89
             add_record author   ${hangar[name]}
90 90
             add_aircraft
91 91
         else
92
-            sqlite_request "delete from aircrafts where name = '$repo' and hangar = ${hangar[i]}"
92
+            sqlite_request "delete from aircrafts where name = '$repo' and hangar = '${hangar[name]}'"
93 93
         fi
94 94
 
95 95
         newprogress=$((i * 100 / $jq_length))
+59 -19
flightgear/fgfs_function
... ...
@@ -59,7 +59,6 @@ function fgfs () {
59 59
                             cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}})
60 60
                             cmake_options+=(${(j. .)${:--DCMAKE_INCLUDE_PATH=$fgfs_install/${^previously_installed}/include}})
61 61
                         fi
62
-                        cmake_options+=("-j$simultaneous")
63 62
 
64 63
                         title="*** ${component:u}${branch:+ [$branch]} ***"
65 64
                         printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
... ...
@@ -71,7 +70,7 @@ function fgfs () {
71 70
                         cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
72 71
                         && make -j$simultaneous > /dev/null \
73 72
                         && {
74
-                            make install | grep --color=always -v '^-- Up-to-date:'
73
+                            make install | sed -r "s,$HOME,\$HOME,; /^-- Up-to-date:/d"
75 74
                         } \
76 75
                         || {
77 76
                             echo "erreur construction $component"
... ...
@@ -153,7 +152,7 @@ function fgfs () {
153 152
                     if test -n "$REPLY" && test ${REPLY:l} = "y"; then
154 153
                         declare -A hangar
155 154
                         eval $(sqlite3 $FGADDON/fgaddon.db <<< "select printf('hangar[type]=%s;hangar[url]=%s;', type, url)
156
-                                                                from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
155
+                                                                from hangars where name = '${${${(@s/ /)ac}[2]}:1:-1}'")
157 156
                         case ${hangar[type]} in
158 157
                             git)
159 158
                                 git -C $FGADDON/Aircraft clone ${hangar[url]}/${${(@s/ /)ac}[1]}.git;;
... ...
@@ -190,11 +189,18 @@ function fgfs () {
190 189
                 local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
191 190
                 local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
192 191
                 local candidate_runway=${fgfs_arg#*+};  [[ $candidate_runway  == $fgfs_arg ]] && unset candidate_runway
193
-                local terrafs=${candidate_airport#-}
194 192
 
195
-                if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then
196
-                    candidate_airport=$terrafs
197
-                    $HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d
193
+                if [[ -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then
194
+                    if test $(grep -Ec "^terrafs\s+$HOME/.fgfs/terrafs.d" /proc/mounts) -eq 0 \
195
+                    && echo "$HOME/.fgfs/terrafs.d present but not mounted !"                 \
196
+                    && test -x $HOME/.fgfs/mount.terrafs                                      \
197
+                    && read -q "mount_terrafs?go to mount it ? (y/N) "                        \
198
+                    && [[ "${mount_terrafs:-n}" = "y" ]]; then
199
+                        $HOME/.fgfs/mount.terrafs || return 1
200
+                    else
201
+                        echo "mount it manually, or remove it to use TerraSync"
202
+                        return 1
203
+                    fi
198 204
                     fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d)
199 205
                     fgfs_args+=(--disable-terrasync)
200 206
                     local scenes_dir=$HOME/.fgfs/terrafs.d
... ...
@@ -365,7 +371,7 @@ EOH
365 371
                                                      and
366 372
                                                        setxml.file = '$file'
367 373
                                                      and
368
-                                                       hangars.name = '${${(@s/ /)ac}[2]:1:-1}'")
374
+                                                       hangars.name = '${${${(@s/ /)ac}[2]}:1:-1}'")
369 375
                         if test -n "$_info"; then
370 376
                             printf "%s: %s\n" "$2" "$_info"
371 377
                         fi
... ...
@@ -439,8 +445,8 @@ EOH
439 445
                         return
440 446
                     fi
441 447
                     local url=$(sqlite3 $FGADDON/fgaddon.db <<< "select printf('%s/${${(@s/ /)ac}[1]}', url)
442
-                                                                 from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
443
-                    if test ${${(@s/ /)ac}[2]:1:-1} = 'FGMEMBERS'; then
448
+                                                                 from hangars where name = '${${${(@s/ /)ac}[2]}:1:-1}'")
449
+                    if test ${${${(@s/ /)ac}[2]}:1:-1} = 'FGMEMBERS'; then
444 450
                         url="https://raw.githubusercontent.com/FGMEMBERS/${${(@s/ /)ac}[1]}/master"
445 451
                     fi
446 452
                     if wget --quiet --spider "$url/thumbnail.jpg"; then
... ...
@@ -448,7 +454,7 @@ EOH
448 454
                         | convert - -resize '200%' -normalize -sharpen '0.0x1.0' - \
449 455
                         | display
450 456
                     else
451
-                        echo "can't find or get thumbnail for ${${(@s/ /)ac}[1]} (${${(@s/ /)ac}[2]:1:-1}'s hangar)"
457
+                        echo "can't find or get thumbnail for ${${(@s/ /)ac}[1]} (${${${(@s/ /)ac}[2]}:1:-1}'s hangar)"
452 458
                     fi
453 459
                     return
454 460
                     ;;
... ...
@@ -583,7 +589,7 @@ EOH
583 589
                     test -z "$ac" && return
584 590
                     declare -A hangar
585 591
                     eval $(sqlite3 $FGADDON/fgaddon.db <<< "select printf('hangar[type]=%s;hangar[url]=%s;', type, url)
586
-                                                            from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
592
+                                                            from hangars where name = '${${${(@s/ /)ac}[2]}:1:-1}'")
587 593
                     case ${hangar[type]} in
588 594
                         git)
589 595
                             git -C $FGADDON/Aircraft clone ${hangar[url]}/${${(@s/ /)ac}[1]}.git;;
... ...
@@ -642,10 +648,44 @@ EOH
642 648
                         echo "can't find requested addon in $addon_path or $FGADDON/$addon_path !"
643 649
                     fi
644 650
                     ;;
651
+                --ws3|--ws3=.*)
652
+                    echo 80 "utilise World Scenery 3.0 (chemin par défaut $FGADDON/WS3.0)" > /dev/null
653
+                    fgfs_args=("${(@)fgfs_args:#--terrasync-dir=$HOME/.fgfs/TerraSync}")
654
+                    fgfs_args=("${(@)fgfs_args:#--enable-terrasync}")
655
+
656
+                    if test "${fgfs_arg#*=}" = "$fgfs_arg"; then
657
+                        fgfs_args+=("--fg-scenery=$FGADDON/WS3.0")
658
+                    elif test -d "${fgfs_arg#*=}/vpb"; then
659
+                        fgfs_args+=("--fg-scenery='${fgfs_arg#*=}'")
660
+                    else
661
+                        echo "${fgfs_arg#*=} isn't a valid WS3 directory"
662
+                        return 1
663
+                    fi
664
+                    fgfs_args+=("--prop:bool:/scenery/use-vpb=true")
665
+                    fgfs_args+=("--prop:int:/sim/rendering/max-paged-lod=300")
666
+                    fgfs_args+=("--prop:double:/sim/rendering/plod-minimum-expiry-time-secs=30")
667
+                    fgfs_args+=("--prop:int:/sim/rendering/database-pager/threads=8")
668
+                    ;;
669
+                --ortho)
670
+                    echo 81 utilise Orthoscenery > /dev/null
671
+                    fgfs_args+=("--prop:bool:/sim/rendering/photoscenery/enabled=true")
672
+                    ;;
673
+                --hdr)
674
+                    echo 82 utilise le compositor HDR > /dev/null
675
+                    local compositor=Compositor/HDR/hdr
676
+                    if test -r $fgfs_source/fgdata/$compositor.xml; then
677
+                        fgfs_args+=("--compositor=$compositor")
678
+                        fgfs_args+=("--prop:bool:/sim/rendering/osm-buildings=false")
679
+                        fgfs_args+=("--prop:bool:/sim/rendering/random-buildings=false")
680
+                    else
681
+                        echo "Compositor $compositor inaccessible"
682
+                    fi
683
+                    ;;
645 684
                 *)
646 685
                     completion_source="$FGDIR/install/flightgear/share/zsh/site-functions/_fgfs"
647 686
                     if test -r "$completion_source"; then
648
-                        if egrep --quiet "^\s*'${fgfs_arg%=*}=?\[" "$completion_source"; then
687
+                        if egrep --quiet "^\s*'(${fgfs_arg%=*}=?|)\[" "$completion_source" \
688
+                        || [[ ${fgfs_arg} =~ ^--prop(:(string|double|float|long|int|bool))?:/[[:print:]]+= ]]; then
649 689
                             fgfs_args+=($fgfs_arg)
650 690
                         else
651 691
                             echo unknown option: ${fgfs_arg%=*}
... ...
@@ -667,11 +707,11 @@ EOH
667 707
 
668 708
     fgfsrc=$HOME/.fgfs/fgfsrc
669 709
     echo ${fgfs_args[@]//$HOME/\$HOME} $(test -r $fgfsrc && sed -r "/^\s*(#|$)/d;s|$HOME|\$HOME|" $fgfsrc | tr '\n' ' ')
670
-# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
671
-    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
672
-    
673
-    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
674
-        fusermount -u $HOME/.fgfs/terrafs.d
710
+    export ${DISCRETE_GPU[@]}
711
+    $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
712
+    unset fgfs_args ${DISCRETE_GPU[@]%=*}
713
+
714
+    if test ${mount_terrafs:-n} = y; then
715
+        $HOME/.fgfs/mount.terrafs
675 716
     fi
676
-    unset fgfs_args
677 717
 }
+87
flightgear/mount.terrafs
... ...
@@ -0,0 +1,87 @@
1
+#!/bin/zsh
2
+
3
+terrafs_d=${1:-$HOME/.fgfs/terrafs.d}
4
+
5
+osm2city_dirs=(
6
+        Buildings
7
+        Details
8
+        Pylons
9
+        Roads
10
+        Trees
11
+    )
12
+
13
+ws20_dirs=(
14
+        Airports
15
+        Models
16
+        Objects
17
+        Terrain
18
+    )
19
+
20
+for k in ${(koM)parameters}; do
21
+    if [[ $k =~ .+_dirs && ${(M)parameters[$k]} == array ]]; then
22
+        sceneries+=(${k%_dirs})
23
+        typeset -A ${k%_dirs}_urls
24
+    fi
25
+done
26
+
27
+if test -r $0.conf; then
28
+    source $0.conf
29
+else
30
+    echo pas de $0.conf trouvé
31
+    exit 1
32
+fi
33
+
34
+for scenery in ${sceneries[@]}; do
35
+    if ! eval "test \${#${scenery}_urls[@]} -gt 0"; then
36
+        echo $scenery erreur
37
+        exit 1
38
+    fi
39
+done
40
+
41
+get_url () {
42
+    eval "local hosts=(\${(k)${1}_urls[@]})"
43
+    echo ${hosts[$(( $RANDOM % ${#hosts[@]} + 1 ))]}
44
+}
45
+
46
+remove_url () {
47
+    eval "unset \"${1}_urls[$2]\""
48
+}
49
+
50
+get_largest () {
51
+    eval "local _1=\${#${1}_urls[@]}"
52
+    eval "local _2=\${#${2}_urls[@]}"
53
+    if test $_1 -gt $_2; then
54
+        echo largest=$1
55
+        echo smallest=$2
56
+    else
57
+        echo largest=$2
58
+        echo smallest=$1
59
+    fi
60
+}
61
+
62
+mount_dirs () {
63
+    local dir=
64
+    eval "local oserver=https://\${${1}_url}/\${${1}_urls[\${${1}_url}]}"
65
+    eval "local dirs=(\${${1}_dirs[@]})"
66
+    for dir in ${dirs[@]}; do
67
+        mkdir -p $HOME/.fgfs/terrafs.d/$dir
68
+        printf "- %-10s " $dir && $HOME/.fgfs/terrafs -oserver=$oserver/$dir $terrafs_d/$dir && echo "ok" || echo "ERROR"
69
+    done
70
+}
71
+
72
+if test $(grep -Ec "^terrafs +$terrafs_d" /proc/mounts) -ne $(( ${#ws20_dirs[@]} + ${#osm2city_dirs[@]} )); then
73
+    eval $(get_largest ${sceneries[@]})
74
+    eval "${largest}_url=$(get_url $largest)"
75
+    eval "remove_url $smallest \$${largest}_url"
76
+    eval "${smallest}_url=$(get_url $smallest)"
77
+
78
+    for m in ${sceneries[@]}; do
79
+        eval "printf 'montage %s depuis %s\n' ${(U)m} \$${m}_url"
80
+        mount_dirs $m
81
+    done
82
+else
83
+    echo "démontage $terrafs_d"
84
+    for dir in ${osm2city_dirs[@]} ${ws20_dirs[@]}; do
85
+        printf "- %-10s " $dir && fusermount -u $terrafs_d/$dir && echo "ok" || echo "ERROR"
86
+    done
87
+fi
+11
flightgear/mount.terrafs.conf
... ...
@@ -0,0 +1,11 @@
1
+osm2city_urls=(
2
+        cdn.merspieler.tk       o2c
3
+        ukmirror.flightgear.org osm2city
4
+    )
5
+
6
+ws20_urls=(
7
+        cdn.merspieler.tk          ts
8
+        ukmirror.flightgear.org    fgscenery
9
+#        flightgear.sourceforge.net scenery
10
+    )
11
+
+6
flightgear/source/OpenVSP.specific
... ...
@@ -9,7 +9,13 @@ cmake     -DVSP_USE_SYSTEM_LIBXML2=true \
9 9
           -DVSP_USE_SYSTEM_EIGEN=false \
10 10
           -DVSP_USE_SYSTEM_CODEELI=false \
11 11
           -DVSP_USE_SYSTEM_CPPTEST=false \
12
+          -DPYTHON_EXECUTABLE='/usr/bin/python3.9' \
13
+          -DPYTHON_LIBRARY='/usr/lib/python3.9' \
14
+          -DPYTHON_INCLUDE_DIR='/usr/include/python3.9' \
15
+          -DPYTHON_INCLUDE_PATH='/usr/include' \
12 16
           -DCMAKE_BUILD_TYPE=Release \
17
+          -DCMAKE_CXX_COMPILER=g++-11 \
18
+          -DCMAKE_CC_COMPILER=gcc-11 \
13 19
           $fgfs_source/OpenVSP/Libraries \
14 20
 && make -j$simultaneous \
15 21
 && cmake_options+=("-DVSP_LIBRARY_PATH=$fgfs_build/OpenVSPlibs") \
-3
flightgear/source/flightgear.specific
... ...
@@ -2,8 +2,5 @@ cmake_options+=("-DENABLE_COMPOSITOR=ON")
2 2
 cmake_options+=("-DFG_DATA_DIR:PATH=$fgfs_source/fgdata")
3 3
 cmake_options+=("-DTRANSLATIONS_SRC_DIR:PATH=$fgfs_source/fgdata/Translations")
4 4
 cmake_options+=("-DSimGear_DIR=$fgfs_install/simgear/lib/cmake/SimGear")
5
-#cmake_options+=("CFLAGS="--std=c++14"")
6
-cmake_options+=("-DCMAKE_CXX_COMPILER=g++-9")
7
-cmake_options+=("-DCMAKE_CC_COMPILER=gcc-9")
8 5
 
9 6
 export OSG_DIR=$fgfs_install/OpenSceneGraph
-4
flightgear/source/simgear.specific
... ...
@@ -1,4 +0,0 @@
1
-#cmake_options+=("CFLAGS="--std=c++14"")
2
-cmake_options+=("-DCMAKE_CXX_COMPILER=g++-9")
3
-cmake_options+=("-DCMAKE_CC_COMPILER=gcc-9")
4
-
+72 -77
get_cover
... ...
@@ -8,9 +8,8 @@ mbz_agent='getCover/0.1 (https://seb.lautre.net/git/seb/scripts)'
8 8
 
9 9
 test -e $0.conf && source $0.conf
10 10
 
11
-coverartarchive_api="https://coverartarchive.org/release"
12 11
 coverart=$(mktemp --dry-run /dev/shm/XXXXXXXX)
13
-sizes=(small 250 500 large 1200)
12
+sizes=(500 large small 250 1200)
14 13
 
15 14
 OK      () { echo -e "\e[3;32m ${1:-OK} \e[0;m";     return 0; }
16 15
 WARNING () { echo -e "\e[3;33m ${1:-alerte} \e[0;m"; return 1; }
... ...
@@ -47,11 +46,29 @@ covered () {
47 46
 }
48 47
 
49 48
 get_image () {
49
+    install_image () {
50
+        mv -f /dev/shm/$1 ${album#*:}/$cover_img.${1##*.} \
51
+        && OK \
52
+        || ERROR "échec en écriture"
53
+    }
54
+
50 55
     if curl -Ls $1 > /dev/shm/$2; then
51 56
         mime_type=$(file -bn --mime-type /dev/shm/$2)
52 57
         if [[ ${mime_type:-erreur} =~ ^image/ ]]; then
53
-            mv -f /dev/shm/$2 ${album#*:}/$cover_img.${2##*.} \
54
-            || ERROR "échec en écriture"
58
+            read -t 30 -p "${album%%:*} check ? "
59
+            rc=$?
60
+            if [[ "$rc$REPLY" =~ 0[OoYy] ]]; then
61
+                display /dev/shm/$2
62
+                read -p "on garde ? "
63
+                if [[ "$REPLY" =~ [OoYy] ]]; then
64
+                    install_image $2
65
+                else
66
+                    rm /dev/shm/$2
67
+                    WARNING "vignette rejetée"
68
+                fi
69
+            else
70
+                install_image $2
71
+            fi
55 72
         else
56 73
             WARNING "${album%%:*} type $mime_type"
57 74
         fi
... ...
@@ -60,31 +77,15 @@ get_image () {
60 77
     fi
61 78
 }
62 79
 
63
-get_spotify_access_token () {
64
-    if test -n "$spotifyID" -a -n "$spotifySecret"; then
65
-        spotify_access_token=$(curl --silent \
66
-            --request POST \
67
-            --url https://accounts.spotify.com/api/token \
68
-            --header 'Content-Type: application/x-www-form-urlencoded' \
69
-            --header "Authorization: Basic $(base64 -w0 <<< $spotifyID:$spotifySecret | sed 's/K$/=/')" \
70
-            -d 'grant_type=client_credentials' | jq -r '.access_token // empty')
71
-        if test -z "$spotify_access_token"; then
72
-            ERROR "problème d'identifant Spotify"
73
-            spotify_access_token_error=1
74
-            echo ID: $spotifyID
75
-        fi
76
-    fi
77
-}
78
-
79 80
 get_from_mbz () {
80
-    curl -Ls $coverartarchive_api/${album%%:*} > $coverart
81
+    curl -Ls https://coverartarchive.org/release${1:+-group}/${album%%:*} > $coverart
81 82
     if test $(file -bn --mime-type $coverart) = application/json; then
82 83
         unset img
83 84
         for size in ${sizes[@]}; do
84 85
             img=$(jq -r '.images | .[] | select(.front == true) | .thumbnails | ."'$size'"?' $coverart 2>/dev/null)
85
-            test -n "$img" && break
86
+            test "${img:-null}" != null && break
86 87
         done
87
-        if test -n "$img"; then
88
+        if test "${img:-null}" != null; then
88 89
             get_image "$img" "${album%%:*}.${img##*.}"
89 90
         fi
90 91
     else
... ...
@@ -92,36 +93,14 @@ get_from_mbz () {
92 93
     fi
93 94
 }
94 95
 
95
-get_from_spotify () {
96
-    if test -n "$album_name" -a -n "$artist"; then
97
-        curl --request GET --silent \
98
-            --header "Authorization: Bearer $spotify_access_token" \
99
-            --header 'Content-Type: application/json' \
100
-            --data 'type=album' \
101
-            --data "query==album:${_album_name}%20artist:${_artist}" \
102
-            --url "https://api.spotify.com/v1/search" > $coverart
103
-        found_albums=$(jq -r '.albums .total // empty' $coverart)
104
-        if test ${found_albums:-0} -gt 0; then
105
-            img=$(jq --raw-output --arg artist "${artist^^}" --arg album "${album_name^^}" "
106
-                    .albums .items
107
-                    | .[]
108
-                    | select(.name | ascii_upcase == \$album)
109
-                    | select(.artists | .[].name | ascii_upcase == \$artist)
110
-                    | .images
111
-                    | .[]
112
-                    | select(.height == 300)
113
-                    | .url // empty" $coverart)
114
-            if test -n "$img"; then
115
-                get_image "$img" "${img##*/}.jpg"
116
-            else
117
-                WARNING "pas d'image trouvée sur spotify (artist: $artist; album: $album_name)"
118
-            fi
119
-        else
120
-            WARNING "aucun album trouvé sur spotify"
121
-        fi
122
-    else
123
-        ERROR "album: $album_name; artist: $artist"
124
-    fi
96
+mbz_api () {
97
+    curl \
98
+        --request ${3:-GET} \
99
+        --user-agent "$mbz_agent" \
100
+        --silent \
101
+        --location \
102
+        --url "http://musicbrainz.org/ws/2/$1/?fmt=json&query=$2"
103
+    sleep 2
125 104
 }
126 105
 
127 106
 if ! test -d $medias; then
... ...
@@ -141,19 +120,28 @@ for arg in $@; do
141 120
     elif [[ $arg =~ ^/ ]]; then
142 121
         from_CLI=1
143 122
         albums[${#albums[@]}]=":${arg%/}"
123
+    elif [[ $arg =~ / ]]; then
124
+        from_CLI=1
125
+        albums[${#albums[@]}]=$(sql_request 'select mbz_album_id||":"||path
126
+                                             from media_file
127
+                                             where artist||"/"||album = "'$arg'"' \
128
+                                | sed -r 's|/[^/]+*$||' \
129
+                                | uniq \
130
+                                | tail -1)
144 131
     elif [[ $arg =~ ^(force|retry)$ ]]; then
145 132
         forcing_level=$arg
146 133
     else
147 134
         WARNING "incohérence sur $arg"
148 135
     fi
149 136
 done
137
+
150 138
 if test -n "$from_CLI"; then
151 139
     forcing_level=force
152 140
 fi
153 141
 
154 142
 if test ${#albums[@]} -eq 0; then
155 143
     albums=($(sql_request 'select printf("%s:'${medias%/}'/%s/%s", mbz_album_id, artist, name)
156
-             from album where cover_art_path = ""
144
+             from album where image_files = ""
157 145
              and name != "[Unknown Album]"'))
158 146
 fi
159 147
 
... ...
@@ -168,12 +156,37 @@ for album in ${albums[@]}; do
168 156
     if covered; then
169 157
         continue
170 158
     fi
171
-    echo -n "${album#*:} "
159
+    echo "${album#*:}"
160
+
161
+    if test -z "${album%%:*}"; then
162
+        mbz_album_id=$(sql_request "select distinct mbz_album_id
163
+                                    from media_file
164
+                                    where path like '${album#*:}/%'")
165
+        album=${mbz_album_id}${album}
166
+    fi
172 167
     if test -n "${album%%:*}"; then
173 168
         mbz_related=1
174 169
         if get_from_mbz; then
175
-            OK
176 170
             continue
171
+        else
172
+            mbz_api release reid:${album%%:*} > $coverart
173
+            rgid=$(jq --raw-output '.releases | .[] | ."release-group" .id // empty' $coverart)
174
+            album="${rgid:-null}:${album#*:}"
175
+            if get_from_mbz release-group; then
176
+                continue
177
+            fi
178
+
179
+            if test -n "$rgid"; then
180
+                mbz_api release-group rgid:$rgid > $coverart
181
+                mbz_album_ids=($(jq --raw-output '."release-groups" | .[].releases | .[].id // empty' $coverart))
182
+
183
+                for reid in ${mbz_album_ids[@]}; do
184
+                    album=$reid:${album#*:}
185
+                    if get_from_mbz; then
186
+                        continue 2
187
+                    fi
188
+                done
189
+            fi
177 190
         fi
178 191
     fi
179 192
 
... ...
@@ -182,11 +195,7 @@ for album in ${albums[@]}; do
182 195
                         where artist || "/" || name = "'${album#*:$medias/}'"')"
183 196
     eval $(php -r 'echo "_artist=".rawurlencode($argv[1]).";_album_name=".rawurlencode($argv[2]);' -- "$artist" "$album_name")
184 197
 
185
-    curl \
186
-        --request GET \
187
-        --user-agent "$mbz_agent" \
188
-        --silent --location \
189
-        --url "http://musicbrainz.org/ws/2/release/?fmt=json&query=release:$_album_name%20AND%20artist:$_artist" > $coverart
198
+    mbz_api release "release:$_album_name%20AND%20artist:$_artist" > $coverart
190 199
 
191 200
     mbids=($(jq --raw-output --arg artist "${artist^^}" --arg album "${album_name^^}" '
192 201
             .releases
... ...
@@ -198,26 +207,12 @@ for album in ${albums[@]}; do
198 207
     for mbid in ${mbids[@]}; do
199 208
         album="$mbid:${album#*:}"
200 209
         if get_from_mbz; then
201
-            OK
202 210
             continue 2
203 211
         fi
204 212
     done
205 213
 
206
-    if test -z "$spotify_access_token" -a -z "$spotify_access_token_error"; then
207
-        get_spotify_access_token
208
-    fi
209
-
210
-    if test -n "$spotify_access_token"; then
211
-        if get_from_spotify; then
212
-            OK
213
-        else
214
-            WARNING "pas trouvé (spotify)"
215
-            touch "${album#*:}/$no_cover_flag"
216
-        fi
217
-    else
218
-        WARNING "pas trouvé ($(( ${mbz_related:-0} + ${#mbids[@]} )) relations sur musicbrainz)"
219
-        touch "${album#*:}/$no_cover_flag"
220
-    fi
214
+    WARNING "pas trouvé ($(( ${mbz_related:-0} + ${#mbids[@]} )) relations sur musicbrainz)"
215
+    touch "${album#*:}/$no_cover_flag"
221 216
 done
222 217
 
223 218
 rm -f $coverart 
+59
get_cover.conf
... ...
@@ -0,0 +1,59 @@
1
+medias=/media/musique
2
+navidrome=/var/lib/navidrome
3
+pre_get_cover () {
4
+    if test ${SCAN:-3} -eq 2 -o ${SCAN:-3} -eq 3; then
5
+        local nouveautes=$(mktemp --dry-run /dev/shm/XXXXXXXX)
6
+        find $medias -name 'lost+found' -prune -o -type d -links 2 -print > $nouveautes
7
+        sqlite3 $navidrome/navidrome.db <<< "select path from media_file" | sed -r 's,/[^/]+$,,' | sort -u >> $nouveautes
8
+        sed -ri "/^${medias//\//\\\/}\/?$/d" $nouveautes
9
+        local IFS=$'\n'
10
+        for d in $(sort $nouveautes | uniq -u); do
11
+            compgen -G "$d/cover.*" > /dev/null \
12
+            || test -e "$d/.no_cover" \
13
+            || albums[${#albums[@]}]=":$d"
14
+        done
15
+        rm $nouveautes
16
+    elif test ${SCAN:-3} -eq 1 -o ${SCAN:-3} -gt 3; then
17
+        echo sync
18
+        sync
19
+        if test ${SCAN:-3} -gt 3; then
20
+            echo scan complet
21
+            local full="-f"
22
+            local _files=15571 # automatiquement mis à jour
23
+            local _eta=1780    # automatiquement mis à jour
24
+            local files=$(find $medias -type f -printf x 2>/dev/null | wc -m)
25
+            local eta=$(( files * _eta / _files ))
26
+            (
27
+                while test $eta -gt 0; do
28
+                    printf "\r\033[Kfin scan complet prévue dans %d:%d" $((eta/60)) $((eta%60))
29
+                    sleep 1
30
+                    let eta--
31
+                done
32
+                printf "\r\033[K"
33
+            )&
34
+            local pid_tc=$!
35
+            _eta=$(date +%s)
36
+        else
37
+            echo scan simple
38
+        fi
39
+    fi
40
+    if test ${SCAN:-3} -gt 4; then
41
+        _eta=$(( $(date +%s) - $_eta ))
42
+        sed -ri "s/^(\s*local\s+_eta=)[0-9]+/\1$_eta/; s/^(\s*local\s+_files=)[0-9]+/\1$files/" ${BASH_SOURCE[0]}
43
+        if test -e /proc/$pid_tc/stat && stat=($(</proc/$pid_tc/stat)) && test ${stat[3]} -eq $$; then
44
+            kill $pid_tc
45
+            printf "\r\033[K"
46
+        fi
47
+        sudo mount -o remount,ro $medias
48
+        exit
49
+    fi
50
+    sudo -u navidrome ~navidrome/navidrome -c $navidrome/navidrome.toml --datafolder $navidrome/ -n --musicfolder $medias scan $full
51
+    sudo mount -o remount,rw $medias
52
+}
53
+post_get_cover () {
54
+    sudo mount -o remount,ro $medias
55
+    if test ${SCAN:-3} -eq 2 -o ${SCAN:-3} -eq 3; then
56
+        echo scan de fin
57
+        sudo -u navidrome ~navidrome/navidrome -c $navidrome/navidrome.toml --datafolder $navidrome/ -n --musicfolder $medias scan
58
+    fi
59
+}
+2 -1
livret
... ...
@@ -12,6 +12,7 @@ size=$(pdfinfo "$pdf" | awk '/^Page size:/{
12 12
 	if (a >= 1189 && a <= 1191 && b >= 841  && b <= 843 ) print "a3"
13 13
 }')
14 14
 pages=$(pdfinfo "$pdf" | awk '/Pages:/{print $2}')
15
+size=${size:-a4}
15 16
 test $pages -ne 4 -o -z "$size" && exit	
16 17
 
17 18
 recto=$(mktemp -d /dev/shm/XXXXXXXX)
... ...
@@ -26,7 +27,7 @@ else
26 27
 fi
27 28
 
28 29
 booksize="a$((${size//[^45]}-1))"
29
-pdfjam --paper ${booksize}paper --nup 2x1 --landscape --outfile $recto "$output" 1 "$output" 4
30
+pdfjam --paper ${booksize}paper --nup 2x1 --landscape --outfile $recto "$output" 4 "$output" 1
30 31
 pdfjam --paper ${booksize}paper --nup 2x1 --landscape --outfile $verso "$output" 2 "$output" 3
31 32
 pdftk A=$(find $recto -name "*pdf") B=$(find $verso -name "*pdf") cat A B output "${pdf%/*}/livret-${pdf##*/}"
32 33
 rm -fr $recto $verso $output