]> git.plutz.net Git - serve0/blob - actions/watch.sh
adopted update in shcgi
[serve0] / actions / watch.sh
1 #!/bin/zsh
2
3 cgi_refdata
4 info="${_GET[i]}"
5 order="${_REF[o]}"
6 search="${_REF[s]}"
7 filter="${_REF[f]}"
8 page="${_REF[pn]}"
9
10 watch_link=''
11 [ -n "$info" ]   && watch_link="i=$(urlsafe "${info}")&"
12 [ -n "$order" ]  && watch_link="${watch_link}o=${order}&"
13 [ -n "$search" ] && watch_link="${watch_link}s=${search}&"
14 [ -n "$filter" ] && watch_link="${watch_link}f=${filter}&"
15 [ -n "$page" ]   && watch_link="${watch_link}pn=${page}"
16
17 meta="${_DATA}/meta/$info.meta"
18 head -n1 "$meta" |read length width height filename
19 [ "$length" -gt 0 ] || length=0
20 [ "$width"  -gt 0 ] || width=0
21 [ "$height" -gt 0 ] || height=0
22
23 linkinfo="$(urlsafe "$info")"
24
25 if [ "${_COOKIE[fakemp4]}" = yes ] && [ "${info##*.}" != mp4 ]; then
26   [ -e "${_DATA}/videos/${info%.*}.mp4" ] || ln -s "${_DATA}/videos/$info" "${_DATA}/mp4/${info%.*}.mp4"
27   videourl="$(urlsafe "mp4/${info%.*}.mp4")"
28 else
29   videourl="$(urlsafe "videos/$info")"
30 fi
31
32 case "${_COOKIE[watch]}" in
33   raspi)
34     rpiaddr="http://pfostenpanne.helmchyn.no-ip.biz/?player=play&path="
35     [ $height -gt 480 -a $width -gt 480 ] && redirect "${rpiaddr}$(urlsafe "http://jupiter:8000/?action=transcode&i=${linkinfo}&t=480")" \
36                                           || redirect "${rpiaddr}$(urlsafe "http://jupiter:8000/${videourl}")"
37   ;;
38   480p)
39     [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \
40                         || redirect "$videourl"
41   ;;
42   240p)
43     [ $height -gt 240 ] && redirect "?action=transcode&i=${linkinfo}&t=240" \
44                         || redirect "$videourl"
45   ;;
46   download)
47     redirect "$videourl"
48   ;;
49   server)
50     DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
51     redirect "$HTTP_REFERER"
52   ;;
53   *) redirect "?p=view&${watch_link}"
54   ;;
55 esac
56
57
58