3 # Copyright 2014 Paul Hänsch
5 # This file is part of Serve0.
7 # Serve0 is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Serve0 is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Serve0. If not, see <http://www.gnu.org/licenses/>.
23 order=$(echo "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$')
24 page=$(echo "$_GET[\"p\"]" |egrep '^[0-9]+$')
25 [ -z "$page" ] && page=0
28 [ -n "$info" ] && page_link="i=$(echo -n "$info" |sed -r 's:%:%25:g;s:\&:%26:g;')&"
29 [ -n "$order" ] && page_link="${page_link}o=${order}&"
30 [ -n "$search" ] && page_link="${page_link}s=${search}&"
31 [ -n "$filter" ] && page_link="${page_link}f=${filter}&"
32 page_prev="${page_link}p=$([ "$page" = 0 ] && echo 0 || echo $(($page - 1)) )"
33 page_next="${page_link}p=$(($page + 1))"
34 page_this="${page_link}p=$page"
38 [ -r ${_DATA}/cache/taglist ] && cat ${_DATA}/cache/taglist ||\
39 for each in ${_DATA}/meta/*.meta; do
40 sed -n '2s:|:\n:gp' "$each"
41 done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist
45 . ${_EXEC}/templates/filterdiag.html.sh
50 hideall="$(sed -rn "s;^([^:]+):.*$;hide_inline('${n}_\\1')\\;;p" <<<"$taglist" |sort -u)hide_inline('${n}_none');"
52 . ${_EXEC}/templates/tagger.html.sh
56 if [ -n "$info" ]; then
57 meta="${_DATA}/meta/$info.meta"
58 video="${_DATA}/videos/$info"
59 #reenc="${_DATA}/vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
60 #[ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
61 tags="$(sed -n '2p' "$meta")"
62 description="$(sed -n '3,$p' "$meta")"
63 length=0; width=0; height=0;
64 eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null\
65 | sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;')
68 . ${_EXEC}/templates/view.html.sh
74 cache="${_DATA}/cache/$info.cache"
75 video="${_DATA}/videos/$info"
76 meta="${_DATA}/meta/$info.meta"
77 if [ "$cache" -nt "$video" -a "$cache" -nt "$meta" ]; then
80 tags="$(sed -n 2p "$meta")"
81 thumb="${_DATA}/thumbs/$info.jpg"
82 head -n1 "$meta" |read length width height filename
83 [ -z "$length" ] && length=0
84 [ -z "$width" ] && width=0
85 [ -z "$height" ] && height=0
87 # reenc="${_DATA}/vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
88 mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )"
89 # [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
90 [ -r "$meta" ] || ". ${_EXEC}/helpers/genmeta.sh" "$video" "$meta"
91 [ -r "$thumb" ] || ". ${_EXEC}/helpers/genthumb.sh" "$video" "$thumb"
92 [ -L "$mpfake" ] || ln -s "../$video" "$mpfake"
93 video="$(echo "videos/$info" |sed 's/\?/\%6F/g')"
94 thumb="$(echo "thumbs/$info.jpg" |sed 's/\?/%6F/g')"
95 mpfake="$(echo "$info" |sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:mp4/\1.mp4:' |sed 's/\?/%6F/g')"
97 [ "$(($length % 60))" -lt 10 ] &&\
98 minutes="$(($length / 60)):0$(($length % 60))" ||\
99 minutes="$(($length / 60)):$(($length % 60))"
101 linkinfo="$(echo -n "$info" |sed -r 's:%:%25:g;s:\&:%26:g;')"
102 tee "$cache" <<VIDEOend
104 <a class="watchlink" name="$linkinfo" href="?action=watch&i=$linkinfo">
107 <a class="videolink" href="$video">$info</a>
108 <!-- a href="$reenc">VP8</a -->
109 <a class="videolink fake-mp4" href="$mpfake">fake-mp4</a>
110 <input type="checkbox" name="tagsel" value="$info">
111 <span class="info property">${minutes}min</span>
112 <span class="info property">${width}x${height}</span>
113 $(echo "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
119 _by_name(){ ls ${_DATA}/videos/ |egrep -i "$file_pattern" }
120 _by_date(){ ls -c ${_DATA}/videos/ |egrep -i "$file_pattern" }
121 _by_length(){ ls ${_DATA}/by_length/ |sed -r 's:[0-9]{5} - ::g' }
124 cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&p=${page}"
125 if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
129 for each in $(sed 's,\^, ,g' <<<"$filter"); do
130 if egrep -q '^!' <<<"$each"; then
131 this="$(sed 's,^!,,' <<<"$each")"
132 filterex="/${this}/q1;{${filterex}}"
134 filterex="/${each}/{${filterex}}"
139 Date) genlist="_by_date"
141 Length) genlist="_by_length"
143 *) genlist="_by_name"
147 if [ -n "$search" ] ; then
148 #$genlist |egrep -i "$search"
149 $genlist |sed -rn 's:^(.+)$:'"${_DATA}"'/meta/\1'.meta':p' |xargs -d\\n egrep -sil "$search" |sed -rn 's:^(.*/)+([^/]+)\.meta$:\2:p'
150 elif [ "$filterex" != "q0" ]; then
151 $genlist |while read video; do
152 [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && echo "$video"
156 fi |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache"
157 fi | while read line; do
167 . ${_EXEC}/templates/videoview.css.sh
170 . ${_EXEC}/templates/videoview.html.sh