X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=actions%2Fwatch.sh;h=cc47088c0bebc5e73c1b13895a307db1dd51e896;hb=efefeef8289f064b3875b9bae1d1b007f5c1d5f8;hp=8b0ee46bd96115cd6d51adf19a8abc3a89e3e77b;hpb=563bd9812b0eb73ae4e49de012e0f67ed836faaf;p=serve0 diff --git a/actions/watch.sh b/actions/watch.sh index 8b0ee46..cc47088 100755 --- a/actions/watch.sh +++ b/actions/watch.sh @@ -1,17 +1,100 @@ #!/bin/zsh cgi_refdata -info="$_GET[\"i\"]" -order="$_REF[\"o\"]" -search="$_REF[\"s\"]" -filter="$_REF[\"f\"]" -page="$_REF[\"p\"]" +info="${_GET[i]}" +watch="${_GET[w]:-${_COOKIE[watch]}}" +location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)" +order="${_POST[o]}" +search="${_POST[s]}" +filter="${_POST[f]}" +page="${_POST[pn]}" watch_link='' -[ -n "$info" ] && watch_link="i=$(echo -n "${info}" |sed -r 's:%:%25:g;s:\&:%26:g;')&" -[ -n "$order" ] && watch_link="${watch_link}o=${order}&" -[ -n "$search" ] && watch_link="${watch_link}s=${search}&" -[ -n "$filter" ] && watch_link="${watch_link}f=${filter}&" -[ -n "$page" ] && watch_link="${watch_link}p=${page}" +[ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&" +[ -n "$info" ] && watch_link="i=$(urlsafe "${info}")&" +[ -n "$order" ] && watch_link="${watch_link}o=${order}&" +[ -n "$search" ] && watch_link="${watch_link}s=${search}&" +[ -n "$filter" ] && watch_link="${watch_link}f=${filter}&" +[ -n "$page" ] && watch_link="${watch_link}pn=${page}" + +meta="${_DATA}/meta/$info.meta" +head -n1 "$meta" |read length width height filename +[ "$length" -gt 0 ] || length=0 +[ "$width" -gt 0 ] || width=0 +[ "$height" -gt 0 ] || height=0 + +linkinfo="$(urlsafe "$info")" + +if [ "${_COOKIE[fakemp4]}" = yes ] && [ "${info##*.}" != mp4 ]; then + [ -e "${_DATA}/videos/${info%.*}.mp4" ] || ln -s "${_DATA}/videos/$info" "${_DATA}/mp4/${info%.*}.mp4" + videourl="$(urlsafe "mp4/${info%.*}.mp4")" +elif [ -z "$info" ]; then + videourl="$(urlsafe "${location#/}")" +else + videourl="$(urlsafe "videos/$info")" +fi + +case "$watch" in + raspi) + rpiaddr="http://atoemchen.helmchyn.no-ip.biz/?action=watch&w=server&i=" + redirect "${rpiaddr}$(urlsafe "http://jupiter:8000/${videourl}")" + ;; + 480p) + [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \ + || redirect "$videourl" + ;; + 240p) + [ $height -gt 240 ] && redirect "?action=transcode&i=${linkinfo}&t=240" \ + || redirect "$videourl" + ;; + download) + redirect "$videourl" + ;; + server) + [ -n "$location" ] && playuri="${treeroot%/}/${location#/}" + [ -n "$info" ] && playuri="${_DATA}/videos/$info" + + metafile="${_DATA}/meta/${info}.meta" + + playmeta="${_DATA}/mplayer.meta" + fifofile="${_DATA}/mplayer.fifo" + statusfile="${_DATA}/mplayer.status" + statusfile="/tmp/mplayer.status" + volume="$(validate "$(cat "${_DATA}/mplayer.volume")" '[1-9]?[0-9]|100' 20)" + [ \! -p "$fifofile" ] && rm -f "$fifofile" && mkfifo -m 600 "$fifofile" + + debug PLAYURI "$playuri" + + if [ -f "$metafile" ]; then + cp "$metafile" "$playmeta" + else + rm "$playmeta" + "${_EXEC}"/helpers/genmeta.sh "$playuri" "$playmeta" >/dev/null + fi + + export DISPLAY=":0" + uid="$(id |sed -rn '1s;.*uid=([0-9]+)[^0-9].*;\1;p')" + export XDG_RUNTIME_DIR="/run/user/$uid" # required for Pulseaudio + xrandr >/dev/null # helps enable all screens + + # nohup /usr/bin/mplayer \ + # -slave -input file="$fifofile" \ + # -volume "$volume" \ + # "$playuri" >"$statusfile" 2>/dev/null & + + # MPlayer2: (statusline on stderr) + nohup /usr/bin/mplayer \ + --slave --input=file="$fifofile" \ + --volume="$volume" \ + "$playuri" 2>"$statusfile" >/dev/null & + + chmod 600 "$statusfile" + + redirect "?p=playctl&${watch_link}" + ;; + *) redirect "?p=view&${watch_link}" + ;; +esac + + -echo -n "Location: ?page=view&${watch_link}\n\n"