libsaria: Web server controls playback
I can choose songs to play by clicking rows in an html table. I also write text to the client as it becomes available, rather than doing it all at once.
This commit is contained in:
parent
7ffd4e14fd
commit
c02bffb652
|
@ -2,7 +2,7 @@
|
|||
|
||||
function control(action)
|
||||
{
|
||||
send_request("controls.py?a=" + action);
|
||||
send_request("RPC/" + action);
|
||||
}
|
||||
|
||||
function play()
|
||||
|
@ -39,3 +39,8 @@ function rewind()
|
|||
{
|
||||
control("rewind");
|
||||
}
|
||||
|
||||
function play_id(id)
|
||||
{
|
||||
control("play_id/" + id)
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="utils.js"></script>
|
||||
<!--<head>
|
||||
<script type="text/javascript" src="utils.js"></script>-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table>
|
||||
<tr><td><a href="library.py">Library Browser</a></td></tr>
|
||||
<tr><td><a href="library2.py">Library Browser 2</a></td></tr>
|
||||
<tr><td><a href="library.html">Library Browser</a></td></tr>
|
||||
<!--<tr><td><a href="library2.py">Library Browser 2</a></td></tr>
|
||||
<tr><td><a href="controls.html">Remote Controls</a></td></tr>
|
||||
<tr><td id="vers"></td><td id="up"></td></tr>
|
||||
<tr><td id="vers"></td><td id="up"></td></tr>-->
|
||||
</table>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--<script type="text/javascript">
|
||||
set_attr_once("version", "vers");
|
||||
set_attr("uptime", "up");
|
||||
</script>
|
||||
</script>-->
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -11,5 +11,8 @@ def format_path(path):
|
|||
def find_file(path):
|
||||
return pages.has_file(path)
|
||||
|
||||
def open_file(path):
|
||||
return pages.page_text(path)
|
||||
def get_type(path):
|
||||
return pages.file_type(path)
|
||||
|
||||
def send_file(write, path):
|
||||
pages.page_text(write, path)
|
||||
|
|
|
@ -9,19 +9,30 @@ docs.update(rpc.docs)
|
|||
|
||||
types = {
|
||||
"html":"text/html",
|
||||
"js":"text/javascript",
|
||||
}
|
||||
|
||||
def lookup(file):
|
||||
doc = docs
|
||||
for cmp in file:
|
||||
for i, cmp in enumerate(file):
|
||||
doc = doc.get(cmp, None)
|
||||
if doc == None:
|
||||
break
|
||||
return doc
|
||||
elif len(doc) == 2:
|
||||
break
|
||||
return doc, i + 1
|
||||
|
||||
def has_file(file):
|
||||
return lookup(file) != None
|
||||
doc, index = lookup(file)
|
||||
return doc != None
|
||||
|
||||
def page_text(file):
|
||||
func, type = lookup(file)
|
||||
return func(), types[type]
|
||||
def file_type(file):
|
||||
(func, type), index = lookup(file)
|
||||
return type
|
||||
|
||||
def page_text(write, file):
|
||||
(func, type), index = lookup(file)
|
||||
if len(file) > index:
|
||||
res = func(write, file[index:])
|
||||
else:
|
||||
res = func(write)
|
||||
|
|
|
@ -1,11 +1,42 @@
|
|||
# Bryan Schumaker (5 / 15 / 2011)
|
||||
|
||||
def index():
|
||||
text = "<html> \
|
||||
<body>Hello, world!</body> \
|
||||
</html>"
|
||||
return text
|
||||
from libsaria import sources
|
||||
|
||||
SCRIPT = "<script type=\"text/javascript\" src=\"%s\"></script>"
|
||||
|
||||
def write_file(write, file):
|
||||
f = open(file)
|
||||
write(f.read())
|
||||
f.close()
|
||||
|
||||
def index(write):
|
||||
write_file(write, "html/index.html")
|
||||
|
||||
def library(write):
|
||||
write("<html><head>")
|
||||
write(SCRIPT % "controls.js")
|
||||
write(SCRIPT % "utils.js")
|
||||
write("</head><body><table>\n")
|
||||
color = "white"
|
||||
for id, title, artist, album in sources.library.walk_library("id", "title", "artist", "album"):
|
||||
write("<tr style=\"background:%s\" ondblclick=play_id(%s)>" % (color, id))
|
||||
write("<td><a href=\"RPC/play_id/%s\" onclick=\"play_id(%s);return false\">%s</a></td>" % (id, id, title))
|
||||
write("<td>%s</td><td>%s</td>\n" % (artist, album))
|
||||
if color == "white":
|
||||
color = "aliceblue"
|
||||
else:
|
||||
color = "white"
|
||||
write("</table></body></html>")
|
||||
|
||||
def controls(write):
|
||||
write_file(write, "html/controls.js")
|
||||
|
||||
def utils(write):
|
||||
write_file(write, "html/utils.js")
|
||||
|
||||
docs = {
|
||||
"index.html":(index, "html"),
|
||||
"library.html":(library, "html"),
|
||||
"controls.js":(controls, "js"),
|
||||
"utils.js":(utils, "js"),
|
||||
}
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
# Bryan Schumaker (5 / 15 / 2011)
|
||||
|
||||
from libsaria import sources
|
||||
from libsaria import controls
|
||||
|
||||
def play():
|
||||
def play(write):
|
||||
controls.play()
|
||||
return ""
|
||||
write("")
|
||||
|
||||
def pause():
|
||||
def pause(write):
|
||||
controls.pause()
|
||||
return ""
|
||||
write("")
|
||||
|
||||
def play_id(write, id):
|
||||
sources.play_id(long(id[0]))
|
||||
write("")
|
||||
|
||||
rpc = {
|
||||
"play.html":(play, "html"),
|
||||
"pause.html":(pause, "html"),
|
||||
"play_id":(play_id, "html"),
|
||||
}
|
||||
|
||||
docs = {
|
||||
|
|
|
@ -9,9 +9,11 @@ class Handler(BaseHTTPRequestHandler):
|
|||
if not files.find_file(path):
|
||||
self.send_error(404, "File Not Found: %s" % path)
|
||||
return
|
||||
text, type = files.open_file(path)
|
||||
|
||||
type = files.get_type(path)
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', type)
|
||||
self.end_headers()
|
||||
self.wfile.write(text)
|
||||
|
||||
files.send_file(self.wfile.write, path)
|
||||
self.wfile.close()
|
||||
|
|
Loading…
Reference in New Issue