]> git.plutz.net Git - serve0/blob - pages/videoview.sh
initial commit
[serve0] / pages / videoview.sh
1 #!/bin/zsh
2
3 # Copyright 2014 Paul Hänsch
4 #
5 # This file is part of Serve0.
6
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.
11
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.
16
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/>. 
19
20 filterdiag() {
21   . ${_EXEC}/templates/filterdiag.html.sh
22 }
23
24 tagger() {
25   n=foot
26   hideall="$(sed -rn "s;^([^:]+):.*$;hide_inline('${n}_\\1')\\;;p" <<<"$taglist" |sort -u)hide_inline('${n}_none');"
27
28   . ${_EXEC}/templates/tagger.html.sh
29 }
30
31 view() {
32   meta="${_DATA}/meta/$info.meta"
33   video="${_DATA}/videos/$info"
34   #reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
35   #[ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
36   tags="$(sed -n '2p' "$meta")"
37   description="$(sed -n '3,$p' "$meta")"
38   length=0; width=0; height=0;
39   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;')
40   
41   taglist=$(
42     for each in ${_DATA}/meta/*.meta; do
43       sed -n '2s:|:\n:gp' "$each"
44     done |sort -u |grep -xv '')
45   
46     . ${_EXEC}/templates/view.html.sh
47 }
48
49 _printVideo(){
50   info="$1"
51   meta="${_DATA}/meta/$info.meta"
52   tags="$(sed -n 2p "$meta")"
53   thumb="${_DATA}/thumbs/$info.jpg"
54   head -n1 "$meta" |read length width height
55   [ -z "$length" ] && length=0
56   [ -z "$width" ] && width=0
57   [ -z "$height" ] && height=0
58
59   video="${_DATA}/videos/$info"
60 #  reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
61   mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )"
62 #  [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
63   [ -r "$meta" ] || ./genmeta.sh "$video" "$meta"
64   [ -r "$thumb" ] || ./genthumb.sh "$video" "$thumb"
65   [ -L "$mpfake" ] || ln -s "../$video" "$mpfake"
66 #    anchor=$(ls videos |grep -xA2 "$info" |tail -n1)
67   video="$(echo "$video" |sed 's/\?/\%6F/g')"
68   thumb="$(echo "$thumb" |sed 's/\?/%6F/g')"
69   mpfake="$(echo "$mpfake" |sed 's/\?/%6F/g')"
70
71   [ "$(($length % 60))" -lt 10 ] &&\
72     minutes="$(($length / 60)):0$(($length % 60))" ||\
73     minutes="$(($length / 60)):$(($length % 60))"
74
75   cat <<VIDEOend
76     <div class="thumb">
77       <a name="$info" href="?i=$info&p=$page&f=$filter&s=$search&o=$order#$anchor"><img src="$thumb"></a>
78       <div class="thumbinfo">
79         <a href="$video"><b>$info</b></a><br>
80         <!-- a href="$reenc">VP8</a -->
81         <a href="$mpfake">fake-mp4</a><br>
82         <input type="checkbox" name="tagsel" value="$info">
83         <span class="coord">${minutes}min</span>
84         <span class="coord">${width}x${height}</span><br>
85         <!--a class="function" href='write/lock.cgi?p=Locations&e=$info&i=$info&f=$filter#$anchor'>edit</a-->
86         <span class="tag">$(sed 's,|$,,;s,|,</span> <span class="tag">,g' <<<"$tags")</span>
87       </div>
88     </div>
89 VIDEOend
90 }
91
92 _by_name(){ ls ${_DATA}/videos/ }
93 _by_date(){ ls -c ${_DATA}/videos/ }
94 _by_length(){ ls ${_DATA}/by_length/ |sed -r 's:[0-9]{5} - ::g' }
95
96 thumblist() {
97   cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&p=${page}"
98   [ -f "$cache" ] && [ "$cache" -ot ${_DATA}/videos -o "$cache" -ot ${_DATA}/meta ] && rm "$cache"
99   if [ -r "$cache" ]; then
100     cat "$cache"
101     exit 0
102   fi
103   
104   filterex="p"
105   for each in $(sed 's,\^, ,g' <<<"$filter"); do
106     if egrep -q '^!' <<<"$each"; then
107       this="$(sed 's,^!,,' <<<"$each")"
108       filterex="/${this}/q;{${filterex}}"
109     else
110       filterex="/${each}/{${filterex}}"
111     fi
112   done
113   
114   case "$order" in
115     Date) genlist="_by_date"
116       ;;
117     Length) genlist="_by_length"
118       ;;
119     *) genlist="_by_name"
120       ;;
121   esac
122     
123   $genlist |while read video; do
124     #video="$(basename "$each")"
125     if [ -n "$search" ] ; then
126       egrep -iq "$search" <<<"$video" <"${_DATA}/meta/$video.meta" && (echo "$video" || exit 0)
127     elif [ "$filterex" != p ]; then
128        [ -n "$(sed -rn "2{$filterex}" "${_DATA}/meta/$video.meta")" ] && (echo "$video" || exit 0)
129     else
130       echo "$video" || exit 0
131     fi
132   done |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p | while read line; do
133     _printVideo "$line"
134   done |tee "$cache"
135 }
136
137 case "$1" in
138   title)
139     echo "Videos"
140   ;;
141   css)
142     . ${_EXEC}/templates/videoview.css.sh
143   ;;
144   body)
145     . ${_EXEC}/templates/videoview.html.sh
146   ;;
147 esac