]> git.plutz.net Git - serve0/commitdiff
code improvements
authorPaul Hänsch <paul@plutz.net>
Mon, 6 Aug 2018 17:37:48 +0000 (19:37 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 6 Aug 2018 17:37:48 +0000 (19:37 +0200)
index.cgi
thumbnail.sh

index 421b81e95ece53ff9c0c58f096518b596062bb0c..4d7e8aa6fc045cdd1f49a29637d8b664917b3df4 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -42,6 +42,10 @@ case $ACTION in
     fi
     REDIRECT "$(POST ref)"
   ;;
+  multitag)
+    . "$_EXEC/multitag.sh"
+    REDIRECT "$(POST ref)"
+  ;;
 esac
 
 if [ "$ITEM" = "/style.css" ]; then
@@ -53,14 +57,14 @@ elif [ "$ITEM" = "/stereoview.js" ]; then
   FILE "$_EXEC/stereoview.js"
 elif [ -f "$_DATA/$ITEM" ]; then
   case $ACTION in
-    tag)
-    ;;
     thumbnail)
       . "$_EXEC/cgilite/file.sh"
+      . "$_EXEC/thumbnail.sh"
       index="$_DATA/${ITEM%/*}/.index"
       thumb="$index/${ITEM##*/}"; thumb="${thumb%.*}.jpg"
-      [ -d "$index" -a \! -f "$thumb" ] \
-      && file="$_DATA/$ITEM" . "$_EXEC/thumbnail.sh"
+      [ -d "$index" -a ! -f "$thumb" ] \
+      && { printf %s "$ITEM" |grep -qE -e "${file_pattern}" ;} \
+      && gen_thumb "$_DATA/$ITEM" "$thumb"
       FILE "$thumb"
     ;;
     delete)
@@ -85,10 +89,6 @@ elif [ -d "$_DATA/$ITEM" ]; then
       fi
       REDIRECT "$(POST ref)"
     ;;
-    multitag)
-      . "$_EXEC/multitag.sh"
-      REDIRECT "$(POST ref)"
-    ;;
     *) . "$_EXEC/list.sh"
     ;;
   esac
index 4e3fd3fb6298c4fcecef63f362d8edd7290a2ba2..143077640c049f1c35dbfbc0584607855cf6986a 100644 (file)
@@ -1,44 +1,42 @@
 #!/bin/sh
 
-# Use: $index $thumb $file_pattern
+[ -n "$include_thumbnails" ] && return 0
+include_thumbnails="$0"
 
-if [ \! -e "$thumb" ] && { printf %s "$file" |grep -qE "$file_pattern"; }; then
-  read l h w <<__EOF
-  $(printf '' \
-    | mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$file" 2>&- \
-    | sort | sed -rn '
-      s:ID_LENGTH=(.*)(\..*)$:\1:p;
-      s:ID_VIDEO_HEIGHT=(.*):\1:p;
-      s:ID_VIDEO_WIDTH=(.*):\1:p;' \
-    | tr '\n' ' '
-  )
-__EOF
+gen_thumb(){
+  file="$1"; thumb="$2";
 
-  [ "$((h * 1000 / w))" -gt "750" ] \
-  && w="$((75 * w / h))" || w=100
-  chunk="$((${l:-10} / 5))"
+  if [ ! -e "$thumb" ] && [ -f "$file" ]; then
+    l="$(
+      printf '' \
+      | mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$file" 2>&- \
+      | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p;' \
+    )"
   
-  tmp="$(mktemp -d)"
-  for cnt in 1 2 3 4; do
+    chunk="$((${l:-10} / 5))"
+    
+    tmp="$(mktemp -d)"
+    for cnt in 1 2 3 4; do
+      printf '' \
+      | mplayer -input nodefault-bindings -nosound -benchmark \
+                -noconfig all -really-quiet \
+                -frames 1 -ss "$((cnt * chunk))" \
+                -vf framestep=I \
+                -vo jpeg:quality=100:outdir="${tmp}" \
+                "$file" 2>&-
+      mv "${tmp}/00000001.jpg" "${tmp}/_${cnt}.jpg"
+    done
     printf '' \
     | mplayer -input nodefault-bindings -nosound -benchmark \
               -noconfig all -really-quiet \
-              -frames 1 -ss "$((cnt * chunk))" \
-              -vf "framestep=I,scale=${w}:-2" \
-              -vo "jpeg:quality=100:outdir=${tmp}" \
-              "$file" 2>&-
-    mv "${tmp}/00000001.jpg" "${tmp}/_${cnt}.jpg"
-  done
-  printf '' \
-  | mplayer -input nodefault-bindings -nosound -benchmark \
-            -noconfig all -really-quiet \
-            -vf scale=159:-2,tile=2:2:4:0:2 \
-            -vo "jpeg:quality=96:outdir=${tmp}"\
-            "mf://$tmp/_*.jpg" 2>&-
-
-  mv "${tmp}/00000001.jpg" "$thumb"
-  rm -r "${tmp}"
-
-elif [ \! -e "$thumb" ]; then
-  touch "$thumb"
-fi
+              -vf scale=159:-2,tile=2:2:4:0:2 \
+              -vo jpeg:quality=96:outdir="${tmp}"\
+              "mf://$tmp/_*.jpg" 2>&-
+  
+    mv "${tmp}/00000001.jpg" "$thumb"
+    rm -r "${tmp}"
+  
+  elif [ ! -e "$thumb" ]; then
+    touch "$thumb"
+  fi
+}