#!/bin/zsh
+# Copyright 2014 - 2016 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/>.
cgi_post
order=$(validate "${_POST[o]}" 'Name|Length|Date' Name)
done
done
-echo "?o=${order}&f=${filters}" >>${_DATA}/meta/recent
-echo -n "Location: ?o=${order}&f=${filters}\n\n"
+printf %s "?o=${order}&f=${filters}" >>${_DATA}/meta/recent
+redirect "?o=${order}&f=${filters}"
#!/bin/zsh
+# Copyright 2014 - 2016 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/>.
cgi_refdata
trash="${_POST[trash]}"
cancel="${_POST[cancel]}"
tagacc="${_POST[tag]}"
-tags="$(echo "${_POST[tags]}" \
- | sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\<\;/g;s/>/\>\;/g'
-)"
-description="$(echo -e "${_POST[description]}" \
- |sed 's/\r//g;s/\\/\\\\/g;s/</\<\;/g;s/>/\>\;/g'
-)"
+tags="$(htmlsafe "${_POST[tags]}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;' |tr '\n' '|')"
+description="$(htmlsafe "${_POST[description]}")"
+
n=0; while [ -n "${_POST[tag$n]}" ]; do
- tagacc="${_POST[tag$n]}|$tagacc"
+ tagacc="$(htmlsafe ${_POST[tag$n]} |sed -r '2,$d;s:\t| :_:g;s:^!|\r|\$|\^::g;')|$tagacc"
n=$(($n + 1))
done
rm "${_DATA}/cache/$info.cache" 2>/dev/null
rm ${_DATA}/cache/\?* 2>/dev/null
else
- echo -e "$length\t$width\t$height\t$info" > "$file"
- echo -e "${tagacc}|${tags}" |tr '\n' '|' >> "$file"
- echo >>"$file"
- echo -e "${description}" >> "$file"
+ cat >$file <<EOF
+${length} ${width} ${height} ${info}
+${tagacc}|${tags}
+${description}
+EOF
rm "${_DATA}/cache/$info.cache" 2>/dev/null
rm ${_DATA}/cache/*[0-9]\?* 2>/dev/null
rm ${_DATA}/cache/taglist 2>/dev/null
fi
-echo -n "Location: ?i=&pn=${page}&s=${search}&f=${filter}&o=${order}#$info\n\n"
+redirect "?i=&pn=${page}&s=${search}&f=${filter}&o=${order}#${info}"
#!/bin/zsh
+# Copyright 2014 - 2016 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/>.
filter="${_GET[f]}"
search="${_GET[s]}"
-order=$(echo "${_GET[o]}" |egrep '^(Name|Date|Length)$')
-page=$(echo "${_GET[pn]}" |egrep '^[0-9]+$')
+order=$(validate "${_GET[o]}" 'Name|Date|Length' Name)
+page=$(validate "${_GET[pn]}" '[0-9]+' 1)
addtag(){
meta="$1"
tagsel="${_POST[tagsel$n]}"
( t=''
while [ -n "${_POST[ctag$t]}" ]; do
- echo "${_POST[ctag$t]}"
+ htmlsafe "${_POST[ctag$t]}"
+ printf \\n
[ -z "$t" ] && t=0 || t=$(($t + 1))
done
- echo "${_POST[tags]}"
- ) |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\<\;/g;s/>/\>\;/g' \
+ htmlsafe "${_POST[tags]}"
+ printf \\n
+ ) |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;' \
| while read tag; do
addtag "${_DATA}/meta/$tagsel.meta" "$tag"
done
rm "${_DATA}"/cache/*[0-9]\?* 2>/dev/null
[ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist 2>/dev/null
-echo -n "Location: ?o=$order&s=$search&f=$filter&pn=$page\n\n"
+redirect "?o=$order&s=$search&f=$filter&pn=$page"
#!/bin/zsh
+# Copyright 2015 - 2016 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/>.
info="${_GET[i]}"
target="${_GET[t]}"
[ "$target" -gt 240 ] && nohup avconv -i "$video" -s "${twidth}x${target}" -threads auto "$trans" &
fi
-echo "Location: /transcoded/${info}.${target}p.webm"
-echo
+redirect "/transcoded/${info}.${target}p.webm"
#!/bin/zsh
+# Copyright 2014 - 2016 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/>.
dir="$(dirname $0)"
genmeta="$dir/genmeta.sh"
egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
- cat <<EOF >"$meta"
+ cat >"$meta" <<EOF
$length $width $height $info
$tags
$description
for each in *; do
if (egrep -q "$file_pattern" <<<"$each"); then
- echo -n "$each ... Thumb ..."
+ printf %s "$each ... Thumb ..."
$genthumb "$each" "${each}.jpg" >/dev/null 2>/dev/null
- echo -n ' Meta ...'
+ printf %s ' Meta ...'
$genmeta "$each" "${each}.meta" >/dev/null 2>/dev/null
- echo -n ' Tags ...'
+ printf %s ' Tags ...'
for tag in $*; do
addtag "${each}.meta" "$tag"
done
- echo ' Done!'
+ printf 'Done!\n'
fi; done
#!/bin/zsh
+# Copyright 2014 - 2016 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/>.
video="$1"
meta="$2"
description="$(sed -n '3,$p' "$meta")"
fi
-echo '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \
+printf '' |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;
#!/bin/zsh
+# Copyright 2014 - 2016 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/>.
video="$1"
thumb="$2"
if [ -e "$video" -a \! -e "$thumb" ]; then
- echo '' |mplayer -input nodefault-bindings -nosound -vo null -frames 0 -identify "$video" \
+ printf '' |mplayer -input nodefault-bindings -nosound -vo null -frames 0 -identify "$video" \
| sort \
| sed -rn 's:^.*ID_LENGTH=(.*)(\..*)$:\1:p;
s:^.*ID_VIDEO_HEIGHT=(.*)$:\1:p;
tmp="$(mktemp -d)"
for cnt in 1 2 3 4; do
- echo '' |mplayer -input nodefault-bindings -nosound -vo jpeg:outdir="$tmp" -frames 1 \
+ printf '' |mplayer -input nodefault-bindings -nosound -vo jpeg:outdir="$tmp" -frames 1 \
-benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null
mv "$tmp/00000001.jpg" "${tmp}/_${cnt}.jpg"
done
#!/bin/zsh
-# Copyright 2014, 2015 Paul Hänsch
+# Copyright 2014 - 2016 Paul Hänsch
#
# This file is part of Serve0.
#
[ -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" -le "$pagesize" ] && echo 1 || echo $(($page - $pagesize)) )"
+[ "$page" -le "$pagesize" ] && page_prev="${page_link}pn=1" || page_prev="${page_link}pn=$(($page - $pagesize))"
page_next="${page_link}pn=$(($page + $pagesize))"
page_this="${page_link}pn=$page"
sed -n '2s:|:\n:gp' "$each"
done \
| sort
- echo
+ printf \\n
) | (while read tag; do
if [ "$tag" = "$lasttag" ]; then
tagcount=$(( ${tagcount:-0} + 1 ))
lasttag="$tag"
done \
| sort -rn
- echo
+ printf \\n
) | while read x tag; do
topcnt=$(grep "${tag%%:*}" ${_DATA}/cache/taglist |wc -l)
[ $topcnt -lt 10 ] \
)
list_categories(){
- echo none
+ printf none\\n
printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
}
#!/bin/zsh
-# Copyright 2014, 2015 Paul Hänsch
+# Copyright 2014 - 2016 Paul Hänsch
#
# This file is part of Serve0.
#
. $_EXEC/pages/common.sh
+LF='
+'
filters="${_GET[f]}"
debug "FILTERS: $filters"
quicklinks(){
output=''
- tac ${_DATA}/meta/recent |while [ "$(echo "$output" |wc -l)" -lt 10 ] && read line; do
+ tac ${_DATA}/meta/recent \
+ | while [ "$(printf %s "$output" |wc -l)" -lt 10 ] && read line; do
line="<a href="$line">$line</a>"
- echo "$output" |grep -qF "$line" || output="$output$line\n"
+ printf %s "$output" |grep -qF "$line" || output="$output$line$LF"
done
- echo $output
+ printf %s\\n "$output"
}
category_selected(){
[ -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
+ length=$(validate "$length" '[0-9]+' 0)
+ width=$(validate "$width" '[0-9]+' 0)
+ height=$(validate "$height" '[0-9]+' 0)
tags="$(sed -n 2p "$meta")"
video="$(urlsafe "videos/$info")"
#!/bin/zsh
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 2016 Paul Hänsch
#
# This file is part of Serve0.
#
length=0; width=0; height=0;
debug "Analysing video: $video"
-echo '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \
+printf '' |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;
-# Copyright 2014,2015 Paul Hänsch
+# Copyright 2014 - 2016 Paul Hänsch
#
# This file is part of Serve0
#
for cat in "$@"; do
cat <<EOF
<div class="tab">
- <input class="tabhandle" type="radio" name="category$n" id="cat${n}_$cat" value="$cat" $([ "$cat" = "$fcat" ] && echo checked)>
+ <input class="tabhandle" type="radio" name="category$n" id="cat${n}_$cat" value="$cat" $([ "$cat" = "$fcat" ] && printf checked)>
<label class="category tabhandle" for="cat${n}_$cat">$([ "$cat" = none ] && printf %s general || printf %s "$cat")</label>
<select class="category tabcontent" class="input tagfilter" name="cfilter${n}_" size="12" multiple>
$(category_selected "$cat" "$filter")
debug "fneg: $fneg fcat: $fcat filter: $filter"
cat <<-EOF
- <input class="tabhandle" type="checkbox" id="filter$n" $([ $n = 0 -o -n "$filter" ] && echo checked) >
+ <input class="tabhandle" type="checkbox" id="filter$n" $([ $n = 0 -o -n "$filter" ] && printf checked) >
<label class="tabhandle filter" for="filter$n">+ and</label>
<div class="tabcontent filter">
<input type="radio" name="type$n" value="pos" id="pos$n" ${fneg:-checked} ><label for="pos$n" class="conjunction">Any</label>
<p class="filter final">
<label for="o3" class="order">Order by:</label>
<select class="edit order" size="1" name="o" id="o3">
- <option $([ "${_GET[o]}" = Name ] && echo selected) >Name</option>
- <option $([ "${_GET[o]}" = Date ] && echo selected) >Date</option>
- <option $([ "${_GET[o]}" = Length ] && echo selected) >Length</option>
+ <option $([ "${_GET[o]}" = Name ] && printf selected) >Name</option>
+ <option $([ "${_GET[o]}" = Date ] && printf selected) >Date</option>
+ <option $([ "${_GET[o]}" = Length ] && printf selected) >Length</option>
</select>
<input type="submit" value="Filter!">
</p>
<span class="info height">Height: $height</span><br>
<label class="tags">Tags:</label>
- $(echo "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
- ${description:+<span class="info description">$(echo -E "$description" |_wiki)</span>}
+ $(printf %s\\n "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
+ ${description:+<span class="info description">$(printf %s "$description" |_wiki)</span>}
<form class="panel" id="tagger" action="?action=meta&${page_this}" method="post" accept-charset="UTF-8">
<input type="hidden" name="length" value="$length">