]> git.plutz.net Git - serve0/commitdiff
enable remote controls for server display
authorpaul <paul@plutz.net>
Wed, 2 Mar 2016 22:40:18 +0000 (22:40 +0000)
committerpaul <paul@plutz.net>
Wed, 2 Mar 2016 22:40:18 +0000 (22:40 +0000)
svn path=/trunk/; revision=107

actions/playctl.sh [new file with mode: 0755]
actions/watch.sh
pages/playctl.sh [new file with mode: 0755]
templates/common.css.sh
templates/playctl.html.sh [new file with mode: 0755]
templates/view.html.sh

diff --git a/actions/playctl.sh b/actions/playctl.sh
new file mode 100755 (executable)
index 0000000..38cd54c
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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"
index b79de8758d5497a50c305f585ca166cb0cba6ba3..c198f4a000f851ebb5a1c48c97133ee3747e2340 100755 (executable)
@@ -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 (executable)
index 0000000..ad6ea24
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. 
+
+. $_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)
index adf78cda75d66ba7cabd06f78535e7a01d88b8a7..62eaabb30f96455b5d2d8ae8564e3f54c15be1b7 100755 (executable)
@@ -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 (executable)
index 0000000..1aada80
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. 
+
+cat <<EOF
+<form class="panel" id="search" style="display: block;" action="?" method="get" accept-charset="UTF-8">
+  <input type="text" name="s" value="$search" placeholder="Search">
+
+  <label for="o1" class="order">Order by:</label>
+  <select class="order" size="1" name="o" id="o1">
+    <option>Name</option>
+    <option>Date</option>
+    <option>Length</option>
+  </select>
+  <input type="submit" name="submit" value="Find">
+
+  <a class="panel clearsearch" href="?">Clear All</a>
+  <a class="panel" href="${info:+?p=list&amp;${page_this}}${info:-?p=tree&amp;d=${directory}&amp;${page_this}}#$(urlsafe $info)">Dismiss</a>
+
+  <div class="pagination_nav">
+    <label>Page:</label>
+    <a href="?p=view&amp;${page_prev}">&lt;&lt;</a>
+    <a href="?p=view&amp;${page_this}">$(($page + 1))</a>
+    <a href="?p=view&amp;${page_next}">&gt;&gt;</a>
+  </div>
+</form>
+
+<div id="playctl">
+  <h1>$info</h1>
+  <a href="$video">Download</a>
+
+  <form action="?action=playctl" method="post">
+     <button type="submit" name="seek" value="-60">&lt;&lt;&lt;</button>
+     <button type="submit" name="seek" value="-10">&lt;&lt;</button>
+     <button type="submit" name="ctl" value="stop">&#x25a0;</button>
+     <button type="submit" name="ctl" value="pause">|| / &#x25b6;</button>
+     <button type="submit" name="seek" value="+10">&gt;&gt;</button>
+     <button type="submit" name="seek" value="+60">&gt;&gt;&gt;</button>
+     <br>
+     <button type="submit" name="amp" value="off">Amp Off</button>
+     <button type="submit" name="amp" value="on">Amp On</button>
+     $(for n in $(seq 0 5 100); do
+       printf '<button class="%s" type="submit" name="vol" value="%s">&nbsp;</button>' "$([ "$volume" = "$n" ] && printf selected)" "$n"
+     done)
+  </form>
+
+  <span class="info length">$(($length / 60)):$(($length % 60)) min</span>
+  <span class="info width" >Width: $width</span>
+  <span class="info height">Height: $height</span><br>
+  
+  <label class="tags">Tags:</label>
+  $(printf %s\\n "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
+  ${description:+<span class="info description">$(printf %s "$description" |_wiki)</span>}
+
+  <form class="panel" id="tagger" action="?action=meta&${page_this}" method="post" accept-charset="UTF-8">
+    <input type="hidden" name="length" value="$length">
+    <input type="hidden" name="width" value="$width">
+    <input type="hidden" name="height" value="$height">
+
+    $(
+    for cat in $(list_categories); do
+      printf '<p class="newtag"><label class="category">%s:</label><select name="tag" size="12" multiple>' "${cat}"
+      catt="${cat}:"
+      [ "$catt" = "none:" ] && catt=''
+      
+      printf %s "$taglist" |egrep '^'"$catt"'[^:]+$' |while read line; do
+        printf '<option %s value="%s">%s</option>' \
+               "$(egrep -q "(^|.*\|)$line(\|.*|$)" "$meta" && printf selected)" \
+               "$line" "${line#*:}"
+      done
+      printf '</select></p>'
+    done
+    )
+
+    <p class="newtag additional">
+      <label class="additional">Additional Tags (one per line):</label>
+      <textarea name="tags" rows="4"></textarea>
+    </p>
+    <p class="newtag description">
+      <label class="description">Description:</label>
+      <textarea name="description" rows="4">$description</textarea>
+    </p>
+    <input type="submit" value="Edit!">
+    <input type="submit" name="trash" value="Delete Video">
+
+    <a class="panel toggle" href="#foot">Hide</a>
+
+  </form>
+</div>
+
+<div class="panel footer" id="foot">
+  <a class="panel toggle" href="#tagger">Edit Tags</a>
+
+  <div class="pagination_nav">
+    <label>Page:</label>
+    <a href="?${page_prev}">&lt;&lt;</a>
+    <a href="?${page_this}">$(($page + 1))</a>
+    <a href="?${page_next}">&gt;&gt;</a>
+  </div>
+</div>
+EOF
+
+# vi:set filetype=html:
index 3c0e3a5f6b8525a7b12292265796c9a422f49d39..7a89a9ec31666cc2104dbbe9ea287b1f4bf4149b 100755 (executable)
@@ -28,7 +28,7 @@ cat <<EOF
   <input type="submit" name="submit" value="Find">
 
   <a class="panel clearsearch" href="?">Clear All</a>
-  <a class="panel" href="${info:+?p=list&amp;${page_this}}${info:-?p=tree&amp;d=${directory}&amp;${page_this}}">Dismiss</a>
+  <a class="panel" href="${info:+?p=list&amp;${page_this}#$(urlsave $info)}${info:-?p=tree&amp;d=${directory}&amp;${page_this}}">Dismiss</a>
 
   <div class="pagination_nav">
     <label>Page:</label>
@@ -91,7 +91,7 @@ cat <<EOF
 </div>
 
 <div class="panel footer" id="foot">
-  <a class="panel toggle" href="#tagger">Add Tags</a>
+  <a class="panel toggle" href="#tagger">Edit Tags</a>
 
   <div class="pagination_nav">
     <label>Page:</label>