X-Git-Url: http://git.plutz.net/?p=serve0;a=blobdiff_plain;f=indexmeta.sh;h=2da085f9a0bf86fcdb630f8fd98443df7d99c423;hp=2ac459fd484689e1a29979b512bf7b24eb792d20;hb=HEAD;hpb=ed3fecb0e3063d2812a082ea46afc33bb4b58820 diff --git a/indexmeta.sh b/indexmeta.sh old mode 100644 new mode 100755 index 2ac459f..87fbd12 --- a/indexmeta.sh +++ b/indexmeta.sh @@ -7,30 +7,22 @@ include_indexmeta="$0" file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$' meta_name() { - local fn - fn="$1" - fn="${fn##*/}" - fn="${fn%.*}" - STRING "$fn" - printf '\r' + local fn="${1##*/}" + STRING "${fn%.*}" } 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")" + probe="$(printf \\n; ffprobe -show_entries format=duration:stream=width,height "$video" 2>&-)" + l="${probe#*duration=}" l="${l%%${BR}*}" l="${l%.*}" + w="${probe#*width=}" w="${w%%${BR}*}" + h="${probe#*height=}" h="${h%%${BR}*}" + + printf '%i %i %i tags= comment= %s\r\n' \ + "${l:-0}" "${w:-0}" "${h:-0}" "$(meta_name "$video")" } meta_file(){ @@ -40,7 +32,7 @@ meta_file(){ name="$(meta_name "$file")" if [ -d "${meta%/meta}" ] && LOCK "$meta"; then - grep -avF " ${name}" "$meta" >"$meta.tmp" + grep -avF " ${name}${CR}" "$meta" >"$meta.tmp" meta_line "$file" \ | tee -a "$meta.tmp" mv "$meta.tmp" "$meta" @@ -55,24 +47,23 @@ meta_purge(){ name="$(meta_name "$file")" if [ -d "${meta%/meta}" ] && LOCK "$meta"; then - grep -avF " ${name}" "$meta" >"$meta.tmp" - grep -aF " ${name}" "$meta" >>"$meta.trash" - mv "$meta.tmp" "$meta" + grep -avF " ${name}${CR}" "$meta" >"${meta}.tmp" + grep -aF " ${name}${CR}" "$meta" >>"${meta}.trash" + mv "${meta}.tmp" "$meta" RELEASE "$meta" fi } meta_info(){ local file meta - file="$1" - meta="${file%/*}/.index/meta" + file="$1"; meta="${file%/*}/.index/meta" if [ -d "${meta%/meta}" ]; then - grep -aF " $(meta_name "$file")" "$meta" \ + grep -aF " $(meta_name "$file")${CR}" "$meta" \ | grep -m1 -axE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' \ || meta_file "$file" else - printf '0\t0\t0\ttags=\tcomment=\t\r' + printf '0\t0\t0\ttags=\tcomment=\t%s\r\n' "$(meta_name "$file")" fi } @@ -80,26 +71,30 @@ meta_dir(){ local dir meta v dir="${1}" meta="${dir}/.index/meta" + metat="${dir}/.index/meta.time" + + [ -f "$metat" ] || touch -d @0 "$metat" 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 v="$(line)"; do + | while read -r v; do meta_line "$v" done >"$meta" + touch "$metat" RELEASE "$meta" - elif [ -d "$dir/.index" -a "$dir" -nt "$meta" ] && LOCK "$meta"; then + elif [ -d "$dir/.index" -a "$dir" -nt "$metat" ] && LOCK "$meta"; then touch "$meta" - find "$dir" -type f -mindepth 1 -maxdepth 1 \ + find -L "$dir" -type f -newer "$metat" \ + -mindepth 1 -maxdepth 1 \ | grep -aE "$file_pattern" \ - | while v="$(line)"; do - if [ "$v" -nt "$meta" ]; then - grep -qF " $(meta_name "$v")" "$meta" \ - || meta_line "$v" - fi + | while read -r v; do + grep -qF " $(meta_name "$v")${CR}" "$meta" \ + || meta_line "$v" done >>"$meta" + touch "$metat" RELEASE "$meta" fi