From 74ff372bee75fb6f9f09014533a2494a9791a9f2 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 6 Sep 2014 15:44:44 +0000 Subject: [PATCH] changed caching method from per-page to per-file cache, some bug fixes svn path=/trunk/; revision=3 --- constants.sh | 1 + pages/videoview.sh | 165 ++++++++++++++++++++-------------------- templates/frame.html.sh | 2 +- 3 files changed, 86 insertions(+), 82 deletions(-) diff --git a/constants.sh b/constants.sh index 33cce96..ffd1e90 100755 --- a/constants.sh +++ b/constants.sh @@ -20,3 +20,4 @@ alias _wiki="stx2any --no-template --link-abbrevs --quote -T html" _GET["page"]=videoview pagesize=100 +file_pattern='^.*(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso)$' diff --git a/pages/videoview.sh b/pages/videoview.sh index 7e1d23d..4b15fe8 100755 --- a/pages/videoview.sh +++ b/pages/videoview.sh @@ -17,13 +17,20 @@ # You should have received a copy of the GNU Affero General Public License # along with Serve0. If not, see . -info="$_GET[i]" -filter="$_GET[f]" -search="$_GET[s]" -order=$(echo "$_GET[o]" |egrep '^(Name|Date|Length)$') -page=$(echo "$_GET[p]" |egrep '^[0-9]+$') +info="$_GET[\"i\"]" +filter="$_GET[\"f\"]" +search="$_GET[\"s\"]" +order=$(echo "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$') +page=$(echo "$_GET[\"p\"]" |egrep '^[0-9]+$') [ -z "$page" ] && page=0 +taglist=$( + [ -r ${_DATA}/cache/taglist ] && cat ${_DATA}/cache/taglist ||\ + for each in ${_DATA}/meta/*.meta; do + sed -n '2s:|:\n:gp' "$each" + done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist +) + filterdiag() { . ${_EXEC}/templates/filterdiag.html.sh } @@ -47,103 +54,99 @@ 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;') - taglist=$( - [ -r ${_DATA}/cache/taglist ] && cat ${_DATA}/cache/taglist ||\ - for each in ${_DATA}/meta/*.meta; do - sed -n '2s:|:\n:gp' "$each" - done |sort -u |grep -xv '' |tee cache/taglist - ) - . ${_EXEC}/templates/view.html.sh fi } _printVideo(){ info="$1" + cache="${_DATA}/cache/$info.cache" + video="${_DATA}/videos/$info" meta="${_DATA}/meta/$info.meta" - tags="$(sed -n 2p "$meta")" - thumb="${_DATA}/thumbs/$info.jpg" - head -n1 "$meta" |read length width height - [ -z "$length" ] && length=0 - [ -z "$width" ] && width=0 - [ -z "$height" ] && height=0 + if [ "$cache" -nt "$video" -a "$cache" -nt "$meta" ]; then + cat "$cache" + else + tags="$(sed -n 2p "$meta")" + thumb="${_DATA}/thumbs/$info.jpg" + head -n1 "$meta" |read length width height + [ -z "$length" ] && length=0 + [ -z "$width" ] && width=0 + [ -z "$height" ] && height=0 - video="${_DATA}/videos/$info" -# reenc="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 "$video" |sed 's/\?/\%6F/g')" - thumb="$(echo "$thumb" |sed 's/\?/%6F/g')" - mpfake="$(echo "$mpfake" |sed 's/\?/%6F/g')" +# reenc="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')" - [ "$(($length % 60))" -lt 10 ] &&\ - minutes="$(($length / 60)):0$(($length % 60))" ||\ - minutes="$(($length / 60)):$(($length % 60))" + [ "$(($length % 60))" -lt 10 ] &&\ + minutes="$(($length / 60)):0$(($length % 60))" ||\ + minutes="$(($length / 60)):$(($length % 60))" - cat < - -
- $info
- - fake-mp4
- - ${minutes}min - ${width}x${height}
- - $(sed 's,|$,,;s,|, ,g' <<<"$tags") + tee "$cache" < + +
+ $info
+ + fake-mp4
+ + ${minutes}min + ${width}x${height}
+ + $(sed 's,|$,,;s,|, ,g' <<<"$tags") +
- VIDEOend + fi } -_by_name(){ ls ${_DATA}/videos/ } -_by_date(){ ls -c ${_DATA}/videos/ } +_by_name(){ ls ${_DATA}/videos/ |egrep -i "$file_pattern" } +_by_date(){ ls -c ${_DATA}/videos/ |egrep -i "$file_pattern" } _by_length(){ ls ${_DATA}/by_length/ |sed -r 's:[0-9]{5} - ::g' } thumblist() { cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&p=${page}" - [ -f "$cache" ] && [ "$cache" -ot ${_DATA}/videos -o "$cache" -ot ${_DATA}/meta ] && rm "$cache" - if [ -r "$cache" ]; then + if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then cat "$cache" - exit 0 - fi - - filterex="p" - for each in $(sed 's,\^, ,g' <<<"$filter"); do - if egrep -q '^!' <<<"$each"; then - this="$(sed 's,^!,,' <<<"$each")" - filterex="/${this}/q;{${filterex}}" - else - filterex="/${each}/{${filterex}}" - fi - done - - case "$order" in - Date) genlist="_by_date" - ;; - Length) genlist="_by_length" - ;; - *) genlist="_by_name" - ;; - esac + else + filterex="p" + for each in $(sed 's,\^, ,g' <<<"$filter"); do + if egrep -q '^!' <<<"$each"; then + this="$(sed 's,^!,,' <<<"$each")" + filterex="/${this}/q;{${filterex}}" + else + filterex="/${each}/{${filterex}}" + fi + done - $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 | while read line; do + case "$order" in + Date) genlist="_by_date" + ;; + Length) genlist="_by_length" + ;; + *) genlist="_by_name" + ;; + 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" + fi | while read line; do _printVideo "$line" - done |tee "$cache" + done } case "$1" in diff --git a/templates/frame.html.sh b/templates/frame.html.sh index b6363d0..822659b 100755 --- a/templates/frame.html.sh +++ b/templates/frame.html.sh @@ -20,7 +20,7 @@ cat < - $($PAGE title) + $(. $PAGE title)