2012-10-04 20:34:45 +00:00
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var express = require('express')
|
|
|
|
, $ = require('jquery')
|
|
|
|
, http = require('http')
|
|
|
|
, xml2js = require('xml2js')
|
|
|
|
, app = module.exports = express();
|
|
|
|
|
|
|
|
|
2012-10-04 21:05:09 +00:00
|
|
|
var port = process.env.PORT || 8888;
|
|
|
|
|
2012-10-04 20:34:45 +00:00
|
|
|
var parser = new xml2js.Parser();
|
|
|
|
|
2012-10-07 12:26:16 +00:00
|
|
|
app.use("/css", express.static(__dirname + '/css'));
|
|
|
|
app.use("/", express.static(__dirname + '/public'));
|
|
|
|
app.use("/js", express.static(__dirname + '/js'));
|
2012-10-08 06:26:37 +00:00
|
|
|
app.use("/img", express.static(__dirname + '/img'));
|
2012-10-07 12:17:15 +00:00
|
|
|
|
2012-10-04 20:34:45 +00:00
|
|
|
app.get('/', function(req,res){
|
|
|
|
res.sendfile("public/index.html");
|
|
|
|
});
|
|
|
|
|
2012-10-04 22:23:39 +00:00
|
|
|
app.get('/search', function(req, resp){
|
2012-10-04 20:34:45 +00:00
|
|
|
var options = {
|
|
|
|
host: 'www.goear.com',
|
|
|
|
port: 80,
|
2012-10-13 14:51:17 +00:00
|
|
|
path: '/search/'+encodeURIComponent(req.query['id'].replace(/\s/g , "-"))+'/'+encodeURIComponent(req.query['p'])
|
2012-10-04 20:34:45 +00:00
|
|
|
};
|
2012-10-13 14:51:17 +00:00
|
|
|
console.log("Query:"+req.query['id']);
|
|
|
|
console.log("Querying:"+options.path);
|
2012-10-04 20:34:45 +00:00
|
|
|
|
2012-10-04 22:23:39 +00:00
|
|
|
var results = [];
|
2012-10-04 20:34:45 +00:00
|
|
|
var html = '';
|
|
|
|
http.get(options, function(res) {
|
|
|
|
res.on('data', function(data) {
|
|
|
|
// collect the data chunks to the variable named "html"
|
|
|
|
html += data;
|
|
|
|
}).on('end', function() {
|
|
|
|
// the whole of webpage data has been collected. parsing time!
|
2013-01-24 20:40:42 +00:00
|
|
|
resultsol = $(html).find('ol#results');
|
|
|
|
$(resultsol).find('li').each(function(i,elem){
|
|
|
|
var a=$(elem).find('a');
|
|
|
|
var id=a.attr('href').split('/')[1];
|
|
|
|
var title = a.find('span.songtitleinfo').html();
|
|
|
|
var group = a.find('span.groupnameinfo').html();
|
|
|
|
var quality = $(elem).find('p.comment').html().split('|')[0];
|
2012-10-11 19:22:41 +00:00
|
|
|
if(typeof title != 'undefined' && typeof group != 'undefined' ){
|
2012-10-11 20:49:31 +00:00
|
|
|
results.push({id:id,title:title,group:group,quality:quality})
|
2012-10-11 19:22:41 +00:00
|
|
|
}
|
2012-10-04 20:34:45 +00:00
|
|
|
});
|
2012-10-04 22:23:39 +00:00
|
|
|
console.log("Results:"+JSON.stringify(results));
|
|
|
|
resp.send(JSON.stringify(results));
|
2013-01-24 20:40:42 +00:00
|
|
|
});
|
2012-10-04 20:34:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/play', function(req,resp){
|
|
|
|
var id = req.query['id'];
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
host: 'www.goear.com',
|
|
|
|
port: 80,
|
|
|
|
path: '/tracker758.php?f='+encodeURIComponent(req.query['id'])
|
|
|
|
};
|
|
|
|
|
|
|
|
var xml = '';
|
|
|
|
http.get(options, function(res) {
|
|
|
|
res.setEncoding('utf8');
|
|
|
|
res.on('data', function(data) {
|
|
|
|
xml += data;
|
|
|
|
}).on('end', function() {
|
|
|
|
// the whole of webpage data has been collected. parsing time!
|
|
|
|
parser.parseString(xml, function(err,result){
|
|
|
|
console.log("xml: "+xml);
|
|
|
|
console.log("Object: "+JSON.stringify(result));
|
2012-11-08 13:28:29 +00:00
|
|
|
try{
|
|
|
|
var song = result['songs']['song'][0]["$"];
|
|
|
|
console.log("Song:"+JSON.stringify(song));
|
|
|
|
var path = song['path'];
|
|
|
|
var title = song['title'];
|
|
|
|
var artist = song['artist'];
|
|
|
|
console.log(title + " - " +artist+" - "+path);
|
|
|
|
resp.writeHead(302, {
|
|
|
|
'Location': path
|
|
|
|
//add other headers here...
|
|
|
|
});
|
|
|
|
}
|
2012-11-08 13:39:50 +00:00
|
|
|
catch(exception){
|
|
|
|
console.log(exception);
|
|
|
|
}
|
2012-10-04 20:34:45 +00:00
|
|
|
resp.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-10-04 21:05:09 +00:00
|
|
|
app.listen(port);
|