]> git.plutz.net Git - serve0/blobdiff - actions/watch.sh
allow mplayer error output to be written to debug
[serve0] / actions / watch.sh
index e473ac4755d1479bb537272e2972090546effc8a..dbaa919b027e1276cf6b8468f159ea4eb23e33bc 100755 (executable)
@@ -3,6 +3,7 @@
 cgi_refdata
 info="${_GET[i]}"
 location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
+foreign="$(validate "${_GET[url]}" 'https?://.*' '')"
 order="${_POST[o]}"
 search="${_POST[s]}"
 filter="${_POST[f]}"
@@ -27,17 +28,19 @@ 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 [ -n "$foreign" ]; then
+  _COOKIE[watch]=server
+  videourl="${_GET[url]}"
 elif [ -z "$info" ]; then
   videourl="$(urlsafe "${location#/}")"
 else
   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}$(urlsafe "http://jupiter:8000/?action=transcode&i=${linkinfo}&t=480")" \
-                                          || redirect "${rpiaddr}$(urlsafe "http://jupiter:8000/${videourl}")"
+    rpiaddr="http://atoemchen.helmchyn.no-ip.biz/?action=watch&url="
+    redirect "${rpiaddr}$(urlsafe "http://${HTTP_HOST}/${videourl}")"
   ;;
   480p)
     [ $height -gt 480 ] && redirect "?action=transcode&i=${linkinfo}&t=480" \
@@ -53,6 +56,7 @@ case "${_COOKIE[watch]}" in
   server)
     [ -n "$location" ] && playuri="${treeroot%/}/${location#/}"
     [ -n "$info" ]     && playuri="${_DATA}/videos/$info"
+    [ -n "$foreign" ]  && playuri="$videourl"
 
     metafile="${_DATA}/meta/${info}.meta"
 
@@ -60,7 +64,7 @@ case "${_COOKIE[watch]}" in
     fifofile="${_DATA}/mplayer.fifo"
     statusfile="${_DATA}/mplayer.status"
     statusfile="/tmp/mplayer.status"
-    volume="$(validate "$(cat "${_DATA}/mplayer.volume")" '[1-9]?[0-9]|100' 20)"
+    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"
@@ -75,17 +79,19 @@ case "${_COOKIE[watch]}" in
     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 >/dev/null  # helps enable all screens
 
-    nohup /usr/bin/mplayer -ao pulse \
-      -slave -input file="$fifofile" \
-      -volume "$volume" \
-      "$playuri" >"$statusfile" 2>/dev/null &
-
-    # # MPlayer2:
-    # nohup /usr/bin/mplayer -ao pulse \
-    #   --slave --input=file="$fifofile" \
-    #   --volume="$volume" \
-    #   "$playuri" >"$statusfile" 2>/dev/null &
+    if mplayer |grep -q MPlayer2; then
+      nohup /usr/bin/mplayer \
+        --slave --input=file="$fifofile" \
+        --volume="$volume" \
+        "$playuri" 2>"$statusfile" >/dev/null &
+    else
+      nohup /usr/bin/mplayer \
+        -slave -input file="$fifofile" \
+        -volume "$volume" \
+        "$playuri" >"$statusfile" &
+    fi
 
     chmod 600 "$statusfile"