From 97d1ea7c728d4b043daccb2d76619de30e9e88b2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 18 Jan 2016 15:59:02 +0100 Subject: [PATCH] first release --- cgi-bin/icecast_last_songs.cgi | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 cgi-bin/icecast_last_songs.cgi diff --git a/cgi-bin/icecast_last_songs.cgi b/cgi-bin/icecast_last_songs.cgi new file mode 100755 index 0000000..7b2cb15 --- /dev/null +++ b/cgi-bin/icecast_last_songs.cgi @@ -0,0 +1,25 @@ +#!/usr/bin/python + +import re +import sys + +print "Content-type: application/json" +print "" + +f = open("/var/log/icecast2/playlist.log", 'r') + +print "[" + +first = True +for line in f: + p = re.compile("([^|]+)\|(.+)\|([0-9]+)\|(.+)") + m = p.match(line) + + if first: + first = False + else: + print ',' + + sys.stdout.write("{ \"date\": \"" + m.group(1) + "\", \"listeners\": " + m.group(3) + ", \"song\": \"" + m.group(4) + "\" }") + +print "]" -- 2.7.4