mirror of
https://github.com/balkian/go5ears.git
synced 2024-11-21 21:02:29 +00:00
Added basic search
This commit is contained in:
parent
08e734215e
commit
aa040292b3
14
player.js
14
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("<p>"+title + " - " + url + "</p>");
|
||||
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));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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<data.length;i++){
|
||||
var title = data[i]["title"];
|
||||
var group = data[i]["group"];
|
||||
var id = data[i]["id"];
|
||||
$("#searchresults").append("<li onClick='playSelected(\""+id+"\")'>"+title+" - "+group+" ["+id+"]</li>");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p onClick='playSelected("fe7e4f9")'>Libertine</p>
|
||||
<p onClick='playSelected("4b9ed95")'>We are the champions</p>
|
||||
<div>
|
||||
Go5ears. Because Flash simply sucks!
|
||||
</div>
|
||||
<div>
|
||||
<audio src="play?id=a78950d" controls="controls"></audio>
|
||||
<ul>
|
||||
<li onClick='playSelected("fe7e4f9")'>Libertine</li>
|
||||
<li onClick='playSelected("4b9ed95")'>We are the champions</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<form method="POST" onsubmit="search(this.goearsearch.value); return false">
|
||||
Search GoEar: <input type="search" name="goearsearch">
|
||||
</form>
|
||||
<ul id="searchresults">
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user