From: paul Date: Sat, 1 Aug 2015 13:45:55 +0000 (+0000) Subject: much faster filtering X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=1fa16d769f765fab3eab88bdc14ecf6adf299347;p=serve0 much faster filtering svn path=/trunk/; revision=70 --- diff --git a/actions/watch.sh b/actions/watch.sh index c0cdb37..46fc795 100755 --- a/actions/watch.sh +++ b/actions/watch.sh @@ -48,7 +48,7 @@ case "${_COOKIE[watch]}" in redirect "$videourl" ;; server) - DISPLAY=:0 nohup /usr/bin/mplayer -ao pulse:jupiter --quiet "${_DATA}/videos/$info" >&- 2>&- & + DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null & redirect "$HTTP_REFERER" ;; *) redirect "?p=view&${watch_link}" diff --git a/pages/common.sh b/pages/common.sh index 9e659bf..377e5f5 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -81,45 +81,41 @@ VIDEOend fi } -_by_name(){ find ${_DATA}/videos/ -mindepth 1 -maxdepth 1 -printf '%f\n' |sort |egrep -i "$file_pattern" } -_by_date(){ ls -c ${_DATA}/videos/ |egrep -i "$file_pattern" } -_by_length(){ find ${_DATA}/by_length/ -mindepth 1 -maxdepth 1 -printf '%f\n' |sort |sed -r 's:[0-9]{5} - ::' } +genlist(){ + case "$order" in + Date) ls -c ${_DATA}/videos/ |egrep -i "$file_pattern";; + Length) sed -sn 1p "${_DATA}/meta/"*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';; + *) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';; + esac +} thumblist() { cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&pn=${page}" if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then cat "$cache" else - filterex="q0" - for each in $(sed 's,\^, ,g' <<<"$filter"); do - if egrep -q '^!' <<<"$each"; then - this="$(sed 's,^!,,' <<<"$each")" - filterex="/${this}/q1;{${filterex}}" - else - filterex="/${each}/{${filterex}}" - fi + filterex="s;^([0-9]+\t){3}(.+)\n.*$;\2;p" + printf '%s\n' "$filter" |tr '^' '\n' \ + | while read each; do + [ "${each:0:1}" = '!' ] && filterex="/^[^\n]+\n(.*\|)?(${each#?})(\|.*)?$/d;{${filterex}}" \ + || filterex="/^[^\n]+\n(.*\|)?(${each})(\|.*)?$/{${filterex}}" done - - case "$order" in - Date) genlist="_by_date" - ;; - Length) genlist="_by_length" - ;; - *) genlist="_by_name" - ;; - esac - 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' + genlist \ + | if [ -n "$search" ] ; then + xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \ + | xargs -d '\n' egrep -sil "$search" \ + | sed -r 's;^.*/;;;s;\.meta$;;' elif [ "$filterex" != "q0" ]; then - $genlist |while read video; do - [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && printf '%s\n' "$video" - done + xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \ + | xargs -d '\n' sed -srn ":a;N;2!ba;{${filterex}}" else - $genlist - fi |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache" - fi | while read line; do + cat + fi \ + | sed -n "$(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p" \ + | tee "$cache" + fi \ + | while read line; do _printVideo "$line" done }