. $_EXEC/pages/common.sh
-filters="$(printf %s "${_GET[f]}" |sed -r 's;^!*\^*;;; s;\^*!*$;;; s;!+;!;g; s;\^+;^;g')"
+filters="${_GET[f]}"
debug "FILTERS: $filters"
quicklinks(){
echo $output
}
-list_categories(){
- echo none
- printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
-}
-
category_selected(){
cat="${1}:"
filter="$2"
| sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
}
-case "$1" in
- title)
- echo "Videos"
- ;;
- css)
- . ${_EXEC}/templates/common.css.sh
- ;;
- body)
- . ${_EXEC}/templates/list.html.sh
- ;;
-esac
+_printVideo(){
+ info="$1"
+ cache="${_DATA}/cache/$info.cache"
+ meta="${_DATA}/meta/$info.meta"
+
+ if [ "$cache" -nt "$meta" ]; then
+ cat "$cache"
+ else
+ videofile="${_DATA}/videos/$info"
+ thumb="${_DATA}/thumbs/${info}.jpg"
+ [ -r "$thumb" ] || genthumb "$videofile" "$thumb"
+ [ -r "$meta" ] || genmeta "$videofile" "$meta"
+
+ head -n1 "$meta" |read length width height filename
+ [ -z "$length" ] && length=0
+ [ -z "$width" ] && width=0
+ [ -z "$height" ] && height=0
+
+ tags="$(sed -n 2p "$meta")"
+ video="$(urlsafe "videos/$info")"
+ thumb="$(urlsafe "thumbs/$info.jpg")"
+ linkinfo="$(urlsafe "$info")"
+ htmlinfo="$(htmlsafe "$info")"
+
+ [ "$(($length % 60))" -lt 10 ] && minutes="$(($length / 60)):0$(($length % 60))" \
+ || minutes="$(($length / 60)):$(($length % 60))"
+
+ tee "$cache" <<VIDEOend
+ <li class="thumb">
+ <a class="watchlink" name="${linkinfo}" href="?action=watch&i=${linkinfo}">
+ <img src="$thumb" alt="Preview not yet available">
+ </a>
+ <h2>${htmlinfo}</h2>
+
+ <input type="checkbox" name="tagsel" value="${htmlinfo}">
+ <span class="info property">${minutes}min</span>
+ <span class="info property">${width}x${height}</span>
+ $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: <span class="info tag">\1</span>:g')
+ </li>
+VIDEOend
+ fi
+}
+
+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;^.*/;;;';;
+ 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
+ cat "$cache"
+ else
+ filterex="s;^([0-9]+\t){3}(.+)\n.*$;\2;p"
+ printf '%s\n' "$filter" |tr '^' '\n' \
+ | while read each; do
+ [ "${each:0:1}" = '!' ] && filterex="/^[^\n]+\n(.*\|)?(${each#?})(\|.*)?$/d;{${filterex}}" \
+ || filterex="/^[^\n]+\n(.*\|)?(${each})(\|.*)?$/{${filterex}}"
+ done
+
+ genlist \
+ | if [ -n "$search" ] ; then
+ debug "Applying search: ${search}"
+ xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
+ | xargs -d '\n' egrep -sil "$search" \
+ | sed -r 's;^.*/;;;s;\.meta$;;'
+ elif [ -n "$filter" ]; then
+ debug "Applying filters: ${filter} ++ ${filterex}"
+ xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
+ | xargs -d '\n' sed -srn ":a;N;2!ba;{${filterex}}"
+ else
+ debug "No search or filtering"
+ cat
+ fi \
+ | sed -n "$page,$(($page + $pagesize - 1))p" \
+ | tee "$cache"
+ fi \
+ | while read line; do
+ _printVideo "$line"
+ done
+}