#!/bin/zsh
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
#
# This file is part of Serve0.
#
# You should have received a copy of the GNU Affero General Public License
# along with Serve0. If not, see <http://www.gnu.org/licenses/>.
+page_link="p=list&"
+
. $_EXEC/pages/common.sh
LF='
filters="${_GET[f]}"
debug "FILTERS: $filters"
-present_filter(){ printf %s "$*" |sed -r 's;(^|!|\^|\|)([^!\^\|:]+:);\1;g;s;\^; \&\; ;g' }
+present_filter(){
+ printf %s\\n "$*" \
+ | sed -r 's;(^|!|\^|\|)([^!\^\|:]+:);\1;g;s;\^;\n;g' \
+ | sort -r \
+ | sed -r '$q;s;$; \&\; ;g'
+}
if [ -n "$search" ]; then
TITLE="$search by $order"
TITLE="List by $order"
fi
-quicklinks(){
- output=''
- tac ${_DATA}/meta/recent \
- | while [ "$(printf %s "$output" |wc -l)" -lt 10 ] && read line; do
- printf %s "$output" |grep -qF "$line" || output="$output$line$LF"
- done
- printf %s "$output" |while read line; do
- linef=$(printf %s "$line" |sed -r 's;^.*(\?|&)f=([^&]+)&?.*$;\2;g')
- lineo=$(printf %s "$line" |sed -r 's;^.*(\?|&)o=([^&]+)&?.*$;\2;g')
- printf %s "<a href="$line">by ${lineo}: $(present_filter "$linef")</a>"
- done
-}
-
category_selected(){
cat="${1}:"
filter="$2"
[ "$cat" = "none:" ] && cat=''
- printf %s "$taglist" \
+ printf %s "$taglist_filter" \
| sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \
| sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
| sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
thumb="$(urlsafe "thumbs/$info.jpg")"
linkinfo="$(urlsafe "$info")"
htmlinfo="$(htmlsafe "$info")"
+ attrinfo="$(attribsafe "$info")"
- [ "$(($length % 60))" -lt 10 ] && minutes="$(($length / 60)):0$(($length % 60))" \
- || minutes="$(($length / 60)):$(($length % 60))"
+ minutes="$(printf "%d:%02d" $(($length / 60)) $(($length % 60)) )"
tee "$cache" <<VIDEOend
- <li class="thumb">
- <a class="watchlink" name="${linkinfo}" href="?action=watch&i=${linkinfo}">
+ <li id="$attrinfo" class="thumb">
+ <button class="watchlink" name="${linkinfo}" formaction="?action=watch&i=${linkinfo}">
<img src="$thumb" alt="Preview not yet available">
- </a>
- <h2>${htmlinfo}</h2>
+ </button>
+ <h2><a href="?action=watch&i=${linkinfo}">${htmlinfo}</a></h2>
<input type="checkbox" name="tagsel" value="${htmlinfo}">
<span class="info property">${minutes}min</span>
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;;';;
- Name) printf '%s\n' "${_DATA}"/videos/* |sed -r 's;^.*/;;;';;
+ 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;;'
+ | while read file; do
+ [ -f "${_DATA}/videos/${file}" ] && printf '%s\\n' "$file"
+ done
+ ;;
+ Name)
+ find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf '%f\n' \
+ | sort -f \
+ | egrep -i "$file_pattern"
+ ;;
esac
}
-thumblist() {
- cache="${_DATA}/cache/${pagesize}?o=${order}&s=${search}&f=${filter}&pn=${page}"
- if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
+selectionlist() {
+ cachebase="?o=${order}&s=${search//\//}&f=${filter//\//}"
+ cache="${_DATA}/cache/${cachebase}"
+ if [ -s "$cache" -a "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
cat "$cache"
else
filterex="s;^([0-9]+\t){3}(.+)\n.*$;\2;p"
printf '%s\n' "$filter" |tr '^' '\n' \
+ | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \
| while read each; do
[ "${each:0:1}" = '!' ] && filterex="/^[^\n]+\n(.*\|)?(${each#?})(\|.*)?$/d;{${filterex}}" \
|| filterex="/^[^\n]+\n(.*\|)?(${each})(\|.*)?$/{${filterex}}"
debug "No search or filtering"
cat
fi \
- | sed -n "$page,$(($page + $pagesize - 1))p" \
| tee "$cache"
- fi \
+ fi
+}
+
+thumblist() {
+ selectionlist \
+ | sed -n "$page,$(($page + $pagesize - 1))p" \
| while read line; do
_printVideo "$line"
done
}
+
+pagecount() {
+ printf "$(( $(selectionlist | wc -l) / $pagesize + 1 ))"
+}