diff --git a/.gitignore b/.gitignore index 7dccd97..233c882 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.swp lib-cov *.seed *.log @@ -12,4 +13,4 @@ logs results node_modules -npm-debug.log \ No newline at end of file +npm-debug.log diff --git a/package.json b/package.json new file mode 100644 index 0000000..e7e1a02 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "5ears", + "description": "Play goear songs in html5", + "version": "0.0.1", + "private": true, + "dependencies": { + "express": "3.x", + "jquery": "*", + "xml2js": "*" + } +} diff --git a/player.js b/player.js new file mode 100644 index 0000000..dcfd6d6 --- /dev/null +++ b/player.js @@ -0,0 +1,86 @@ +/** + * Module dependencies. + */ +var express = require('express') +, $ = require('jquery') +, http = require('http') +, xml2js = require('xml2js') +, app = module.exports = express(); + + +var parser = new xml2js.Parser(); + +app.get('/', function(req,res){ + res.sendfile("public/index.html"); +}); + +app.get('/goear', function(req,res){ + jquery.get(req.query['id'],null,function(data, textStatus,jqXHR){ + res.write("PidiĆ³:"+req.query['id']); + res.end(); +}); +}); + +app.get('/nodetube', function(req, resp){ + var options = { + host: 'www.goear.com', + port: 80, + path: '/search.php?q='+encodeURIComponent(req.query['id']) + }; + + 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! + $(html).find('.play').each(function(i,elem){ + var prev = $(elem).prev(); + var url = prev.attr("href").split("/")[1]; + var title = prev.text(); + console.log(title + " - " +url); + resp.write("
"+title + " - " + url + "
"); + }); + resp.end(); + }); + }); + +}); + +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)); + 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... + }); + resp.end(); + }); + }); + }); +}); + +app.listen(8888); diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..2f9fa4c --- /dev/null +++ b/public/index.html @@ -0,0 +1,15 @@ + + + + + + +Libertine
+We are the champions
+ + +