]> git.plutz.net Git - serve0/commitdiff
speed up in filtering
authorpaul <paul@plutz.net>
Sat, 6 Sep 2014 17:29:40 +0000 (17:29 +0000)
committerpaul <paul@plutz.net>
Sat, 6 Sep 2014 17:29:40 +0000 (17:29 +0000)
svn path=/trunk/; revision=4

actions/filter.sh [new file with mode: 0755]
pages/videoview.sh
templates/filterdiag.html.sh

diff --git a/actions/filter.sh b/actions/filter.sh
new file mode 100755 (executable)
index 0000000..84bd841
--- /dev/null
@@ -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"
index 4b15fe8d0c708dd2b9e6c3716a1da4fc4eacd986..c3965a975f5323799bb7f82660164131da9adde3 100755 (executable)
@@ -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" <<VIDEOend
       <div class="thumb">
-        <a name="$info" href="?i=$info&p=$page&f=$filter&s=$search&o=$order#$anchor"><img src="$thumb"></a>
+        <a name="$info" href="?i=$info&p=$page&f=$filter&s=$search&o=$order#$info"><img src="$thumb"></a>
         <div class="thumbinfo">
           <a href="$video"><b>$info</b></a><br>
           <!-- a href="$reenc">VP8</a -->
@@ -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
index 006c876bee5aa69d3d651de8b4e6987c10119036..5fbf2c3d2228313af61bcca1f394b27f19f31bae 100755 (executable)
@@ -2,7 +2,7 @@
 
 cat <<FilterEnd
   <div class="panel" id="search" style="display: block;">
-    <form action="index.cgi" method="get" accept-charset="UTF-8">
+    <form action="?" method="get" accept-charset="UTF-8">
       <input type="text" name="s" value="$search" placeholder="Search">
       Order by:<select size="1" name="o">
        <option>Name</option>
@@ -28,7 +28,7 @@ cat <<FilterEnd
     <a class="panel" href="#" onclick="javascript:hide_block('advfilter');$(for n in {1..9}; do echo "hide_inline('filter$n');"; done)show_block('search')">Hide</a>
     <hr>
     Up to <b>10</b> filter boxes will appear as you start selecting tags. You can select <b>multiple</b> tags in each box by holding down the <b>Ctrl</b>-key. Click the "<b>Filter!</b>" button when you are ready.
-    <form action="filter.cgi" method="post" accept-charset="UTF-8">
+    <form action="?action=filter" method="post" accept-charset="UTF-8">
     $(for n in {0..9}; do
       hideall="$(sed -rn "s;^([^:]+):.*$;hide_inline('${n}_\\1')\\;;p" <<<"$taglist" |sort -u)hide_inline('${n}_none');"
       echo "