]> git.plutz.net Git - serve0/blobdiff - indexmeta.sh
use ffprobe for reading video meta data, dropping dependency on mplayer
[serve0] / indexmeta.sh
index 2da085f9a0bf86fcdb630f8fd98443df7d99c423..50d83ef1b867f30e15aeb0f6861c5fd53de6cc32 100644 (file)
@@ -13,21 +13,17 @@ meta_name() {
 }
 
 meta_line() {
-  local video l w h
+  local video probe l w h
   video="$1"
+  [ "${video%.part}" = "$video" -a -s "$video" ] || return 0
 
-  read l h w <<__EOF
-  $(printf '' \
-    | mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" 2>&- \
-    | sort | sed -rn '
-      s:ID_LENGTH=(.*)(\..*)$:\1:p;
-      s:ID_VIDEO_HEIGHT=(.*):\1:p;
-      s:ID_VIDEO_WIDTH=(.*):\1:p;' \
-    | tr '\n' ' '
-  )
-__EOF
-  printf '%i\t%i\t%i\ttags=\tcomment=\t%s\n' \
-         "${l-0}" "${w-0}" "${h-0}" "$(meta_name "$video")"
+  meta="$(printf \\n; ffprobe -show_entries format=duration:stream=width,height 2>&-)"
+  l="${probe#*duration=}" l="${l%%${BR}*}"
+  w="${probe#*width=}"    w="${w%%${BR}*}"
+  h="${probe#*height=}"   h="${h%%${BR}*}"
+
+  printf '%i   %i      %i      tags=   comment=        %s\n' \
+         "${l:-0}" "${w:-0}" "${h:-0}" "$(meta_name "$video")"
 }
 
 meta_file(){
@@ -82,24 +78,23 @@ meta_dir(){
 
   if [ -d "$dir/.index" -a \! -f "$meta" ] && LOCK "$meta"; then
     touch "$meta"  # preliminary touch to prevent concurrent generators
-    find "$dir" -type f -mindepth 1 -maxdepth 1 \
+    find -L "$dir" -type f -mindepth 1 -maxdepth 1 \
     | grep -aE "$file_pattern" \
     | while read -r v; do
       meta_line "$v"
     done >"$meta"
+    touch "$metat"
 
     RELEASE "$meta"
   elif [ -d "$dir/.index" -a "$dir" -nt "$metat" ] && LOCK "$meta"; then
-    cp -p "$meta" "$meta.ref"; touch "$meta"
-    find "$dir" -type f -newer "$metat" \
+    touch "$meta"
+    find -L "$dir" -type f -newer "$metat" \
          -mindepth 1 -maxdepth 1 \
     | grep -aE "$file_pattern" \
     | while read -r v; do
       grep -qF "       $(meta_name "$v")" "$meta" \
       || meta_line "$v"
     done >>"$meta"
-    sort -u "$meta" >"$meta.ref"
-    mv "$meta.ref" "$meta"
     touch "$metat"
 
     RELEASE "$meta"