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
|
splitext = path.splitext
|
||||||
|
|
||||||
def header(wfile):
|
def header(wfile):
|
||||||
wfile.write("<html><head><script type=\"text/javascript\">")
|
wfile.write("<html><head>")
|
||||||
wfile.write("function playSong(id, ext){")
|
wfile.write("<script type=\"text/javascript\" src=\"controls.js\"></script>\n")
|
||||||
wfile.write("var src=id+ext;")
|
wfile.write("<script type=\"text/javascript\" src=\"utils.js\"></script>\n")
|
||||||
wfile.write("var audio = document.getElementById(\"audio\");")
|
wfile.write("<script type=\"text/javascript\">")
|
||||||
wfile.write("audio.innerHTML=\"<audio src=\\\"\" + src + \"\\\" controls autoplay></audio>\";")
|
wfile.write("function playSong(id){")
|
||||||
wfile.write("return false;")
|
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("}")
|
||||||
wfile.write("</script><body>")
|
wfile.write("</script><body>")
|
||||||
|
|
||||||
|
@ -39,13 +43,12 @@ def body(wfile, args):
|
||||||
titles = []
|
titles = []
|
||||||
for title, key in library.titles(args["artist"], args["album"]):
|
for title, key in library.titles(args["artist"], args["album"]):
|
||||||
sid = library.song_id(args["artist"], args["album"], key)
|
sid = library.song_id(args["artist"], args["album"], key)
|
||||||
track, filepath = library.get_attrs(sid, "track", "filepath")
|
track = library.get_attrs(sid, "track")
|
||||||
ext = splitext(filepath)[1]
|
titles += [(track, sid, title)]
|
||||||
titles += [(track, sid, ext, title)]
|
|
||||||
titles.sort()
|
titles.sort()
|
||||||
tags = "<tr><td align=right>%s.</td><td><font onclick=\"playSong('%s', '%s');\">%s</font></td></tr>\n"
|
tags = "<tr><td align=right>%s.</td><td><font onclick=\"playSong('%s');\">%s</font></td></tr>\n"
|
||||||
for id, sid, ext, title in titles:
|
for id, sid, title in titles:
|
||||||
wfile.write(tags % (id, sid, ext, title))
|
wfile.write(tags % (id, sid, title))
|
||||||
wfile.write("</table></td>")
|
wfile.write("</table></td>")
|
||||||
wfile.write("</tr></table></td></tr>")
|
wfile.write("</tr></table></td></tr>")
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ function play()
|
||||||
control("play");
|
control("play");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load_id(id)
|
||||||
|
{
|
||||||
|
control("load&id="+id);
|
||||||
|
}
|
||||||
|
|
||||||
function pause()
|
function pause()
|
||||||
{
|
{
|
||||||
control("pause");
|
control("pause");
|
||||||
|
|
|
@ -11,6 +11,7 @@ pause = controls.pause
|
||||||
stop = controls.stop
|
stop = controls.stop
|
||||||
next = controls.next
|
next = controls.next
|
||||||
attrs = libsaria.sources.get_attrs
|
attrs = libsaria.sources.get_attrs
|
||||||
|
load_id = libsaria.sources.library.load_id
|
||||||
|
|
||||||
playing = controls.playing
|
playing = controls.playing
|
||||||
forward = controls.seek_forward
|
forward = controls.seek_forward
|
||||||
|
@ -43,4 +44,9 @@ def to_html(wfile, args):
|
||||||
ret = "by %s" % attrs("artist")
|
ret = "by %s" % attrs("artist")
|
||||||
elif action == "playing":
|
elif action == "playing":
|
||||||
ret = playing()
|
ret = playing()
|
||||||
|
elif action == "load":
|
||||||
|
load_id(int(args['id']))
|
||||||
|
play()
|
||||||
|
#else:
|
||||||
|
# print action, args
|
||||||
wfile.write(str(ret))
|
wfile.write(str(ret))
|
||||||
|
|
Loading…
Reference in New Issue