summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpodcastserver/podcastserver.py66
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)
+