# 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]"
-filter="$_GET[f]"
-search="$_GET[s]"
-order=$(echo "$_GET[o]" |egrep '^(Name|Date|Length)$')
-page=$(echo "$_GET[p]" |egrep '^[0-9]+$')
+info="$_GET[\"i\"]"
+filter="$_GET[\"f\"]"
+search="$_GET[\"s\"]"
+order=$(echo "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$')
+page=$(echo "$_GET[\"p\"]" |egrep '^[0-9]+$')
[ -z "$page" ] && page=0
+taglist=$(
+ [ -r ${_DATA}/cache/taglist ] && cat ${_DATA}/cache/taglist ||\
+ for each in ${_DATA}/meta/*.meta; do
+ sed -n '2s:|:\n:gp' "$each"
+ done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist
+)
+
filterdiag() {
. ${_EXEC}/templates/filterdiag.html.sh
}
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;')
- taglist=$(
- [ -r ${_DATA}/cache/taglist ] && cat ${_DATA}/cache/taglist ||\
- for each in ${_DATA}/meta/*.meta; do
- sed -n '2s:|:\n:gp' "$each"
- done |sort -u |grep -xv '' |tee cache/taglist
- )
-
. ${_EXEC}/templates/view.html.sh
fi
}
_printVideo(){
info="$1"
+ cache="${_DATA}/cache/$info.cache"
+ video="${_DATA}/videos/$info"
meta="${_DATA}/meta/$info.meta"
- tags="$(sed -n 2p "$meta")"
- thumb="${_DATA}/thumbs/$info.jpg"
- head -n1 "$meta" |read length width height
- [ -z "$length" ] && length=0
- [ -z "$width" ] && width=0
- [ -z "$height" ] && height=0
+ if [ "$cache" -nt "$video" -a "$cache" -nt "$meta" ]; then
+ cat "$cache"
+ else
+ tags="$(sed -n 2p "$meta")"
+ thumb="${_DATA}/thumbs/$info.jpg"
+ head -n1 "$meta" |read length width height
+ [ -z "$length" ] && length=0
+ [ -z "$width" ] && width=0
+ [ -z "$height" ] && height=0
- video="${_DATA}/videos/$info"
-# reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
- mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )"
-# [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
- [ -r "$meta" ] || ./genmeta.sh "$video" "$meta"
- [ -r "$thumb" ] || ./genthumb.sh "$video" "$thumb"
- [ -L "$mpfake" ] || ln -s "../$video" "$mpfake"
-# anchor=$(ls videos |grep -xA2 "$info" |tail -n1)
- video="$(echo "$video" |sed 's/\?/\%6F/g')"
- thumb="$(echo "$thumb" |sed 's/\?/%6F/g')"
- mpfake="$(echo "$mpfake" |sed 's/\?/%6F/g')"
+# reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
+ mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )"
+# [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
+ [ -r "$meta" ] || ./genmeta.sh "$video" "$meta"
+ [ -r "$thumb" ] || ./genthumb.sh "$video" "$thumb"
+ [ -L "$mpfake" ] || ln -s "../$video" "$mpfake"
+# anchor=$(ls videos |grep -xA2 "$info" |tail -n1)
+ video="$(echo "videos/$info" |sed 's/\?/\%6F/g')"
+ thumb="$(echo "thumbs/$info.jpg" |sed 's/\?/%6F/g')"
+ mpfake="$(echo "$info" |sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:mp4/\1.mp4:' |sed 's/\?/%6F/g')"
- [ "$(($length % 60))" -lt 10 ] &&\
- minutes="$(($length / 60)):0$(($length % 60))" ||\
- minutes="$(($length / 60)):$(($length % 60))"
+ [ "$(($length % 60))" -lt 10 ] &&\
+ minutes="$(($length / 60)):0$(($length % 60))" ||\
+ minutes="$(($length / 60)):$(($length % 60))"
- cat <<VIDEOend
- <div class="thumb">
- <a name="$info" href="?i=$info&p=$page&f=$filter&s=$search&o=$order#$anchor"><img src="$thumb"></a>
- <div class="thumbinfo">
- <a href="$video"><b>$info</b></a><br>
- <!-- a href="$reenc">VP8</a -->
- <a href="$mpfake">fake-mp4</a><br>
- <input type="checkbox" name="tagsel" value="$info">
- <span class="coord">${minutes}min</span>
- <span class="coord">${width}x${height}</span><br>
- <!--a class="function" href='write/lock.cgi?p=Locations&e=$info&i=$info&f=$filter#$anchor'>edit</a-->
- <span class="tag">$(sed 's,|$,,;s,|,</span> <span class="tag">,g' <<<"$tags")</span>
+ tee "$cache" <<VIDEOend
+ <div class="thumb">
+ <a name="$info" href="?i=$info&p=$page&f=$filter&s=$search&o=$order#$anchor"><img src="$thumb"></a>
+ <div class="thumbinfo">
+ <a href="$video"><b>$info</b></a><br>
+ <!-- a href="$reenc">VP8</a -->
+ <a href="$mpfake">fake-mp4</a><br>
+ <input type="checkbox" name="tagsel" value="$info">
+ <span class="coord">${minutes}min</span>
+ <span class="coord">${width}x${height}</span><br>
+ <!--a class="function" href='write/lock.cgi?p=Locations&e=$info&i=$info&f=$filter#$anchor'>edit</a-->
+ <span class="tag">$(sed 's,|$,,;s,|,</span> <span class="tag">,g' <<<"$tags")</span>
+ </div>
</div>
- </div>
VIDEOend
+ fi
}
-_by_name(){ ls ${_DATA}/videos/ }
-_by_date(){ ls -c ${_DATA}/videos/ }
+_by_name(){ ls ${_DATA}/videos/ |egrep -i "$file_pattern" }
+_by_date(){ ls -c ${_DATA}/videos/ |egrep -i "$file_pattern" }
_by_length(){ ls ${_DATA}/by_length/ |sed -r 's:[0-9]{5} - ::g' }
thumblist() {
cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&p=${page}"
- [ -f "$cache" ] && [ "$cache" -ot ${_DATA}/videos -o "$cache" -ot ${_DATA}/meta ] && rm "$cache"
- if [ -r "$cache" ]; then
+ if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
cat "$cache"
- exit 0
- fi
-
- filterex="p"
- for each in $(sed 's,\^, ,g' <<<"$filter"); do
- if egrep -q '^!' <<<"$each"; then
- this="$(sed 's,^!,,' <<<"$each")"
- filterex="/${this}/q;{${filterex}}"
- else
- filterex="/${each}/{${filterex}}"
- fi
- done
-
- case "$order" in
- Date) genlist="_by_date"
- ;;
- Length) genlist="_by_length"
- ;;
- *) genlist="_by_name"
- ;;
- esac
+ else
+ filterex="p"
+ for each in $(sed 's,\^, ,g' <<<"$filter"); do
+ if egrep -q '^!' <<<"$each"; then
+ this="$(sed 's,^!,,' <<<"$each")"
+ filterex="/${this}/q;{${filterex}}"
+ else
+ filterex="/${each}/{${filterex}}"
+ fi
+ done
- $genlist |while read video; do
- #video="$(basename "$each")"
- if [ -n "$search" ] ; then
- egrep -iq "$search" <<<"$video" <"${_DATA}/meta/$video.meta" && (echo "$video" || exit 0)
- elif [ "$filterex" != p ]; then
- [ -n "$(sed -rn "2{$filterex}" "${_DATA}/meta/$video.meta")" ] && (echo "$video" || exit 0)
- else
- echo "$video" || exit 0
- fi
- done |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p | while read line; do
+ case "$order" in
+ Date) genlist="_by_date"
+ ;;
+ Length) genlist="_by_length"
+ ;;
+ *) genlist="_by_name"
+ ;;
+ esac
+
+ $genlist |while read video; do
+ #video="$(basename "$each")"
+ if [ -n "$search" ] ; then
+ egrep -iq "$search" <<<"$video" <"${_DATA}/meta/$video.meta" && (echo "$video" || exit 0)
+ elif [ "$filterex" != p ]; then
+ [ -n "$(sed -rn "2{$filterex}" "${_DATA}/meta/$video.meta")" ] && (echo "$video" || exit 0)
+ else
+ echo "$video" || exit 0
+ fi
+ done |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache"
+ fi | while read line; do
_printVideo "$line"
- done |tee "$cache"
+ done
}
case "$1" in