From 1e104f8cffd4766cc114ada45f18c7d07f291aa8 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 6 Sep 2014 17:29:40 +0000 Subject: [PATCH] speed up in filtering svn path=/trunk/; revision=4 --- actions/filter.sh | 37 ++++++++++++++++++++++++++++++++++++ pages/videoview.sh | 31 +++++++++++++++--------------- templates/filterdiag.html.sh | 4 ++-- 3 files changed, 54 insertions(+), 18 deletions(-) create mode 100755 actions/filter.sh diff --git a/actions/filter.sh b/actions/filter.sh new file mode 100755 index 0000000..84bd841 --- /dev/null +++ b/actions/filter.sh @@ -0,0 +1,37 @@ +#!/bin/zsh + +if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then +(head -c "${CONTENT_LENGTH}"; echo)|sed 's:&:\n:g;s:\r::g' |while read line; do + case "$line" in + type[0-9]=neg) + [ -z "$filters" ] && filters="!" + [ -n "$filters" ] && egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^!" + ;; + type[0-9]=pos) + egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^" + ;; + category=*) + category="$(sed 's/^category=//;s/+/ /g;s/%/\\x/g' <<<"$line")" + category="$(echo -e "${category}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)" + ;; + filter=*) + filter="$(sed 's/^filter=//;s/+/ /g;s/%/\\x/g' <<<"$line")" + filter="$(echo -e "${filter}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)" + egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|" + filters="${filters}${filter}" + ;; + cfilter=*) + cfilter="$(sed 's/^cfilter=//;s/+/ /g;s/%/\\x/g' <<<"$line")" + cfilter="$(echo -e "${cfilter}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)" + egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|" + [ -n "$cfilter" ] && filters="${filters}${category}:${cfilter}" + ;; + o=Name) order=Name;; + o=Date) order=Date;; + o=Length) order=Length;; + esac +done +fi + +echo "?o=${order}&f=${filters}" >>${DATA}/meta/recent +echo -n "Location: ?o=${order}&f=${filters}\n\n" diff --git a/pages/videoview.sh b/pages/videoview.sh index 4b15fe8..c3965a9 100755 --- a/pages/videoview.sh +++ b/pages/videoview.sh @@ -68,18 +68,17 @@ _printVideo(){ else tags="$(sed -n 2p "$meta")" thumb="${_DATA}/thumbs/$info.jpg" - head -n1 "$meta" |read length width height + head -n1 "$meta" |read length width height filename [ -z "$length" ] && length=0 [ -z "$width" ] && width=0 [ -z "$height" ] && height=0 -# reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )" +# 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" [ -L "$mpfake" ] || ln -s "../$video" "$mpfake" -# anchor=$(ls videos |grep -xA2 "$info" |tail -n1) video="$(echo "videos/$info" |sed 's/\?/\%6F/g')" thumb="$(echo "thumbs/$info.jpg" |sed 's/\?/%6F/g')" mpfake="$(echo "$info" |sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:mp4/\1.mp4:' |sed 's/\?/%6F/g')" @@ -90,7 +89,7 @@ _printVideo(){ tee "$cache" < - +
$info
@@ -115,11 +114,11 @@ thumblist() { if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then cat "$cache" else - filterex="p" + filterex="q0" for each in $(sed 's,\^, ,g' <<<"$filter"); do if egrep -q '^!' <<<"$each"; then this="$(sed 's,^!,,' <<<"$each")" - filterex="/${this}/q;{${filterex}}" + filterex="/${this}/q1;{${filterex}}" else filterex="/${each}/{${filterex}}" fi @@ -134,16 +133,16 @@ thumblist() { ;; esac - $genlist |while read video; do - #video="$(basename "$each")" - if [ -n "$search" ] ; then - egrep -iq "$search" <<<"$video" <"${_DATA}/meta/$video.meta" && (echo "$video" || exit 0) - elif [ "$filterex" != p ]; then - [ -n "$(sed -rn "2{$filterex}" "${_DATA}/meta/$video.meta")" ] && (echo "$video" || exit 0) - else - echo "$video" || exit 0 - fi - done |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache" + if [ -n "$search" ] ; then + #$genlist |egrep -i "$search" + $genlist |sed -rn 's:^(.+)$:'"${_DATA}"'/meta/\1'.meta':p' |xargs -d\\n egrep -sil "$search" |sed -rn 's:^(.*/)+([^/]+)\.meta$:\2:p' + elif [ "$filterex" != "q0" ]; then + $genlist |while read video; do + [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && echo "$video" + done + else + $genlist + fi |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache" fi | while read line; do _printVideo "$line" done diff --git a/templates/filterdiag.html.sh b/templates/filterdiag.html.sh index 006c876..5fbf2c3 100755 --- a/templates/filterdiag.html.sh +++ b/templates/filterdiag.html.sh @@ -2,7 +2,7 @@ cat < -
+ Order by: