]> git.plutz.net Git - serve0/blobdiff - actions/watch.sh
extending cooperation functions
[serve0] / actions / watch.sh
index 04c023925962297ffe600556b0e4d40f82d4e6bf..cc47088c0bebc5e73c1b13895a307db1dd51e896 100755 (executable)
@@ -2,16 +2,99 @@
 
 cgi_refdata
 info="${_GET[i]}"
-order="${_REF[o]}"
-search="${_REF[s]}"
-filter="${_REF[f]}"
-page="${_REF[pn]}"
+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}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
+[ "$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: ?p=view&${watch_link}\n\n"