JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
initial version (working)
[cmus-lan-control.git] / make_page.sh
diff --git a/make_page.sh b/make_page.sh
new file mode 100755 (executable)
index 0000000..de49eb8
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+# Copyright (C) 2010 Jason Woofenden
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+HIDE_PREFIX="$HOME/music/"
+
+# escape / and \ so we can pass this to sed
+HIDE_PREFIX="`echo "$HIDE_PREFIX" | sed -e 's/\([\\\/]\)/\\\\\1/g'`"
+
+if test "$1" '!=' ''
+then
+       PLAYLIST="$1"
+else
+       PLAYLIST="$HOME/.cmus/lib.pl"
+fi
+
+exec <"$PLAYLIST"
+
+PLAY_LINK='<a href="do.php?action=play&amp;file='
+PLAY_LINK2='">play</a>'
+QUEUE_LINK='<a href="do.php?action=queue&amp;file='
+QUEUE_LINK2='">queue</a>'
+
+cat <<EOF
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <title>cmus command page</title>
+  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
+  <script type="text/javascript">
+    \$(function() {
+      var loading = \$('#loading');
+      \$('a').click(function(event) {
+        event.preventDefault();
+        loading.html('connecting...');
+        loading.load(this.href);
+      });
+    });
+  </script>
+</head>
+
+<body>
+<div style="position: fixed; width: 100%; height: 20px; background: #ffc; padding: 3px; border: 2px solid #ee0; top: 0; left: 0"><a href="do.php?action=pause">pause</a> <a href="do.php?action=prev">prev</a> <a href="do.php?action=next">next</a> <a href="do.php?action=voldown">quieter</a> <a href="do.php?action=volup">louder</a>  &mdash; Status: <span id="loading">OK</span></div>
+<div style="height: 25px"></div>
+EOF
+
+while read
+do
+       FILEPATH="$REPLY"
+       DISPLAY="`echo "$REPLY" | sed -e "s/$HIDE_PREFIX//"`"
+       #echo sed -e "s/$HIDE_PREFIX//"
+       echo "<div>$DISPLAY $PLAY_LINK$FILEPATH$PLAY_LINK2 $QUEUE_LINK$FILEPATH$QUEUE_LINK2</div>"
+done
+
+cat <<EOF
+</body>
+</html>
+EOF