From c7e6e63b567cd68f0a9c1f12dd92b175d2f6a2a0 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 6 Sep 2014 19:04:08 +0000 Subject: [PATCH] tagging engine svn path=/trunk/; revision=5 --- actions/filter.sh | 2 +- actions/meta.sh | 54 +++++++++++++++++++++++++++++++++++++ actions/multitag.sh | 49 +++++++++++++++++++++++++++++++++ helpers/genall.sh | 41 ++++++++++++++++++++++++++++ helpers/genmeta.sh | 19 +++++++++++++ helpers/genthumb.sh | 33 +++++++++++++++++++++++ pages/videoview.sh | 5 ++-- templates/videoview.html.sh | 2 +- templates/view.html.sh | 4 +-- 9 files changed, 203 insertions(+), 6 deletions(-) create mode 100755 actions/meta.sh create mode 100755 actions/multitag.sh create mode 100755 helpers/genall.sh create mode 100755 helpers/genmeta.sh create mode 100755 helpers/genthumb.sh diff --git a/actions/filter.sh b/actions/filter.sh index 84bd841..94b87f2 100755 --- a/actions/filter.sh +++ b/actions/filter.sh @@ -33,5 +33,5 @@ if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then done fi -echo "?o=${order}&f=${filters}" >>${DATA}/meta/recent +echo "?o=${order}&f=${filters}" >>${_DATA}/meta/recent echo -n "Location: ?o=${order}&f=${filters}\n\n" diff --git a/actions/meta.sh b/actions/meta.sh new file mode 100755 index 0000000..b5fbe51 --- /dev/null +++ b/actions/meta.sh @@ -0,0 +1,54 @@ +#!/bin/zsh + +info="$_GET[\"i\"]" +file="{$DATA}/meta/$info.meta" + +if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then +(head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do + if (egrep -xq 'length=[0-9]{1,5}' <<<"${line}"); then + length="$(cut -d= -f2 <<<"${line}")" + elif (egrep -xq 'width=[0-9]{1,5}' <<<"${line}"); then + width="$(cut -d= -f2 <<<"${line}")" + elif (egrep -xq 'height=[0-9]{1,5}' <<<"${line}"); then + height="$(cut -d= -f2 <<<"${line}")" + elif (egrep -xq 'tag=.+' <<<"${line}"); then + tag="$(sed -r 's:^tag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")" + tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g')" + tagacc="$tag|$tagacc" + elif (egrep -xq 'tags=.+' <<<"${line}"); then + tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")" + tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g')" + elif (egrep -xq 'description=.+' <<<"${line}"); then + description="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')" + description="$(echo -e "${description}" |sed 's/\r//g;s/\\/\\\\/g;s//\>\;/g')" + elif (egrep -xq 'trash=.+' <<<"${line}"); then + trash="true" + elif (egrep -xq 'cancel=.+' <<<"${line}"); then + cancel="true" + elif (egrep -xq 'f=.+' <<<"${line}"); then + filter="$(cut -d= -f2- <<<"${line}")" + elif (egrep -xq 's=.+' <<<"${line}"); then + search="$(cut -d= -f2- <<<"${line}")" + elif (egrep -xq 'p=.+' <<<"${line}"); then + page="$(cut -d= -f2- <<<"${line}")" + elif (egrep -xq 'o=.+' <<<"${line}"); then + order="$(cut -d= -f2- <<<"${line}")" + fi +done +fi + +[ -z "$cancel" ] && if [ "$trash" = "true" ]; then + rm "${_DATA}/thumbs/$info.jpg" 2>/dev/null + mv "${_DATA}/videos/$info" "${_DATA}/meta/$info.meta" "${_DATA}/trash/" 2>/dev/null + rm "${_DATA}/cache/$info.cache" 2>/dev/null + rm ${_DATA}/cache/\?* 2>/dev/null +else + echo -e "$length\t$width\t$height\t$info" > "$file" + echo -e "${tagacc}${tags}" |tr '\n' '|' >> "$file" + echo >>"$file" + echo -e "${description}" >> "$file" + rm "${_DATA}/cache/$info.cache" 2>/dev/null + rm ${_DATA}/cache/\?* 2>/dev/null +fi + +echo -n "Location: index.cgi?i=&p=${page}&s=${search}&f=${filter}&o=${order}#$info\n\n" diff --git a/actions/multitag.sh b/actions/multitag.sh new file mode 100755 index 0000000..127a64e --- /dev/null +++ b/actions/multitag.sh @@ -0,0 +1,49 @@ +#!/bin/zsh + +addtag(){ + meta="$1" + tag="$2" + + length=0; width=0; height=0; + if [ -r "$meta" ]; then + head -n1 "$meta" |read length width height info + tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')" + description="$(sed -n '3,$p' "$meta")" + fi + + egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags" + + cat <"$meta" +$length $width $height $info +$tags +$description +EOF +} + +n=0 +if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then +(head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do + if expr "$line" : "tagsel=" >/dev/null; then + n=$(($n + 1)) + tagsel[$n]="$(echo -e "$(sed -nr 's:(^|&)tagsel=(.*)(&|$):\2:;s:&.*$::;s:\+: :g;s:%:\\x:g;p' <<<"$line" )")" + elif expr "$line" : "ctag=" >/dev/null; then + tag="$(sed -r 's:^ctag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")" + tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g')" + for i in {1..$n}; do + addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag" + rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null + done + elif expr "$line" : 'tags=.\+' >/dev/null; then + tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")" + tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g')" + for i in {1..$n}; do echo "$tags" |while read tag; do + addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag" + rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null + done; done + fi +done +fi + +rm ${_DATA}/cache/\?* 2>/dev/null + +echo -n "Location: index.cgi?${QUERY_STRING}#$info\n\n" diff --git a/helpers/genall.sh b/helpers/genall.sh new file mode 100755 index 0000000..6aab046 --- /dev/null +++ b/helpers/genall.sh @@ -0,0 +1,41 @@ +#!/bin/zsh + +dir="$(dirname $0)" +genmeta="$dir/genmeta.sh" +genthumb="$dir/genthumb.sh" +. "$dir/../constants.sh" + +addtag(){ + meta="$1" + info="$(basename "$1" |sed -r 's:^(.+)\.meta$:\1:')" + tag="$2" + + length=0; width=0; height=0; + if [ -r "$meta" ]; then + head -n1 "$meta" |read length width height info + tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')" + description="$(sed -n '3,$p' "$meta")" + fi + + egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags" + + cat <"$meta" +$length $width $height $info +$tags +$description +EOF +} + + +for each in *; do +if (egrep -q "$file_pattern" <<<"$each"); then + echo -n "$each ... Thumb ..." + $genthumb "$each" "${each}.jpg" + echo -n ' Meta ...' + $genmeta "$each" "${each}.meta" + echo -n ' Tags ...' + for tag in $*; do + addtag "${each}.meta" "$tag" + done + echo ' Done!' +fi; done diff --git a/helpers/genmeta.sh b/helpers/genmeta.sh new file mode 100755 index 0000000..805bde1 --- /dev/null +++ b/helpers/genmeta.sh @@ -0,0 +1,19 @@ +#!/bin/zsh + +video="$1" +meta="$2" + +if [ -r "$meta" ]; then + tags="$(sed -n 2p "$meta")" + description="$(sed -n '3,$p' "$meta")" +fi + +eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" |sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;') + +[ -z "$tags" ] && tags='|' + +cat <"$meta" +$length $width $height $(basename "$video") +$tags +$description +EOF diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh new file mode 100755 index 0000000..625b729 --- /dev/null +++ b/helpers/genthumb.sh @@ -0,0 +1,33 @@ +#!/bin/zsh + +video="$1" +thumb="$2" + +eval $(mplayer -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null |sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;') + +[ -z "$length" -o -z "$width" -o -z "$height" ] && exit 0 + +if [ "$(($height*1000/$width))" -gt "750" ]; then + width="$((75*$width/$height))" + height=75 +else + height="$((100*$height/$width))" + width=100 +fi +[ -z $width ] && width=100 +[ -z $height ] && height=100 +chunk="$(($length / 5))" + +for cnt in 1 2 3 4; do + debug mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" + mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null & + mpid="$!"; watch=0 + while (ps -p "$mpid" >/dev/null 2>/dev/null); do + [ "$watch" -gt 10 ] && kill -9 "$mpid" || sleep 1 + watch="$(($watch+1))" + done + cp -f 00000009.jpg "${thumb}-${cnt}.jpg" 2>/dev/null +done +montage "${thumb}-"[1234]".jpg" -tile 2x2+0+0 -geometry 100x75+3+3 -background "#000000" "${thumb}" 2>/dev/null +rm 000000[01][0-9].jpg "${thumb}-"[1234]".jpg" 2>/dev/null + diff --git a/pages/videoview.sh b/pages/videoview.sh index c3965a9..dacb524 100755 --- a/pages/videoview.sh +++ b/pages/videoview.sh @@ -54,6 +54,7 @@ view() { eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null\ | sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;') + video="videos/$info" . ${_EXEC}/templates/view.html.sh fi } @@ -76,8 +77,8 @@ _printVideo(){ # reenc="${_DATA}/vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )" mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )" # [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv" - [ -r "$meta" ] || ./genmeta.sh "$video" "$meta" - [ -r "$thumb" ] || ./genthumb.sh "$video" "$thumb" + [ -r "$meta" ] || ". ${_EXEC}/helpers/genmeta.sh" "$video" "$meta" + [ -r "$thumb" ] || ". ${_EXEC}/helpers/genthumb.sh" "$video" "$thumb" [ -L "$mpfake" ] || ln -s "../$video" "$mpfake" video="$(echo "videos/$info" |sed 's/\?/\%6F/g')" thumb="$(echo "thumbs/$info.jpg" |sed 's/\?/%6F/g')" diff --git a/templates/videoview.html.sh b/templates/videoview.html.sh index 504bfe0..cb0ed75 100755 --- a/templates/videoview.html.sh +++ b/templates/videoview.html.sh @@ -18,7 +18,7 @@ cat < +
$(thumblist)
$(tagger)
diff --git a/templates/view.html.sh b/templates/view.html.sh index c17284b..42f74ac 100755 --- a/templates/view.html.sh +++ b/templates/view.html.sh @@ -21,8 +21,8 @@ cat <