]> git.plutz.net Git - serve0/blobdiff - actions/watch.sh
generate fresh meta file when playing from directory
[serve0] / actions / watch.sh
index 2a91ce89b751f976d128f30787c8c21023f96aaa..796c654608ba654abf171f79d8a4a78bd6ea8274 100755 (executable)
@@ -2,17 +2,19 @@
 
 cgi_refdata
 info="${_GET[i]}"
+location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
 order="${_REF[o]}"
 search="${_REF[s]}"
 filter="${_REF[f]}"
 page="${_REF[pn]}"
 
 watch_link=''
-[ -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}"
+[ -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
@@ -25,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
@@ -47,8 +51,40 @@ case "${_COOKIE[watch]}" in
     redirect "$videourl"
   ;;
   server)
-    DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
-    redirect "$HTTP_REFERER"
+    [ -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"
+    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" ]; done
+      cp "$metafile" "$playmeta"
+    else
+      rm "$playmeta"
+      "${_EXEC}"/helpers/genmeta.sh "$playuri" "$playmeta" >/dev/null
+    fi
+
+    DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 \
+      nohup /usr/bin/mplayer -ao pulse \
+      -slave -input file="$fifofile" \
+      -volume "$volume" \
+      "$playuri" >"$statusfile" 2>/dev/null &
+
+    # # MPlayer2:
+    # 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}"
   ;;