5 location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
6 foreign="$(validate "${_GET[url]}" 'https?://.*' '')"
12 watch_link="${_POST[page]}&"
13 [ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&"
14 [ -n "$info" ] && watch_link="i=$(urlsafe "${info}")&"
16 meta="${_DATA}/meta/$info.meta"
17 head -n1 "$meta" |read length width height filename
18 [ "$length" -gt 0 ] || length=0
19 [ "$width" -gt 0 ] || width=0
20 [ "$height" -gt 0 ] || height=0
22 linkinfo="$(urlsafe "$info")"
24 if [ "${_COOKIE[fakemp4]}" = yes ] && [ "${info##*.}" != mp4 ]; then
25 [ -e "${_DATA}/videos/${info%.*}.mp4" ] || ln -s "${_DATA}/videos/$info" "${_DATA}/mp4/${info%.*}.mp4"
26 videourl="$(urlsafe "mp4/${info%.*}.mp4")"
27 elif [ -n "$foreign" ]; then
29 videourl="${_GET[url]}"
30 watch_link="${_GET[return]}"
31 elif [ -z "$info" ]; then
32 videourl="$(urlsafe "${location#/}")"
34 videourl="$(urlsafe "videos/$info")"
37 case "$_COOKIE[watch]" in
39 rpiaddr="http://atoemchen.helmchyn.no-ip.biz/?action=watch"
40 redirect "${rpiaddr}&url=$(urlsafe "http://${HTTP_HOST}/${videourl}")&return=$(urlsafe "http://${HTTP_HOST}/?${_POST[page]}")"
43 [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \
44 || redirect "$videourl"
47 [ $height -gt 240 ] && redirect "?action=transcode&i=${linkinfo}&t=240" \
48 || redirect "$videourl"
54 [ -n "$location" ] && playuri="${treeroot%/}/${location#/}"
55 [ -n "$info" ] && playuri="${_DATA}/videos/$info"
56 [ -n "$foreign" ] && playuri="$videourl"
58 metafile="${_DATA}/meta/${info}.meta"
60 playmeta="${_DATA}/mplayer.meta"
61 fifofile="${_DATA}/mplayer.fifo"
62 statusfile="${_DATA}/mplayer.status"
63 statusfile="/tmp/mplayer.status"
64 volume="$(validate "$(cat "${_DATA}/mplayer.volume" || true)" '[1-9]?[0-9]|100' 20)"
65 [ \! -p "$fifofile" ] && rm -f "$fifofile" && mkfifo -m 600 "$fifofile"
67 debug PLAYURI "$playuri"
69 if [ -f "$metafile" ]; then
70 cp "$metafile" "$playmeta"
73 "${_EXEC}"/helpers/genmeta.sh "$playuri" "$playmeta" >&-
77 uid="$(id |sed -rn '1s;.*uid=([0-9]+)[^0-9].*;\1;p')"
78 export XDG_RUNTIME_DIR="/run/user/$uid" # required for Pulseaudio
79 xrandr || true >&- # helps enable all screens
80 xvkbd -text '\x+10000\y+10000' || true >&-
82 if mplayer |grep -q MPlayer2; then
83 nohup /usr/bin/mplayer \
84 --slave --input=file="$fifofile" \
86 "$playuri" 2>"$statusfile" >&- &
88 nohup /usr/bin/mplayer \
89 -slave -input file="$fifofile" \
91 "$playuri" >"$statusfile" &
94 chmod 600 "$statusfile"
96 redirect "?p=playctl&${watch_link}"
98 *) redirect "?p=view&${watch_link}"