From 623e13703a176cf67053c5e21a6d2c71f5a96c55 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 2 Mar 2016 22:40:18 +0000 Subject: [PATCH] enable remote controls for server display svn path=/trunk/; revision=107 --- actions/playctl.sh | 34 +++++++++++ actions/watch.sh | 20 +++++-- pages/playctl.sh | 39 +++++++++++++ templates/common.css.sh | 22 +++++++- templates/playctl.html.sh | 116 ++++++++++++++++++++++++++++++++++++++ templates/view.html.sh | 4 +- 6 files changed, 226 insertions(+), 9 deletions(-) create mode 100755 actions/playctl.sh create mode 100755 pages/playctl.sh create mode 100755 templates/playctl.html.sh diff --git a/actions/playctl.sh b/actions/playctl.sh new file mode 100755 index 0000000..38cd54c --- /dev/null +++ b/actions/playctl.sh @@ -0,0 +1,34 @@ +#!/bin/zsh +# Copyright 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Serve0 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Serve0 If not, see . + +fifofile="${_DATA}/mplayer.fifo" +volfile="${_DATA}/mplayer.volume" + +if [ -n "${_POST[amp]+x}" ]; then + amp $(validate "${_POST[amp]}" '(on|off)' off) +elif [ -n "${_POST[vol]+x}" ]; then + vol=$(validate "${_POST[vol]}" '[1-9]?[0-9]|100' 10) + printf %s\\n $vol >"$volfile" + printf 'volume %s 1\n' $vol >"$fifofile" +elif [ -n "${_POST[ctl]+x}" ]; then + printf '%s\n' $(validate "${_POST[ctl]}" "pause|stop" pause) >"$fifofile" +elif [ -n "${_POST[seek]+x}" ]; then + printf 'seek %s\n' $(validate "${_POST[seek]}" "[+-]?[0-9]+" 0) >"$fifofile" +fi & + +redirect "$HTTP_REFERER" diff --git a/actions/watch.sh b/actions/watch.sh index b79de87..c198f4a 100755 --- a/actions/watch.sh +++ b/actions/watch.sh @@ -51,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#$linkinfo" + [ -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}" ;; diff --git a/pages/playctl.sh b/pages/playctl.sh new file mode 100755 index 0000000..ad6ea24 --- /dev/null +++ b/pages/playctl.sh @@ -0,0 +1,39 @@ +#!/bin/zsh + +# Copyright 2014 2016 Paul Hänsch +# +# This file is part of Serve0. +# +# Serve0 is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Serve0 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Serve0. If not, see . + +. $_EXEC/pages/common.sh + +info="${_GET[i]}" +location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)" +directory="${location%/*}" + +TITLE="$info" + +meta="${_DATA}/meta/$info.meta" +[ -n "$info" ] && video="${_DATA}/videos/$info" \ + || video="${treeroot%/}/${location#/}" +tags="$(sed -n '2p' "$meta")" +description="$(sed -n '3,$p' "$meta")" +length=0; width=0; height=0; + +video="videos/$info" +[ -n "$info" ] && video="videos/$info" \ + || video="${location#/}" + +volume=$(validate "$(cat "$_DATA/mplayer.volume")" '[1-9]?[0-9]|100' 20) diff --git a/templates/common.css.sh b/templates/common.css.sh index adf78cd..62eaabb 100755 --- a/templates/common.css.sh +++ b/templates/common.css.sh @@ -289,7 +289,8 @@ a.panel { } .panel#preferences > input { display: block; } -#videoview h1, #videoview > a { +#videoview h1, #videoview > a, +#playctl h1, #playctl > a { display: inline-block; margin-right: 1em; } @@ -298,6 +299,25 @@ a.panel { margin: 0; width: 100%; } + +#playctl form { text-align: center; } +#playctl form button { + display: inline-block; + height: 100%; + min-height: 2em; + margin: 0 -.75ex 2em 0; + background-color: #EEE; + border: 1px solid #333; + max-width: 4em; + vertical-align: bottom; +} +#playctl form button[name="ctl"] { width: 16%;} +#playctl form button[name="amp"] { width: 15%;} +#playctl form button[name="vol"] { width: 3%; min-height: 1em;} +#playctl form button[name="vol"].selected { background-color: #FA6;} +#playctl form button[name="vol"][value="100"], +#playctl form button[name="vol"][value="0"] { width: 6%;} + EOF # vi:set filetype=css: diff --git a/templates/playctl.html.sh b/templates/playctl.html.sh new file mode 100755 index 0000000..1aada80 --- /dev/null +++ b/templates/playctl.html.sh @@ -0,0 +1,116 @@ +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Serve0 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Serve0 If not, see . + +cat < + + + + + + + Clear All + Dismiss + +
+ + << + $(($page + 1)) + >> +
+ + +
+

$info

+ Download + +
+ + + + + + +
+ + + $(for n in $(seq 0 5 100); do + printf '' "$([ "$volume" = "$n" ] && printf selected)" "$n" + done) +
+ + $(($length / 60)):$(($length % 60)) min + Width: $width + Height: $height
+ + + $(printf %s\\n "$tags" |sed -r 's:\|*([^|]+)\|*:\1:g') + ${description:+$(printf %s "$description" |_wiki)} + +
+ + + + + $( + for cat in $(list_categories); do + printf '

' + done + ) + +

+ + +

+

+ + +

+ + + + Hide + +
+
+ + +EOF + +# vi:set filetype=html: diff --git a/templates/view.html.sh b/templates/view.html.sh index 3c0e3a5..7a89a9e 100755 --- a/templates/view.html.sh +++ b/templates/view.html.sh @@ -28,7 +28,7 @@ cat < Clear All - Dismiss + Dismiss
@@ -91,7 +91,7 @@ cat <