mirror of
				https://github.com/balkian/go5ears.git
				synced 2025-11-04 01:28:20 +00:00 
			
		
		
		
	Added basic search
This commit is contained in:
		
							
								
								
									
										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 = {
 | 
					     var options = {
 | 
				
			||||||
        host: 'www.goear.com',
 | 
					        host: 'www.goear.com',
 | 
				
			||||||
        port: 80,
 | 
					        port: 80,
 | 
				
			||||||
        path: '/search.php?q='+encodeURIComponent(req.query['id'])
 | 
					        path: '/search.php?q='+encodeURIComponent(req.query['id'])
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var results = [];
 | 
				
			||||||
    var html = '';
 | 
					    var html = '';
 | 
				
			||||||
    http.get(options, function(res) {
 | 
					    http.get(options, function(res) {
 | 
				
			||||||
        res.on('data', function(data) {
 | 
					        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!
 | 
					            // the whole of webpage data has been collected. parsing time!
 | 
				
			||||||
            $(html).find('.play').each(function(i,elem){
 | 
					            $(html).find('.play').each(function(i,elem){
 | 
				
			||||||
                var prev = $(elem).prev();
 | 
					                var prev = $(elem).prev();
 | 
				
			||||||
                var url = prev.attr("href").split("/")[1];
 | 
					                var title = $(prev).children(".song").text();
 | 
				
			||||||
                var title = prev.text();
 | 
					                var group = $(prev).children(".group").text();
 | 
				
			||||||
                console.log(title + " - " +url);
 | 
					                var id = prev.attr("href").split("/")[1];
 | 
				
			||||||
                resp.write("<p>"+title + " - " + url + "</p>");
 | 
					                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){
 | 
					            function playSelected(id){
 | 
				
			||||||
                $("audio").attr("src","play?id="+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>
 | 
					        </script>
 | 
				
			||||||
    </head>
 | 
					    </head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
<p onClick='playSelected("fe7e4f9")'>Libertine</p>
 | 
					<div>
 | 
				
			||||||
<p onClick='playSelected("4b9ed95")'>We are the champions</p>
 | 
					Go5ears. Because Flash simply sucks!
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					<div>
 | 
				
			||||||
<audio src="play?id=a78950d" controls="controls"></audio>
 | 
					<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>
 | 
					</body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user