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 -E "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$')
24 page=$(echo -E "$_GET[\"p\"]" |egrep '^[0-9]+$')
25 [ -z "$page" ] && page=0
28 [ -n "$info" ] && page_link="i=$(echo -En "$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 "$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 [ -r "$meta" ] || ". ${_EXEC}/helpers/genmeta.sh" "$video" "$meta"
88 [ -r "$thumb" ] || ". ${_EXEC}/helpers/genthumb.sh" "$video" "$thumb"
89 video="$(urlsave "videos/$info")"
90 thumb="$(urlsave "thumbs/$info.jpg")"
92 [ "$(($length % 60))" -lt 10 ] &&\
93 minutes="$(($length / 60)):0$(($length % 60))" ||\
94 minutes="$(($length / 60)):$(($length % 60))"
96 linkinfo="$(urlsave "$info")"
98 rpiaddr="$(host pfostenpanne |sed -r 's;^.* ([0-9\.]+)$;\1;')"
99 rpibase="http://${rpiaddr}/?path=http://jupiter:8000/"
101 [ $height -gt 480 ] && \
102 raspi="<a class=\"videolink alt raspi\" href=\"${rpibase}?action=transcode&i=${linkinfo}&t=480\">RasPi</a>" \
103 || raspi="<a class=\"videolink alt raspi\" href=\"${rpibase}${video}\">RasPi</a>"
104 [ $height -gt 480 ] && \
105 alt480="<a class=\"videolink alt 480p\" href=\"?action=transcode&i=${linkinfo}&t=480\">480p</a>" \
107 [ $height -gt 240 ] && \
108 alt240="<a class=\"videolink alt 240p\" href=\"?action=transcode&i=${linkinfo}&t=240\">240p</a>" \
111 tee "$cache" <<VIDEOend
113 <a class="watchlink" name="${linkinfo}" href="?action=watch&i=${linkinfo}">
116 <a class="videolink" href="$video">$info</a>
117 ${alt480} ${alt320} ${alt240} ${raspi}<br>
119 <input type="checkbox" name="tagsel" value="$info">
120 <span class="info property">${minutes}min</span>
121 <span class="info property">${width}x${height}</span>
122 $(echo -E "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
128 _by_name(){ find ${_DATA}/videos/ -mindepth 1 -maxdepth 1 -printf '%f\n' |sort |egrep -i "$file_pattern" }
129 _by_date(){ ls -c ${_DATA}/videos/ |egrep -i "$file_pattern" }
130 _by_length(){ find ${_DATA}/by_length/ -mindepth 1 -maxdepth 1 -printf '%f\n' |sort |sed -r 's:[0-9]{5} - ::' }
133 cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&p=${page}"
134 if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
138 for each in $(sed 's,\^, ,g' <<<"$filter"); do
139 if egrep -q '^!' <<<"$each"; then
140 this="$(sed 's,^!,,' <<<"$each")"
141 filterex="/${this}/q1;{${filterex}}"
143 filterex="/${each}/{${filterex}}"
148 Date) genlist="_by_date"
150 Length) genlist="_by_length"
152 *) genlist="_by_name"
156 if [ -n "$search" ] ; then
157 #$genlist |egrep -i "$search"
158 $genlist |sed -rn 's:^(.+)$:'"${_DATA}"'/meta/\1'.meta':p' |xargs -d\\n egrep -sil "$search" |sed -rn 's:^(.*/)+([^/]+)\.meta$:\2:p'
159 elif [ "$filterex" != "q0" ]; then
160 $genlist |while read video; do
161 [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && echo -E "$video"
165 fi |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache"
166 fi | while read line; do
176 . ${_EXEC}/templates/videoview.css.sh
179 . ${_EXEC}/templates/videoview.html.sh