X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=actions%2Fwatch.sh;h=546654c6adfcdd2b7583d615e46d2b31dab94991;hb=9554fea689ec1519a572888aae9dc37ae140cd57;hp=c0cdb377c8904d5849335fbdf4b4c834f34f8054;hpb=7bf56bff8e30ea23047422e05d1ef5352ea9cc31;p=serve0 diff --git a/actions/watch.sh b/actions/watch.sh index c0cdb37..546654c 100755 --- a/actions/watch.sh +++ b/actions/watch.sh @@ -1,19 +1,17 @@ #!/bin/zsh cgi_refdata -cgi_cookie info="${_GET[i]}" -order="${_REF[o]}" -search="${_REF[s]}" -filter="${_REF[f]}" -page="${_REF[pn]}" - -watch_link='' -[ -n "$info" ] && watch_link="i=$(urlsave "${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}" +location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)" +foreign="$(validate "${_GET[url]}" 'https?://.*' '')" +order="${_POST[o]}" +search="${_POST[s]}" +filter="${_POST[f]}" +page="${_POST[pn]}" + +watch_link="${_POST[page]}&" +[ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&" +[ -n "$info" ] && watch_link="i=$(urlsafe "${info}")&" meta="${_DATA}/meta/$info.meta" head -n1 "$meta" |read length width height filename @@ -21,20 +19,25 @@ head -n1 "$meta" |read length width height filename [ "$width" -gt 0 ] || width=0 [ "$height" -gt 0 ] || height=0 -linkinfo="$(urlsave "$info")" +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="$(urlsave "mp4/${info%.*}.mp4")" + videourl="$(urlsafe "mp4/${info%.*}.mp4")" +elif [ -n "$foreign" ]; then + _COOKIE[watch]=server + videourl="${_GET[url]}" + watch_link="${_POST[return]}" +elif [ -z "$info" ]; then + videourl="$(urlsafe "${location#/}")" else - videourl="$(urlsave "videos/$info")" + videourl="$(urlsafe "videos/$info")" fi -case "${_COOKIE[watch]}" in +case "$_COOKIE[watch]" in raspi) - rpiaddr="http://pfostenpanne.helmchyn.no-ip.biz/?player=play&path=" - [ $height -gt 480 -a $width -gt 480 ] && redirect "${rpiaddr}$(urlsave "http://jupiter:8000/?action=transcode&i=${linkinfo}&t=480")" \ - || redirect "${rpiaddr}$(urlsave "http://jupiter:8000/${videourl}")" + rpiaddr="http://atoemchen.helmchyn.no-ip.biz/?action=watch" + redirect "${rpiaddr}&url=$(urlsafe "http://${HTTP_HOST}/${videourl}")&return=$(urlsafe "http://${HTTP_HOST}/?${_POST[page]}")" ;; 480p) [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \ @@ -48,8 +51,49 @@ case "${_COOKIE[watch]}" in redirect "$videourl" ;; server) - DISPLAY=:0 nohup /usr/bin/mplayer -ao pulse:jupiter --quiet "${_DATA}/videos/$info" >&- 2>&- & - redirect "$HTTP_REFERER" + [ -n "$location" ] && playuri="${treeroot%/}/${location#/}" + [ -n "$info" ] && playuri="${_DATA}/videos/$info" + [ -n "$foreign" ] && playuri="$videourl" + + 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" || true)" '[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" >&- + 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 || true >&- # helps enable all screens + xvkbd -text '\x+10000\y+10000' || true >&- + + if mplayer |grep -q MPlayer2; then + nohup /usr/bin/mplayer \ + --slave --input=file="$fifofile" \ + --volume="$volume" \ + "$playuri" 2>"$statusfile" >&- & + else + nohup /usr/bin/mplayer \ + -slave -input file="$fifofile" \ + -volume "$volume" \ + "$playuri" >"$statusfile" & + fi + + chmod 600 "$statusfile" + + redirect "?p=playctl&${watch_link}" ;; *) redirect "?p=view&${watch_link}" ;;