]> git.plutz.net Git - serve0/blob - actions/watch.sh
enable remote controls for server display
[serve0] / actions / watch.sh
1 #!/bin/zsh
2
3 cgi_refdata
4 info="${_GET[i]}"
5 location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
6 order="${_REF[o]}"
7 search="${_REF[s]}"
8 filter="${_REF[f]}"
9 page="${_REF[pn]}"
10
11 watch_link=''
12 [ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&"
13 [ -n "$info" ]     && watch_link="i=$(urlsafe "${info}")&"
14 [ -n "$order" ]    && watch_link="${watch_link}o=${order}&"
15 [ -n "$search" ]   && watch_link="${watch_link}s=${search}&"
16 [ -n "$filter" ]   && watch_link="${watch_link}f=${filter}&"
17 [ -n "$page" ]     && watch_link="${watch_link}pn=${page}"
18
19 meta="${_DATA}/meta/$info.meta"
20 head -n1 "$meta" |read length width height filename
21 [ "$length" -gt 0 ] || length=0
22 [ "$width"  -gt 0 ] || width=0
23 [ "$height" -gt 0 ] || height=0
24
25 linkinfo="$(urlsafe "$info")"
26
27 if [ "${_COOKIE[fakemp4]}" = yes ] && [ "${info##*.}" != mp4 ]; then
28   [ -e "${_DATA}/videos/${info%.*}.mp4" ] || ln -s "${_DATA}/videos/$info" "${_DATA}/mp4/${info%.*}.mp4"
29   videourl="$(urlsafe "mp4/${info%.*}.mp4")"
30 elif [ -z "$info" ]; then
31   videourl="$(urlsafe "${location#/}")"
32 else
33   videourl="$(urlsafe "videos/$info")"
34 fi
35
36 case "${_COOKIE[watch]}" in
37   raspi)
38     rpiaddr="http://pfostenpanne.helmchyn.no-ip.biz/?player=play&path="
39     [ $height -gt 480 -a $width -gt 480 ] && redirect "${rpiaddr}$(urlsafe "http://jupiter:8000/?action=transcode&i=${linkinfo}&t=480")" \
40                                           || redirect "${rpiaddr}$(urlsafe "http://jupiter:8000/${videourl}")"
41   ;;
42   480p)
43     [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \
44                         || redirect "$videourl"
45   ;;
46   240p)
47     [ $height -gt 240 ] && redirect "?action=transcode&i=${linkinfo}&t=240" \
48                         || redirect "$videourl"
49   ;;
50   download)
51     redirect "$videourl"
52   ;;
53   server)
54     [ -n "$location" ] && playuri="${treeroot%/}/${location#/}"
55     [ -n "$info" ]     && playuri="${_DATA}/videos/$info"
56
57     fifofile="${_DATA}/mplayer.fifo"
58     volume="$(validate "$(cat "${_DATA}/mplayer.volume")" '[1-9]?[0-9]|100' 20)"
59     [ \! -p "$fifofile" ] && rm -f "$fifofile" && mkfifo -m 600 "$fifofile"
60
61     DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 \
62       nohup /usr/bin/mplayer -ao pulse --quiet \
63       --slave --input=file="$fifofile" \
64       --volume="$volume" \
65       "$playuri" >/dev/null 2>/dev/null &
66
67     redirect "?p=playctl&${watch_link}"
68   ;;
69   *) redirect "?p=view&${watch_link}"
70   ;;
71 esac
72
73
74