]> git.plutz.net Git - serve0/blobdiff - actions/watch.sh
bugfixes and visual fixes in player control
[serve0] / actions / watch.sh
index d0987177c6e157318b6b46ec4e35ed773100ca1a..c198f4a000f851ebb5a1c48c97133ee3747e2340 100755 (executable)
@@ -27,6 +27,8 @@ 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
@@ -49,12 +51,20 @@ case "${_COOKIE[watch]}" in
     redirect "$videourl"
   ;;
   server)
-    if [ -n "$info" ]; then
-      DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
-    elif [ -n "$location" ]; then
-      DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${treeroot%/}/${location#/}" >/dev/null 2>/dev/null &
-    fi
-    redirect "$HTTP_REFERER"
+    [ -n "$location" ] && playuri="${treeroot%/}/${location#/}"
+    [ -n "$info" ]     && playuri="${_DATA}/videos/$info"
+
+    fifofile="${_DATA}/mplayer.fifo"
+    volume="$(validate "$(cat "${_DATA}/mplayer.volume")" '[1-9]?[0-9]|100' 20)"
+    [ \! -p "$fifofile" ] && rm -f "$fifofile" && mkfifo -m 600 "$fifofile"
+
+    DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 \
+      nohup /usr/bin/mplayer -ao pulse --quiet \
+      --slave --input=file="$fifofile" \
+      --volume="$volume" \
+      "$playuri" >/dev/null 2>/dev/null &
+
+    redirect "?p=playctl&${watch_link}"
   ;;
   *) redirect "?p=view&${watch_link}"
   ;;