3 # Copyright 2014 - 2017 Paul Hänsch
5 # This file is part of Serve0.
7 # Serve0 is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Serve0 is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Serve0. If not, see <http://www.gnu.org/licenses/>.
22 . $_EXEC/pages/common.sh
27 debug "FILTERS: $filters"
31 | sed -r 's;(^|!|\^|\|)([^!\^\|:]+:);\1;g;s;\^;\n;g' \
33 | sed -r '$q;s;$; \&\; ;g'
36 if [ -n "$search" ]; then
37 TITLE="$search by $order"
38 elif [ -n $filter ]; then
39 TITLE="$(present_filter "$filter") by $order"
41 TITLE="List by $order"
47 [ "$cat" = "none:" ] && cat=''
49 printf %s "$taglist_filter" \
50 | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \
51 | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
52 | sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
57 cache="${_DATA}/cache/$info.cache"
58 meta="${_DATA}/meta/$info.meta"
60 if [ "$cache" -nt "$meta" ]; then
63 videofile="${_DATA}/videos/$info"
64 thumb="${_DATA}/thumbs/${info}.jpg"
65 [ -r "$thumb" ] || genthumb "$videofile" "$thumb"
66 [ -r "$meta" ] || genmeta "$videofile" "$meta"
68 head -n1 "$meta" |read length width height filename
69 length=$(validate "$length" '[0-9]+' 0)
70 width=$(validate "$width" '[0-9]+' 0)
71 height=$(validate "$height" '[0-9]+' 0)
73 tags="$(sed -n 2p "$meta")"
74 video="$(urlsafe "videos/$info")"
75 thumb="$(urlsafe "thumbs/$info.jpg")"
76 linkinfo="$(urlsafe "$info")"
77 htmlinfo="$(htmlsafe "$info")"
78 attrinfo="$(attribsafe "$info")"
80 minutes="$(printf "%d:%02d" $(($length / 60)) $(($length % 60)) )"
82 tee "$cache" <<VIDEOend
83 <li id="$attrinfo" class="thumb">
84 <button class="watchlink" name="${linkinfo}" formaction="?action=watch&i=${linkinfo}">
85 <img src="$thumb" alt="Preview not yet available">
87 <h2><a href="?action=watch&i=${linkinfo}">${htmlinfo}</a></h2>
89 <input type="checkbox" name="tagsel" value="${htmlinfo}">
90 <span class="info property">${minutes}min</span>
91 <span class="info property">${width}x${height}</span>
92 $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: <span class="info tag">\1</span>:g')
100 Date) find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf '%T@ %f\n' |sort -r |cut -d\ -f2- |egrep -i "$file_pattern";;
101 Length) sed -sn 1p "${_DATA}"/meta/*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';;
102 Name) find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf '%f\n' |sort |egrep -i "$file_pattern";;
107 cachebase="?o=${order}&s=${search//\//}&f=${filter//\//}"
108 cache="${_DATA}/cache/${cachebase}"
109 if [ -s "$cache" -a "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
112 filterex="s;^([0-9]+\t){3}(.+)\n.*$;\2;p"
113 printf '%s\n' "$filter" |tr '^' '\n' \
114 | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \
115 | while read each; do
116 [ "${each:0:1}" = '!' ] && filterex="/^[^\n]+\n(.*\|)?(${each#?})(\|.*)?$/d;{${filterex}}" \
117 || filterex="/^[^\n]+\n(.*\|)?(${each})(\|.*)?$/{${filterex}}"
121 | if [ -n "$search" ] ; then
122 debug "Applying search: ${search}"
123 xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
124 | xargs -d '\n' egrep -sil "$search" \
125 | sed -r 's;^.*/;;;s;\.meta$;;'
126 elif [ -n "$filter" ]; then
127 debug "Applying filters: ${filter} ++ ${filterex}"
128 xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
129 | xargs -d '\n' sed -srn ":a;N;2!ba;{${filterex}}"
131 debug "No search or filtering"
140 | sed -n "$page,$(($page + $pagesize - 1))p" \
141 | while read line; do
147 printf "$(( $(selectionlist | wc -l) / $pagesize + 1 ))"