Commit 739bd866 authored by Marco Flowers's avatar Marco Flowers

Using xml library for .xspf

Used xmlbuilder to create the xml for .xspf files replacing string
concatenation.
parent 2100a719
......@@ -6,7 +6,9 @@ var express = require('express'),
bodyParser = require('body-parser'),
qs = require('qs'),
conf = require('konphyg')(__dirname + '/config'),
validator = require('validator');
validator = require('validator'),
xmlbuilder = require('xmlbuilder');
var cache = cache_manager.caching({store: "memory", max: 100, ttl: 10});
var app = express();
......@@ -19,7 +21,7 @@ var index = require('./controllers/index.js')(query, cache, streamApi)
var genres = require('./controllers/genres.js')(query, cache, streamApi);
var formats = require('./controllers/formats.js')(query, cache, streamApi);
var yp_cgi = require('./controllers/yp-cgi.js')(query, qs, validator, config);
var listen = require('./controllers/listen.js')(query, qs, streamApi);
var listen = require('./controllers/listen.js')(query, qs, xmlbuilder, streamApi);
......
var query, cache, streamApi;
var query, cache, xmlbuilder, streamApi;
function init(q, c, s) {
function init(q, c, x, s) {
query = q;
cache = c;
streamApi = s;
xmlbuilder = x;
return getListen;
}
......@@ -44,16 +45,17 @@ function getListen(req, res) {
}
res.send(outputString);
} else if(extension == 'xspf') {
outputString = '<?xml version="1.0" encoding="UTF-8"?>\
\r\n<playlist version="1" xmlns="http://xspf.org/ns/0/">\
\r\n <title>'+rows[0].stream_name+'</title>\
\r\n <info>'+rows[0].url+'</info>\
\r\n <trackList>';
var xml = xmlbuilder.create('playlist', {'version': '1.0', 'encoding': 'UTF-8'});
xml.attribute({'version':'1','xmlns':'http://xspf.org/ns/0/'});
xml.ele("title", rows[0].stream_name);
xml.ele("info", rows[0].url);
var trackList = xml.ele("trackList");
for (var d = 0; d < listenurls.length; d++)
{
outputString +='\r\n <track><location>'+listenurls[d]+'</location></track>';
trackList.ele("track").ele("location", listenurls[d]);
}
outputString +='\r\n </trackList>\r\n</playlist>';
var xmlString = xml.end({ 'pretty': true, 'indent': ' ' });
//console.log(xmlString);
res.set('Content-Type','application/xspf+xml');
res.set('Content-Disposition','filename="listen.xspf"');
if(userAgent.indexOf('/MSIE 5.5/') != -1) {
......@@ -62,7 +64,7 @@ function getListen(req, res) {
else {
res.set('Content-Disposition','filename="listen.xspf"');
}
res.send(outputString);
res.send(xmlString);
}
});
}
......
var query, qs, validator, config;
var async = require('async');
var foreign_key_violation = '23503';
function init(q, q_, v, c) {
query = q;
......@@ -180,7 +181,7 @@ function ypRemove(req, res) {
],
function(err, result) {
if(err) {
if(err.code == '23503') {
if(err.code == foreign_key_violation) {
// couldn't delete stream because other servers still referncing
ypRes(res, true, "Successfully removed", null, null);
} else {
......
......@@ -13,6 +13,7 @@
"pg-query": "0.10.1",
"qs": "^2.3.3",
"swig": "1.4.2",
"validator":"*"
"validator":"*",
"xmlbuilder":"*"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment