diff options
author | Jack <jack@encoder.localnet.cc> | 2013-05-07 19:50:02 +0000 |
---|---|---|
committer | Jack <jack@encoder.localnet.cc> | 2013-05-07 19:50:02 +0000 |
commit | 24b941f1fadce69def98c46ea03248f6d0bcee32 (patch) | |
tree | 4158a88b5c694f703fd13bfe3e1145d0074f4f45 | |
parent | 3412f6537cc27f10644b67cd50f757016925b5e7 (diff) | |
download | scripts-24b941f1fadce69def98c46ea03248f6d0bcee32.tar.gz scripts-24b941f1fadce69def98c46ea03248f6d0bcee32.zip |
podcastserver
-rwxr-xr-x | podcastserver/podcastserver.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/podcastserver/podcastserver.py b/podcastserver/podcastserver.py new file mode 100755 index 0000000..fe06cb3 --- /dev/null +++ b/podcastserver/podcastserver.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# encoding: utf-8 +from os.path import relpath,basename +from bottle import route,run,request,response,static_file,jinja2_template,GunicornServer +from glob import glob + +DIRECTORY=None + +@route("/") +def index(): + podcasts = dict() + for cast in glob(DIRECTORY + "/*"): + podcasts[relpath(cast,DIRECTORY)] = sorted(map(lambda p: relpath(p, DIRECTORY), glob(cast+"/*mp3")),reverse=True) + template = """<!doctype html> +<html><head> + <title>xapek.org Podcastserver</title> + <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> + <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> + <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> + <style>audio { width: 100%; }</style> +</head><body> + <h1>Podcastserver</h1> + <div id="podcasts"> + {% for cast,titles in podcasts.items() %} + <h3>{{cast.decode("utf-8")}}</h3> + <div class="podcast"> + {% for file in titles[:15] %} + <a href="/mp3/{{file.decode("utf-8")}}">{{basename(file.decode("utf-8"))}}</a> + (<a class="html5audio" href="#" data-src="/mp3/{{file.decode("utf-8")}}">html5</a>, + <a href="/m3u/{{file.decode("utf-8")}}">playlist</a>) + <br /> + {% endfor %} + </div> + {% endfor %} + </div> + <script> + $(window).load(function() { + $("#podcasts").accordion({collapsible: true, active: false, animate: false, heightStyle: "content"}); + $("a.html5audio").click(function(){ + $(this).parent().after( + $("<audio>").attr("src", $(this).data("src")) + .attr("preload", "none").attr("controls", "true") + .text("No html5 audio support")); + }); + }); + </script> +</body></html>""" + return jinja2_template(template, podcasts=podcasts,basename=basename) + +@route('/mp3/<filename:path>') +def mp3(filename): + return static_file(filename, root=DIRECTORY) + +@route("/m3u/<filename:path>") +def m3u(filename): + response.content_type = "audio/x-mpegurl" + response.body = request.environ['wsgi.url_scheme']+"://"+request.environ['HTTP_HOST'] + "/mp3/" + filename + return response + +if __name__ == '__main__': + from sys import argv,exit + DIRECTORY=( len(argv) == 2 and argv[1] or exit(1)) + server = GunicornServer() + server.options.update({"workers":8,"daemon":False}) + run(host="0.0.0.0",port=8080,server=server,reloader=True,debug=True) + |