mirror of
https://github.com/balkian/go5ears.git
synced 2024-11-23 13:52:29 +00:00
Using goear_api
This commit is contained in:
parent
208a398d3b
commit
0a217665c7
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "5ears",
|
"name": "5ears",
|
||||||
"description": "Play goear songs in html5",
|
"description": "Play goear songs in html5",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "*",
|
"express": "*",
|
||||||
"jquery": "*",
|
"jquery": "*",
|
||||||
"xml2js": "*"
|
"xml2js": "*",
|
||||||
|
"goear_api": "*"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "0.8.x",
|
"node": "0.8.x",
|
||||||
|
71
player.js
71
player.js
@ -5,7 +5,8 @@ var express = require('express')
|
|||||||
, $ = require('jquery')
|
, $ = require('jquery')
|
||||||
, http = require('http')
|
, http = require('http')
|
||||||
, xml2js = require('xml2js')
|
, xml2js = require('xml2js')
|
||||||
, app = module.exports = express();
|
, app = module.exports = express()
|
||||||
|
, api = require('goear_api');
|
||||||
|
|
||||||
|
|
||||||
var port = process.env.PORT || 8888;
|
var port = process.env.PORT || 8888;
|
||||||
@ -22,78 +23,34 @@ app.get('/', function(req,res){
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/search', function(req, resp){
|
app.get('/search', function(req, resp){
|
||||||
var options = {
|
var query = req.query['id']
|
||||||
host: 'www.goear.com',
|
var page = req.query['p']
|
||||||
port: 80,
|
|
||||||
path: '/search/'+encodeURIComponent(req.query['id'].replace(/\s/g , "-"))+'/'+encodeURIComponent(req.query['p'])
|
|
||||||
};
|
|
||||||
console.log("Query:"+req.query['id']);
|
console.log("Query:"+req.query['id']);
|
||||||
console.log("Querying:"+options.path);
|
console.log("Page:"+page);
|
||||||
|
|
||||||
|
api.search(query, { offset: page }, function(err, data) {
|
||||||
var results = [];
|
var results = [];
|
||||||
var html = '';
|
for( var i in data.tracks){
|
||||||
http.get(options, function(res) {
|
res = data.tracks[i];
|
||||||
res.on('data', function(data) {
|
results.push({id:res.id,title:res.title,group:res.artist,quality:res.quality})
|
||||||
// collect the data chunks to the variable named "html"
|
|
||||||
html += data;
|
|
||||||
}).on('end', function() {
|
|
||||||
// the whole of webpage data has been collected. parsing time!
|
|
||||||
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').text();
|
|
||||||
var group = a.find('span.groupnameinfo').text();
|
|
||||||
var quality = $(elem).find('p.comment').text().split('|')[0];
|
|
||||||
if(typeof title != 'undefined' && typeof group != 'undefined' ){
|
|
||||||
results.push({id:id,title:title,group:group,quality:quality})
|
|
||||||
}
|
}
|
||||||
});
|
console.log("Total songs available: " + data.totalCount);
|
||||||
|
console.log("First title available: " + data.tracks[0].title);
|
||||||
console.log("Results:"+JSON.stringify(results));
|
console.log("Results:"+JSON.stringify(results));
|
||||||
resp.send(JSON.stringify(results));
|
resp.send(JSON.stringify(results));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/play', function(req,resp){
|
app.get('/play', function(req,resp){
|
||||||
var id = req.query['id'];
|
var id = req.query['id'];
|
||||||
|
api.lookup(id, function(err, data){
|
||||||
var options = {
|
console.log('Lookup:', data);
|
||||||
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!
|
|
||||||
xml = xml.replace('&','');
|
|
||||||
parser.parseString(xml, function(err,result){
|
|
||||||
console.log("xml: "+xml);
|
|
||||||
console.log("Object: "+JSON.stringify(result));
|
|
||||||
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, {
|
resp.writeHead(302, {
|
||||||
'Location': path
|
'Location': data.link
|
||||||
//add other headers here...
|
//add other headers here...
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch(exception){
|
|
||||||
console.log(exception);
|
|
||||||
}
|
|
||||||
resp.end();
|
resp.end();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port);
|
app.listen(port);
|
||||||
|
Loading…
Reference in New Issue
Block a user