5 location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
6 foreign="$(validate "${_GET[url]}" 'https?://.*' '')"
13 [ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&"
14 [ -n "$info" ] && watch_link="i=$(urlsafe "${info}")&"
15 [ -n "$order" ] && watch_link="${watch_link}o=${order}&"
16 [ -n "$search" ] && watch_link="${watch_link}s=${search}&"
17 [ -n "$filter" ] && watch_link="${watch_link}f=${filter}&"
18 [ -n "$page" ] && watch_link="${watch_link}pn=${page}"
20 meta="${_DATA}/meta/$info.meta"
21 head -n1 "$meta" |read length width height filename
22 [ "$length" -gt 0 ] || length=0
23 [ "$width" -gt 0 ] || width=0
24 [ "$height" -gt 0 ] || height=0
26 linkinfo="$(urlsafe "$info")"
28 if [ "${_COOKIE[fakemp4]}" = yes ] && [ "${info##*.}" != mp4 ]; then
29 [ -e "${_DATA}/videos/${info%.*}.mp4" ] || ln -s "${_DATA}/videos/$info" "${_DATA}/mp4/${info%.*}.mp4"
30 videourl="$(urlsafe "mp4/${info%.*}.mp4")"
31 elif [ -n "$foreign" ]; then
33 videourl="${_GET[url]}"
34 elif [ -z "$info" ]; then
35 videourl="$(urlsafe "${location#/}")"
37 videourl="$(urlsafe "videos/$info")"
40 case "$_COOKIE[watch]" in
42 rpiaddr="http://atoemchen.helmchyn.no-ip.biz/?action=watch&url="
43 redirect "${rpiaddr}$(urlsafe "http://${HTTP_HOST}/${videourl}")"
46 [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \
47 || redirect "$videourl"
50 [ $height -gt 240 ] && redirect "?action=transcode&i=${linkinfo}&t=240" \
51 || redirect "$videourl"
57 [ -n "$location" ] && playuri="${treeroot%/}/${location#/}"
58 [ -n "$info" ] && playuri="${_DATA}/videos/$info"
59 [ -n "$foreign" ] && playuri="$videourl"
61 metafile="${_DATA}/meta/${info}.meta"
63 playmeta="${_DATA}/mplayer.meta"
64 fifofile="${_DATA}/mplayer.fifo"
65 statusfile="${_DATA}/mplayer.status"
66 statusfile="/tmp/mplayer.status"
67 volume="$(validate "$(cat "${_DATA}/mplayer.volume" || true)" '[1-9]?[0-9]|100' 20)"
68 [ \! -p "$fifofile" ] && rm -f "$fifofile" && mkfifo -m 600 "$fifofile"
70 debug PLAYURI "$playuri"
72 if [ -f "$metafile" ]; then
73 cp "$metafile" "$playmeta"
76 "${_EXEC}"/helpers/genmeta.sh "$playuri" "$playmeta" >/dev/null
80 uid="$(id |sed -rn '1s;.*uid=([0-9]+)[^0-9].*;\1;p')"
81 export XDG_RUNTIME_DIR="/run/user/$uid" # required for Pulseaudio
82 xrandr || true >/dev/null # helps enable all screens
84 if mplayer |grep -q MPlayer2; then
85 nohup /usr/bin/mplayer \
86 --slave --input=file="$fifofile" \
88 "$playuri" 2>"$statusfile" >/dev/null &
90 nohup /usr/bin/mplayer \
91 -slave -input file="$fifofile" \
93 "$playuri" >"$statusfile" 2>/dev/null &
96 chmod 600 "$statusfile"
98 redirect "?p=playctl&${watch_link}"
100 *) redirect "?p=view&${watch_link}"