From 41bef4fb0a0858fb50a6906cbbcf2dda936d6d05 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 14 Jan 2017 01:12:35 +0000 Subject: [PATCH] improved browse page (code improvements, page enumeration) svn path=/trunk/; revision=168 --- globals.sh | 2 +- pages/browse.sh | 141 ++++++++++++++++++--------------------- templates/browse.html.sh | 2 +- 3 files changed, 68 insertions(+), 77 deletions(-) diff --git a/globals.sh b/globals.sh index fed5215..d6dcefd 100755 --- a/globals.sh +++ b/globals.sh @@ -22,7 +22,7 @@ file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmv data_dirs cache meta mp4 videos thumbs trash transcoded -PAGE="${_GET[p]:-${PAGE:-list}}" +PAGE="${_GET[p]:-${PAGE:-browse}}" treeroot="${treeroot:-${_DATA}}" _GET[o]=$( validate "${_GET[o]}" 'Name|Date|Length' Name) diff --git a/pages/browse.sh b/pages/browse.sh index 95741af..9b3e866 100755 --- a/pages/browse.sh +++ b/pages/browse.sh @@ -53,47 +53,41 @@ category_selected(){ } _printVideo(){ - info="$1" - cache="${info%/*}/.index/${info##*/}.cache" - meta="${info%/*}/.index/${info##*/}.meta" - - if [ "$cache" -ont "$meta" ]; then - cat "$cache" - else - videofile="$info" - thumb="${info%/*}/.index/${info##*/}.jpg" - [ -f "$thumb" ] || genthumb "$videofile" "$thumb" - [ -f "$meta" ] || genmeta "$videofile" "$meta" - - { read -r length width height filename - read -r tags - } <"$meta" - length=$(validate "$length" '[0-9]+' 0) - width=$(validate "$width" '[0-9]+' 0) - height=$(validate "$height" '[0-9]+' 0) - - video="$(urlsafe "$info")" - thumb="$(urlsafe "$directory/.index/${info##*/}.jpg")" - linkinfo="$(urlsafe "${directory%/}/${info##*/}")" - htmlinfo="$(htmlsafe "${info##*/}")" - attrinfo="$(attribsafe "$info")" - - minutes="$(printf "%d:%02d" $(($length / 60)) $(($length % 60)) )" - - tee "$cache" < - -

${htmlinfo}

- - - ${minutes}min - ${width}x${height} - $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: \1:g') - + name="$1" + + video="${treeroot%/}/${directory%/}/${name}" + thumb="${treeroot%/}/${directory%/}/.index/${name}.jpg" + meta="${treeroot%/}/${directory%/}/.index/${name}.meta" + + [ -f "$thumb" ] || genthumb "$video" "$thumb" + [ -f "$meta" ] || genmeta "$video" "$meta" + + { read -r length width height filename + read -r tags + } <"$meta" + read length width height <<-EOF + $(validate "$length $width $height" '[0-9]+ [0-9]+ [0-9]+' "0 0 0") + EOF + + location="$(attribsafe "${directory%/}/${name}")" + thumblocation="$(attribsafe "${directory%/}/.index/${name}.jpg")" + display="$(htmlsafe "$name")" + + minutes="$(printf "%d:%02d" $(($length / 60)) $(($length % 60)) )" + + cat < + +

${display}

+ + + ${minutes}min + ${width}x${height} + $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: \1:g') + VIDEOend - fi } genlist(){ @@ -136,47 +130,44 @@ selectionlist() { fi } -thumblist() { - selectionlist \ - | sed -n "$page,$(($page + $pagesize - 1))p" \ - | while read line; do - _printVideo "$line" - done -} - -pagecount() { - printf "$(( $(selectionlist | wc -l) / $pagesize + 1 ))" +filelist(){ + dir="${treeroot%/}/${directory#/}" + + find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -printf "directory %P\n" \ + | sort + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -printf "video %P\n" \ + | grep -iE "$file_pattern" \ + | sort + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -printf "plain %P\n" \ + | grep -viE "$file_pattern" \ + | sort } -filelist(){ +thumblist(){ debug "Filelist with dir = $directory" [ -n "${directory#/}" ] && printf %s ".." - find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type d \ - | grep -v '.index' \ - | sort \ - | while read dir; do - name="${dir##*/}" - printf %s "$(htmlsafe "$name")" - done - - find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \ - | grep -E "$file_pattern" \ - | sort \ - | while read -r file; do - name="${file##*/}" - $indexed && _printVideo "$file" \ - || printf '%s' \ - "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")" - done - - find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \ - | grep -vE "$file_pattern" \ - | sort \ - | while read -r file; do - name="${file##*/}" - printf '%s' "$(htmlsafe "$name")" + filelist \ + | sed -n "$page,$(($page + $pagesize - 1))p" \ + | while read -r type name; do + case $type in + directory) + printf '%s\n' \ + "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")" + ;; + video) + $indexed && _printVideo "$name" \ + || printf '%s\n' \ + "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")" + ;; + plain) + printf '%s\n' "$(htmlsafe "$name")" + ;; + esac done } +pagecount() { + printf "$(( $(filelist | wc -l) / $pagesize + 1 ))" +} diff --git a/templates/browse.html.sh b/templates/browse.html.sh index 8bf29a3..a061ed1 100755 --- a/templates/browse.html.sh +++ b/templates/browse.html.sh @@ -54,7 +54,7 @@ cat < EOF - filelist + thumblist pages="$( seq 1 $(pagecount) \ -- 2.39.2