From ccaf72a1f346a69d88af2c74242e10cd6a90eecb Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 14 Jan 2017 13:10:19 +0000 Subject: [PATCH] enabled sorting in browse page svn path=/trunk/; revision=171 --- pages/browse.sh | 86 +++++++++++++++++++++++++++------------- templates/browse.html.sh | 3 +- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/pages/browse.sh b/pages/browse.sh index e46023a..adde4d8 100755 --- a/pages/browse.sh +++ b/pages/browse.sh @@ -19,10 +19,8 @@ . $_EXEC/pages/common.sh -LF=' -' directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)" -[ -d "${treeroot}/${directory#/}/.index" ] && indexed=true || indexed=false +[ -d "${treeroot%/}${directory%/}/.index" ] && indexed=true || indexed=false filters="${_GET[f]}" debug "FILTERS: $filters" @@ -57,9 +55,9 @@ category_selected(){ _printVideo(){ name="$1" - video="${treeroot%/}/${directory%/}/${name}" - thumb="${treeroot%/}/${directory%/}/.index/${name}.jpg" - meta="${treeroot%/}/${directory%/}/.index/${name}.meta" + 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" @@ -92,14 +90,6 @@ _printVideo(){ VIDEOend } -genlist(){ - case "$order" in - Date) find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf '%T@ %f\n' |sort -r |cut -d\ -f2- |egrep -i "$file_pattern";; - Length) sed -sn 1p "${_DATA}"/meta/*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';; - Name) find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf '%f\n' |sort |egrep -i "$file_pattern";; - esac -} - selectionlist() { cachebase="?o=${order}&s=${search//\//}&f=${filter//\//}" cache="${_DATA}/cache/${cachebase}" @@ -133,16 +123,56 @@ selectionlist() { } 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 + dir="${treeroot%/}${directory%/}" + + case "$order" in + Name) + find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -print0 \ + | sort -z \ + | xargs -0 printf 'directory %s\n' + + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \ + | grep -ziE "$file_pattern" \ + | sort -z \ + | xargs -0 printf 'video %s\n' + + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \ + | grep -zviE "$file_pattern" \ + | sort -z \ + | xargs -0 printf 'plain %s\n' + ;; + Date) + find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -print0 \ + | xargs -0 stat -c '%Z directory %n' \ + | sort -r |cut -c12- + + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \ + | grep -ziE "$file_pattern" \ + | xargs -0 stat -c '%Y video %n' \ + | sort -r |cut -c12- + + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \ + | grep -zviE "$file_pattern" \ + | xargs -0 stat -c '%Y plain %n' \ + | sort -r |cut -c12- + ;; + Length) + find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -print0 \ + | sort -z \ + | xargs -0 printf 'directory %s\n' + + head -qn1 "${dir}"/.index/*.meta \ + | sort \ + | cut -f4- \ + | tr \\n \\0 \ + | xargs -0 printf 'video %s\n' + + find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \ + | grep -zviE "$file_pattern" \ + | sort -z \ + | xargs -0 printf 'plain %s\n' + ;; + esac } thumblist(){ @@ -156,15 +186,15 @@ thumblist(){ case $type in directory) printf '%s\n' \ - "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")" + "$(urlsafe "${directory%/}/${name##*/}")" "$(htmlsafe "${name##*/}")" ;; video) - $indexed && _printVideo "$name" \ + $indexed && _printVideo "${name##*/}" \ || printf '%s\n' \ - "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")" + "$(urlsafe "${directory%/}/${name##*/}")" "$(htmlsafe "${name##*/}")" ;; plain) - printf '%s\n' "$(htmlsafe "$name")" + printf '%s\n' "$(htmlsafe "${name##*/}")" ;; esac done diff --git a/templates/browse.html.sh b/templates/browse.html.sh index a061ed1..ff1944e 100755 --- a/templates/browse.html.sh +++ b/templates/browse.html.sh @@ -19,7 +19,8 @@ cat <