From 24b941f1fadce69def98c46ea03248f6d0bcee32 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 7 May 2013 19:50:02 +0000 Subject: podcastserver --- podcastserver/podcastserver.py | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 podcastserver/podcastserver.py (limited to 'podcastserver') 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 = """ + + xapek.org Podcastserver + + + + + +

Podcastserver

+
+ {% for cast,titles in podcasts.items() %} +

{{cast.decode("utf-8")}}

+
+ {% for file in titles[:15] %} + {{basename(file.decode("utf-8"))}} + (html5, + playlist) +
+ {% endfor %} +
+ {% endfor %} +
+ +""" + return jinja2_template(template, podcasts=podcasts,basename=basename) + +@route('/mp3/') +def mp3(filename): + return static_file(filename, root=DIRECTORY) + +@route("/m3u/") +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) + -- cgit v1.2.1