#!/bin/zsh
cgi_post
-cgi_cookie
-fakemp4="$(printf %s "${_POST[fakemp4]}" |sed -rn '/^yes$/{p;q};ano' )"
-watch="$(printf %s "${_POST[watch]}" |sed -rn '/^(240p|480p|download|raspi|player|server)$/{p;q};aplayer' )"
+fakemp4=$(validate "${_POST[fakemp4]}" yes no)
+watch=$(validate "${_POST[watch]}" '(240p|480p|download|raspi|player|server)' player)
+pagesize=$(validate "${_POST[pagesize]}" '[1-9][0-9]+' 1)
debug '== Setting Preferences =='
-debug "fakemp4 = $fakemp4"
-debug "watch = $watch"
+debug "fakemp4 = $fakemp4"
+debug "watch = $watch"
+debug "pagesize = $pagesize"
set_cookie '+ 1 month' "fakemp4=${fakemp4}" HttpOnly
set_cookie '+ 1 month' "watch=${watch}" HttpOnly
+set_cookie '+ 1 month' "pagesize=${pagesize}" HttpOnly
redirect "$HTTP_REFERER"
#!/bin/zsh
cgi_refdata
-cgi_cookie
info="${_GET[i]}"
order="${_REF[o]}"
search="${_REF[s]}"
alias _wiki="stx2any --no-template --link-abbrevs --quote -T html"
[ -z "${_GET[p]}" ] && _GET[p]=list
-pagesize=100
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
+
+cgi_cookie
+validate(){ printf '%s\n' "$1" |sed -rn '2q;/^'"$2"'$/{p;q};a'"$3"; }
+
+_GET[o]=$( validate "${_GET[o]}" '(Name|Date|Length)' Name)
+_GET[pn]=$(validate "${_GET[pn]}" '[1-9][0-9]*' 1)
+
+_COOKIE[pagesize]=$(validate "${_COOKIE[pagesize]}" '[1-9][0-9]*' 50)
+
+
filter="${_GET[f]}"
search="${_GET[s]}"
-order=$(echo -E "${_GET[o]}" |egrep '^(Name|Date|Length)$')
-page=$(echo -E "${_GET[pn]}" |egrep '^[0-9]+$')
-[ -z "$page" ] && page=0
+order="${_GET[o]}" #validated
+page="${_GET[pn]}" #validated
+pagesize="${_COOKIE[pagesize]}" #validated
page_link=''
[ -n "$info" ] && page_link="i=$(urlsave "$info")&"
[ -n "$order" ] && page_link="${page_link}o=${order}&"
[ -n "$search" ] && page_link="${page_link}s=${search}&"
[ -n "$filter" ] && page_link="${page_link}f=${filter}&"
-page_prev="${page_link}pn=$([ "$page" = 0 ] && echo 0 || echo $(($page - 1)) )"
-page_next="${page_link}pn=$(($page + 1))"
+page_prev="${page_link}pn=$([ "$page" -le "$pagesize" ] && echo 1 || echo $(($page - $pagesize)) )"
+page_next="${page_link}pn=$(($page + $pagesize))"
page_this="${page_link}pn=$page"
taglist=$(
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;;';;
- *) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';;
+ Name) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';;
esac
}
thumblist() {
- cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&pn=${page}"
+ 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
else
cat
fi \
- | sed -n "$(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p" \
+ | sed -n "$page,$(($page + $pagesize - 1))p" \
| tee "$cache"
fi \
| while read line; do
# You should have received a copy of the GNU Affero General Public License
# along with Serve0. If not, see <http://www.gnu.org/licenses/>.
-cgi_cookie
. $_EXEC/pages/common.sh
filters="$(printf %s "${_GET[f]}" |sed -r 's;^!*\^*;;; s;\^*!*$;;; s;!+;!;g; s;\^+;^;g')"
color: #DDD;
}
a { color: #EEE; }
-label, .label { font-weight: bold; }
+legend, label, .label { font-weight: bold; }
input.tabhandle { display: none; }
.tabcontent { display: none; }
#advfilter .quicklinks,
#advfilter .filter,
#tagger .newtag,
-#tagger input[type=submit] {
+#tagger input[type=submit],
+#preferences > * {
display: inline-block;
vertical-align: top;
margin-top: 1em;
margin: .75em .5em;
}
-#preferences { display: none; }
-#preferences:target { display: block; z-index: 1; }
-
#tagger { display: none; }
#tagger:target {
display: block;
z-index: 1;
}
-
#tagger .newtag select,
#tagger .newtag .label{
display: block;
width: 10em;
}
+#preferences { display: none; }
+#preferences:target {
+ display: block;
+ z-index: 1;
+}
+#preferences > fieldset {
+ border: solid 1px;
+ border-radius: .25em;
+}
+#preferences > input { display: block; }
+
#videoview a.panel {
position: absolute;
right: 1em;
<div class="pagination_nav">
<label>Page:</label>
<a href="?${page_prev}"><<</a>
- <a href="?${page_this}">$(($page + 1))</a>
+ <a href="?${page_this}">$(($page / $pagesize + 1))</a>
<a href="?${page_next}">>></a>
</div>
</form>
<div class="pagination_nav">
<label>Page:</label>
<a href="?${page_prev}"><<</a>
- <a href="?${page_this}">$(($page + 1))</a>
+ <a href="?${page_this}">$(($page / $pagesize + 1))</a>
<a href="?${page_next}">>></a>
</div>
</div>
cat <<EOF
<form class="panel footer" id="preferences"
action="?action=preferences" method="post" accept-charset="UTF-8">
+ <fieldset>
+ <legend>Watch videos:</legend>
+ <input type="radio" name="watch" value="240p" $([ "${_COOKIE[watch]}" = 240p ] && printf 'checked') id="rd_w240p">
+ <label for="rd_w240p">as Download in 240p</label><br>
+ <input type="radio" name="watch" value="480p" $([ "${_COOKIE[watch]}" = 480p ] && printf 'checked') id="rd_w480p">
+ <label for="rd_w480p">as Download in 480p</label><br>
+ <input type="radio" name="watch" value="download" $([ "${_COOKIE[watch]}" = download ] && printf 'checked') id="rd_wdown">
+ <label for="rd_wdown">as Download (original)</label><br>
+ <input type="radio" name="watch" value="raspi" $([ "${_COOKIE[watch]}" = raspi ] && printf 'checked') id="rd_wrasp">
+ <label for="rd_wrasp">on RaspBerry</label><br>
+ <input type="radio" name="watch" value="player" $([ "${_COOKIE[watch]}" = player ] && printf 'checked') id="rd_wplay">
+ <label for="rd_wplay">in embedded player</label><br>
+ <input type="radio" name="watch" value="server" $([ "${_COOKIE[watch]}" = server ] && printf 'checked') id="rd_wserv">
+ <label for="rd_wserv">on screen connected to server</label><br>
- <input type="checkbox" name="fakemp4" value="yes" $([ "${_COOKIE[fakemp4]}" = yes ] && printf 'checked') id="ck_fakemp4">
- <label for="ck_fakemp4">Fake .mp4 file ending, even if file is of different type</label>
+ <input type="checkbox" name="fakemp4" value="yes" $([ "${_COOKIE[fakemp4]}" = yes ] && printf 'checked') id="ck_fakemp4">
+ <label for="ck_fakemp4">Fake .mp4 file ending, even if file is of different type</label>
+ </fieldset>
- <h2>Watch videos:</h2>
- <input type="radio" name="watch" value="240p" $([ "${_COOKIE[watch]}" = 240p ] && printf 'checked') id="rd_w240p">
- <label for="rd_w240p">as Download in 240p</label><br>
- <input type="radio" name="watch" value="480p" $([ "${_COOKIE[watch]}" = 480p ] && printf 'checked') id="rd_w480p">
- <label for="rd_w480p">as Download in 480p</label><br>
- <input type="radio" name="watch" value="download" $([ "${_COOKIE[watch]}" = download ] && printf 'checked') id="rd_wdown">
- <label for="rd_wdown">as Download (original)</label><br>
- <input type="radio" name="watch" value="raspi" $([ "${_COOKIE[watch]}" = raspi ] && printf 'checked') id="rd_wrasp">
- <label for="rd_wrasp">on RaspBerry</label><br>
- <input type="radio" name="watch" value="player" $([ "${_COOKIE[watch]}" = player ] && printf 'checked') id="rd_wplay">
- <label for="rd_wplay">in embedded player</label><br>
- <input type="radio" name="watch" value="server" $([ "${_COOKIE[watch]}" = server ] && printf 'checked') id="rd_wserv">
- <label for="rd_wserv">on screen connected to server</label><br>
+ <fieldset>
+ <legend>Display:</legend>
+ <label for="n_pagesize">Number of items per page: </label>
+ <input type="number" name="pagesize" value="${pagesize}" id="n_pagesize">
+ </fieldset>
<input type="submit" value="Set Cookie!">