[ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
[ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
+file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$'
+
. "$_EXEC/cgilite/cgilite.sh"
. "$_EXEC/widgets.sh"
tag)
;;
thumbnail)
- printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'
+ . "$_EXEC/cgilite/file.sh"
+ index="$_DATA/${ITEM%/*}/.index"
+ thumb="$index/${ITEM##*/}.jpg"
+ [ -d "$index" -a \! -f "$thumb" ] \
+ && file="$_DATA/$ITEM" . "$_EXEC/thumbnail.sh"
+ FILE "$thumb"
;;
delete)
;;
list_item(){
name="$(HTML "$1")"
path="$(HTML "$ITEM/$1")"
+ meta="$_DATA/$ITEM/.index/meta"
if [ -d "$_DATA/$ITEM/$1" ]; then
printf '[a .list .dir href="%s" %s]' \
"$path" "$name"
+ elif [ -f "$meta" ]; then
+ read -r length width height tags comment n <<-EOF
+ $(grep -m1 -F " $1" "$meta")
+ EOF
+ printf '[div .list .file
+ [a href="%s" [img src="%s?a=thumbnail"] %s]
+ [span .time %i:%imin] [span .dim %ix%i] %s
+ ]' \
+ "$path" "$path" "$name" \
+ "$((length / 60))" "$((length % 60))" \
+ "$width" "$height" \
+ "$(printf %s\\n "${tags#tags=}" |tr , ' ' |xargs printf '[span .tag %s]')"
else
printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \
"$path" "$path" "$name"
[ "$mode" = browse -a "$ITEM" ] && printf '..\n'
if [ "$mode" = browse ]; then
- [ -d "$_DATA/$ITEM/.index" -a "$_DATA/$ITEM" -nt "$_DATA/$ITEM/.index/meta" ] \
- && . "$_EXEC/update_meta.sh"
+ [ -d "$_DATA/$ITEM/.index" -a \! "$_DATA/$ITEM" -ot "$_DATA/$ITEM/.index/meta" ] \
+ && dir="$_DATA/$ITEM" . "$_EXEC/update_meta.sh"
(cd "$_DATA/$ITEM";
find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \
-exec stat -c '%Y %n' '{}' +
-exec stat -c '%Y %n' '{}' +
)
elif [ "$mode" = index ]; then
+ find "$_DATA/$ITEM" -type d -name .index \
+ | while d="$(line)"; do
+ [ ! "${d%/.index}" -ot "$d/meta" ] \
+ && dir="${d%/.index}" . "$_EXEC/update_meta.sh"
+ done
(cd "$_DATA/$ITEM";
find ./ -type f \
-exec stat -c '%Y %n' '{}' +
--- /dev/null
+#!/bin/sh
+
+# Use: $index $thumb $file_pattern
+
+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
+
+ [ "$((h * 1000 / w))" -gt "750" ] \
+ && w="$((75 * w / h))" || w=100
+ 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,scale=${w}:-2" \
+ -vo "jpeg: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=127:-2,tile=2:2:4:0:2 \
+ -vo "jpeg:quality=60:outdir=${tmp}"\
+ "mf://$tmp/_*.jpg" 2>&-
+
+ mv "${tmp}/00000001.jpg" "$thumb"
+ rm -r "${tmp}"
+
+elif [ \! -e "$thumb" ]; then
+ touch "$thumb"
+fi
--- /dev/null
+#!/bin/sh
+
+file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$'
+meta="${dir}/.index/meta"
+
+meta_line() {
+ video="$1"
+
+ 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" "$w" "$h" "${video##*/}"
+}
+
+
+if [ \! -f "$meta" ]; then
+ find "$dir" -type f -mindepth 1 -maxdepth 1 \
+ | grep -E "$file_pattern" \
+ | while v="$(line)"; do
+ meta_line "$v"
+ done >"$meta"
+else
+ find "$dir" -type f -mindepth 1 -maxdepth 1 \
+ | grep -E "$file_pattern" \
+ | while v="$(line)"; do
+ if [ "$v" -nt "$meta" ]; then
+ grep -qF " ${v}" "$meta" \
+ || meta_line "$v"
+ fi
+ done >>"$meta"
+fi