Showing 1 changed files with 52 additions and 30 deletions
+52 -30
thumbnails
... ...
@@ -47,7 +47,7 @@ if ! which convert > /dev/null; then
47 47
     exit 1
48 48
 fi
49 49
 
50
-sqlcmd="select path from ${dbprefix}images
50
+sqlcmd="select distinct path from ${dbprefix}images
51 51
            where id in (
52 52
               select distinct image_id from ${dbprefix}image_category
53 53
                   where category_id in (
... ...
@@ -55,35 +55,57 @@ sqlcmd="select path from ${dbprefix}images
55 55
                   )
56 56
            )"
57 57
 
58
-IFS=$'\n'
59
-for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
60
-    format=""
61
-    fnNoExt="${file%.*}"
62
-    fnExt="${file##*.}"
63
-    fnPath="${file%/*}"
64
-    test $fnExt = 'mp4' && continue
65
-    cmd="sudo -u www-data convert \"$site/$file\" -write mpr:image +delete "
66
-    count=0
67
-    for size in ${!imgsize[@]}; do
68
-        if ! test -e "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" -a -z "$FORCE"; then
69
-            format+="$size "
70
-            cmd+="mpr:image -filter Lanczos -auto-orient -strip -quality 95 -interlace line -sampling-factor 4:2:2 "
71
-            cmd+="-resize ${width[$size]}x${height[$size]} -write \"${destDir}/${fnNoExt}-${size:0:2}.$fnExt\" +delete "
72
-            let count++
73
-        fi
58
+function get_ext_fn () {
59
+    fnNoExt="${1%.*}"
60
+    fnExt="${1##*.}"
61
+    fnPath="${1%/*}"
62
+}
63
+
64
+function get_formats () {
65
+    local IFS=$'\n'
66
+    for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
67
+        get_ext_fn "$file"
68
+        test $fnExt = 'mp4' && continue
69
+        for size in ${!imgsize[@]}; do
70
+            if ! test -e "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" -a -z "$FORCE"; then
71
+                formats[$file]+="$size "
72
+                let total_ext++
73
+            fi
74
+        done
74 75
     done
75
-    if test -n "$format"; then
76
-        echo "$site/$file : $format"
77
-        if test -n "$LIST"; then
78
-            continue
79
-        fi
80
-        echo -n "please wait... "
81
-        cmd=$(sed -r 's/^(.+) -write (.*) \+delete $/\1 \2/' <<< $cmd)
82
-        eval $(echo -e nice -20 $cmd)
76
+}
77
+
78
+function calc_left () {
79
+    local format=(${formats[$file]})
80
+    unset formats[$file]
81
+    total_ext=$(( $total_ext - ${#format[@]} ))
82
+}
83
+
84
+declare -A formats
85
+get_formats
86
+
87
+if test -n "$LIST"; then
88
+    for file in ${!formats[@]}; do
89
+        echo "[${#formats[@]}/$total_ext] $file : ${formats[$file]}"
90
+        calc_left
91
+    done
92
+else
93
+    for file in ${!formats[@]}; do
94
+        unset cmd sleep_duration
95
+        get_ext_fn "$file"
96
+        for size in ${formats[$file]}; do
97
+            cmd+=(mpr:image -resize ${width[$size]}x${height[$size]} -write "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" +delete)
98
+            let sleep_duration++
99
+        done
100
+        printf "\r\033[K[${#formats[@]}/$total_ext] $file : ${formats[$file]}"
101
+        cmd[-1]="null:"
102
+        sudo -u www-data nice -20 convert \
103
+            -filter Lanczos -strip -auto-orient -quality 95 -interlace line -sampling-factor 4:2:2 \
104
+            "$site/$file" +write ${cmd[@]}
83 105
         for size in ${!imgsize[@]}; do
84
-            test -s "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" || echo "missing extension ${size:0:2}.$fnExt"
106
+            test -s "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" || echo -e "\nmissing extension ${size:0:2}.$fnExt"
85 107
         done
86
-        echo "done, sleeping..."
87
-        sleep $(( 2 + $count ))
88
-    fi
89
-done
108
+        sleep $sleep_duration
109
+        calc_left
110
+    done
111
+fi