web server: Load songs from the library browser
This patch will load a song clicked on in the original library browser. This is a better action than trying to play the song through html5!
This commit is contained in:
parent
7c4f32c30b
commit
8ff437a682
|
@ -5,12 +5,16 @@ from libsaria import path
|
|||
splitext = path.splitext
|
||||
|
||||
def header(wfile):
|
||||
wfile.write("<html><head><script type=\"text/javascript\">")
|
||||
wfile.write("function playSong(id, ext){")
|
||||
wfile.write("var src=id+ext;")
|
||||
wfile.write("var audio = document.getElementById(\"audio\");")
|
||||
wfile.write("audio.innerHTML=\"<audio src=\\\"\" + src + \"\\\" controls autoplay></audio>\";")
|
||||
wfile.write("return false;")
|
||||
wfile.write("<html><head>")
|
||||
wfile.write("<script type=\"text/javascript\" src=\"controls.js\"></script>\n")
|
||||
wfile.write("<script type=\"text/javascript\" src=\"utils.js\"></script>\n")
|
||||
wfile.write("<script type=\"text/javascript\">")
|
||||
wfile.write("function playSong(id){")
|
||||
wfile.write("load_id(id);")
|
||||
#wfile.write("var src=id+ext;")
|
||||
#wfile.write("var audio = document.getElementById(\"audio\");")
|
||||
#wfile.write("audio.innerHTML=\"<audio src=\\\"\" + src + \"\\\" controls autoplay></audio>\";")
|
||||
#wfile.write("return false;")
|
||||
wfile.write("}")
|
||||
wfile.write("</script><body>")
|
||||
|
||||
|
@ -39,13 +43,12 @@ def body(wfile, args):
|
|||
titles = []
|
||||
for title, key in library.titles(args["artist"], args["album"]):
|
||||
sid = library.song_id(args["artist"], args["album"], key)
|
||||
track, filepath = library.get_attrs(sid, "track", "filepath")
|
||||
ext = splitext(filepath)[1]
|
||||
titles += [(track, sid, ext, title)]
|
||||
track = library.get_attrs(sid, "track")
|
||||
titles += [(track, sid, title)]
|
||||
titles.sort()
|
||||
tags = "<tr><td align=right>%s.</td><td><font onclick=\"playSong('%s', '%s');\">%s</font></td></tr>\n"
|
||||
for id, sid, ext, title in titles:
|
||||
wfile.write(tags % (id, sid, ext, title))
|
||||
tags = "<tr><td align=right>%s.</td><td><font onclick=\"playSong('%s');\">%s</font></td></tr>\n"
|
||||
for id, sid, title in titles:
|
||||
wfile.write(tags % (id, sid, title))
|
||||
wfile.write("</table></td>")
|
||||
wfile.write("</tr></table></td></tr>")
|
||||
|
||||
|
|
|
@ -10,6 +10,11 @@ function play()
|
|||
control("play");
|
||||
}
|
||||
|
||||
function load_id(id)
|
||||
{
|
||||
control("load&id="+id);
|
||||
}
|
||||
|
||||
function pause()
|
||||
{
|
||||
control("pause");
|
||||
|
|
|
@ -11,6 +11,7 @@ pause = controls.pause
|
|||
stop = controls.stop
|
||||
next = controls.next
|
||||
attrs = libsaria.sources.get_attrs
|
||||
load_id = libsaria.sources.library.load_id
|
||||
|
||||
playing = controls.playing
|
||||
forward = controls.seek_forward
|
||||
|
@ -43,4 +44,9 @@ def to_html(wfile, args):
|
|||
ret = "by %s" % attrs("artist")
|
||||
elif action == "playing":
|
||||
ret = playing()
|
||||
elif action == "load":
|
||||
load_id(int(args['id']))
|
||||
play()
|
||||
#else:
|
||||
# print action, args
|
||||
wfile.write(str(ret))
|
||||
|
|
Loading…
Reference in New Issue