From aa040292b30ff559ff7fefdb3e6ed2e570781d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2EFernando=20S=C3=A1nchez?= Date: Fri, 5 Oct 2012 00:23:39 +0200 Subject: [PATCH] Added basic search --- player.js | 14 ++++++++------ public/index.html | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/player.js b/player.js index d92ccfe..8c6f1f0 100644 --- a/player.js +++ b/player.js @@ -23,13 +23,14 @@ app.get('/goear', function(req,res){ }); }); -app.get('/nodetube', function(req, resp){ +app.get('/search', function(req, resp){ var options = { host: 'www.goear.com', port: 80, path: '/search.php?q='+encodeURIComponent(req.query['id']) }; + var results = []; var html = ''; http.get(options, function(res) { res.on('data', function(data) { @@ -39,12 +40,13 @@ app.get('/nodetube', function(req, resp){ // 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 + "

"); + var title = $(prev).children(".song").text(); + var group = $(prev).children(".group").text(); + var id = prev.attr("href").split("/")[1]; + results.push({id:id,"title":title,group:group}) }); - resp.end(); + console.log("Results:"+JSON.stringify(results)); + resp.send(JSON.stringify(results)); }); }); diff --git a/public/index.html b/public/index.html index 2f9fa4c..54a9bae 100644 --- a/public/index.html +++ b/public/index.html @@ -5,11 +5,40 @@ function playSelected(id){ $("audio").attr("src","play?id="+id); } + function search(term){ + $.ajax({url:'/search?id='+term, + dataType: 'json', + success: function(data){ + alert("SUCCESS"); + for(var i=0; i"+title+" - "+group+" ["+id+"]"); + } + } + }); + }; -

Libertine

-

We are the champions

+
+Go5ears. Because Flash simply sucks! +
+
+
    +
  • Libertine
  • +
  • We are the champions
  • +
+
+
+
+ Search GoEar: +
+
    + +
+