cgi_refdata
info="${_GET[i]}"
+location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
order="${_REF[o]}"
search="${_REF[s]}"
filter="${_REF[f]}"
page="${_REF[pn]}"
watch_link=''
-[ -n "$info" ] && watch_link="i=$(urlsafe "${info}")&"
-[ -n "$order" ] && watch_link="${watch_link}o=${order}&"
-[ -n "$search" ] && watch_link="${watch_link}s=${search}&"
-[ -n "$filter" ] && watch_link="${watch_link}f=${filter}&"
-[ -n "$page" ] && watch_link="${watch_link}pn=${page}"
+[ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&"
+[ -n "$info" ] && watch_link="i=$(urlsafe "${info}")&"
+[ -n "$order" ] && watch_link="${watch_link}o=${order}&"
+[ -n "$search" ] && watch_link="${watch_link}s=${search}&"
+[ -n "$filter" ] && watch_link="${watch_link}f=${filter}&"
+[ -n "$page" ] && watch_link="${watch_link}pn=${page}"
meta="${_DATA}/meta/$info.meta"
head -n1 "$meta" |read length width height filename
redirect "$videourl"
;;
server)
- DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
+ if [ -n "$info" ]; then
+ DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
+ elif [ -n "$location" ]; then
+ DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${treeroot%/}/${location#/}" >/dev/null 2>/dev/null &
+ fi
redirect "$HTTP_REFERER"
;;
*) redirect "?p=view&${watch_link}"
# along with Serve0. If not, see <http://www.gnu.org/licenses/>.
alias _wiki="stx2any --no-template --link-abbrevs --quote -T html"
-file_pattern='^.*(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmvb)$'
+file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmvb)$'
data_dirs cache meta mp4 videos thumbs trash by_length transcoded
PAGE="${_GET[p]:-${PAGE:-list}}"
+treeroot="${treeroot:-${_DATA}}"
_GET[o]=$( validate "${_GET[o]}" 'Name|Date|Length' Name)
_GET[pn]=$(validate "${_GET[pn]}" '[1-9][0-9]*' 1)
done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist
)
+list_categories(){
+ echo none
+ printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
+}
+
genthumb(){
videofile="$1"
thumb="$2"
"${_EXEC}"/helpers/genmeta.sh "$videofile" "$meta" >/dev/null
}
-
-_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
-}
echo $output
}
-list_categories(){
- echo none
- printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
-}
-
category_selected(){
cat="${1}:"
filter="$2"
| sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
| sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
}
+
+_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
+}
--- /dev/null
+#!/bin/zsh
+
+# Copyright 2014, 2015 Paul Hänsch
+#
+# This file is part of Serve0.
+#
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0. If not, see <http://www.gnu.org/licenses/>.
+
+. $_EXEC/pages/common.sh
+
+directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)"
+
+filelist(){
+ debug "Filelist with dir = $directory"
+
+ [ -n "${directory#/}" ] && printf %s "<a class='file directory' href='?p=tree&d=$(urlsafe "${directory%/*}")'>..</a>"
+
+ find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type d \
+ | sort \
+ | while read dir; do
+ name="${dir##*/}"
+ printf %s "<a class='file directory' href='?p=tree&d=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>"
+ done
+
+ find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \
+ | sort \
+ | while read file; do
+ name="${file##*/}"
+ printf %s\\n "$name" |egrep -q "$file_pattern" && \
+ printf %s "<a class='file video' href='?action=watch&l=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>" \
+ || printf %s "<span class='file plain'>$(htmlsafe "$name")</span>"
+ done
+}
+
# You should have received a copy of the GNU Affero General Public License
# along with Serve0. If not, see <http://www.gnu.org/licenses/>.
+. $_EXEC/pages/list.sh
+. $_EXEC/pages/tree.sh
+
info="${_GET[i]}"
-. $_EXEC/pages/common.sh
+location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
+directory="${location%/*}"
meta="${_DATA}/meta/$info.meta"
-video="${_DATA}/videos/$info"
+[ -n "$info" ] && video="${_DATA}/videos/$info" \
+ || video="${treeroot%/}/${location#/}"
tags="$(sed -n '2p' "$meta")"
description="$(sed -n '3,$p' "$meta")"
length=0; width=0; height=0;
-eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null\
-| sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;')
+
+debug "Analysing video: $video"
+echo '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \
+| sort \
+| sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p;
+ s:ID_VIDEO_HEIGHT=(.*):\1:p;
+ s:ID_VIDEO_WIDTH=(.*):\1:p;' \
+| tr '\n' ' ' \
+| read length height width 2>/dev/null
+
video="videos/$info"
+[ -n "$info" ] && video="videos/$info" \
+ || video="${location#/}"
word-wrap: break-word;
}
-
/* == Thumblist == */
#thumblist {
text-align: left;
width: 90%;
padding: 0 .5em;
- margin: auto;
+ margin: .5%;
margin-bottom: .75em;
vertical-align: top;
word-wrap: break-word;
}
-@media (min-width: 480px){#thumblist .thumb{width: 49.5%;}}
-@media (min-width: 640px){#thumblist .thumb{width: 33%;}}
-@media (min-width: 1024px){#thumblist .thumb{width: 256px;}}
+@media (min-width: 460px){#thumblist .thumb{width: 48%;}}
+@media (min-width: 620px){#thumblist .thumb{width: 32%;}}
+@media (min-width: 1004px){#thumblist .thumb{width: 250px; margin: 2px;}}
#thumblist .thumb img {
width: 100%;
margin: .75em .5em;
}
+/* == Filelist == */
+
+#thumblist .file {
+ color: #000;
+ display: inline-block;
+ text-align: left;
+ width: 90%;
+ padding: .5em .5em;
+ margin: .5%;
+ margin-bottom: .75em;
+ vertical-align: top;
+ word-wrap: break-word;
+}
+@media (min-width: 460px){#thumblist .file{width: 48%;}}
+@media (min-width: 620px){#thumblist .file{width: 32%;}}
+@media (min-width: 1004px){#thumblist .file{width: 250px; margin: 2px;}}
+
+#thumblist .file.directory { background-color: #BBD; }
+#thumblist .file.plain { background-color: #111; color: #777; }
+#thumblist .file.video { background-color: #DBB; }
+
.panel#tagger .newtag select,
.panel#tagger .newtag .label{
display: block;
<div class="panel" id="foot">
<a class="panel toggle" href="#tagger">Add Tags</a>
<a class="panel toggle" href="#preferences">Preferences</a>
+ <a class="panel treeview" href="?p=tree">Browse Folders</a>
<div class="pagination_nav">
<label>Page:</label>
--- /dev/null
+# Copyright 2014, 2015 Paul Hänsch
+#
+# This file is part of Serve0
+#
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0 If not, see <http://www.gnu.org/licenses/>.
+
+cat <<EOF
+ <form class="panel" id="search" action="?" method="get" accept-charset="UTF-8">
+ <input type="text" name="s" value="$search" placeholder="Search">
+ <input type="submit" name="submit" value="Find">
+
+ <a class="panel clearsearch" href="?p=tree">Clear All</a>
+ </form>
+
+ <form action="?action=multitag&${page_this}" method="post" accept-charset="UTF-8">
+ <ul id="thumblist">
+ $(filelist)
+ </ul>
+ $(. $_EXEC/templates/tagger.html.sh)
+ </form>
+
+ <div class="panel" id="foot">
+ <a class="panel toggle" href="#tagger">Add Tags</a>
+ <a class="panel toggle" href="#preferences">Preferences</a>
+ <a class="panel listview" href="?p=list">Index view</a>
+ </div>
+
+ $(. $_EXEC/templates/preferences.html.sh)
+EOF
+
+# vi:set filetype=html:
</form>
<div class="panel" id="videoview">
- <a href="?p=list&${page_this}" class="panel">Dismiss</a>
+ <a href="${info:+?p=list&${page_this}}${info:-?p=tree&d=${directory}&${page_this}}" class="panel">Dismiss</a>
<h1>$info</h1>
<div class="video">
<form>
<ul id="thumblist">
- $(thumblist)
+ $([ -n "$info" ] && thumblist || filelist)
</ul>
</form>