Example #1
0
yt.searchChannels = function(user_search, page,cb){
    var videos_responses = new Array();
    if (page === 1){
        current_start_index = 1;
    } else {
        current_start_index = (page - 1) * 25 + 1;    
    }
    try{
       videos_responses = new Array();
        var url = 'http://'+ip.address()+':8081/?link=https://gdata.youtube.com/feeds/api/channels?q='+user_search+'&start-index='+current_start_index+'&v=2&alt=json&orderby=relevance';
		request(url, function(err, res, body) {
			if (err) return cb(err);
			if (res.statusCode !== 200) {
			  return cb(new Error('Video not found'));
			}
			cb(JSON.parse(body));
		});
        
        //var req=https.get('https://gdata.youtube.com/feeds/api/channels?q='+user_search+'&start-index='+current_start_index+'&v=2&alt=json&orderby=relevance');
        //req.on('response',function(response) { 
            //var data = new Array(); 
            //response.on("data", function(chunk) {
                //data.push(chunk)
            //});
            //response.on('end',function(){
                //var datas = JSON.parse(data.join(''));
                //cb(datas);
            //});
        //});
        //req.on('error', function(e) {
            //console.log("Got error: " + e.message);
        //});
        //req.end();
    } catch(err){
        console.log('youtube searchChannels err: '+err);
    }
}
Example #2
0
yt.loadChannelSongs = function(url,page,cb){
    if (page === 1){
        current_start_index = 1;
    } else {
        current_start_index = (page - 1) * 25 + 1;    
    }
    try{
       videos_responses = new Array();
        var url = 'http://'+ip.address()+':8081/?link='+url+'&max-results=25&alt=jsonc&start-index='+current_start_index;
		request(url, function(err, res, body) {
			if (err) return cb(err);
			if (res.statusCode !== 200) {
			  return cb(new Error('Video not found'));
			}
			cb(JSON.parse(body));
		});
        
        //var req=https.get(url+'&max-results=25&alt=jsonc&start-index='+current_start_index+'');
        //req.on('response',function(response) { 
            //var data = new Array(); 
            //response.on("data", function(chunk) {
                //data.push(chunk);
            //});
            //response.on('end',function(){
                //var datas = JSON.parse(data.join(''));
                //cb(datas);
            //});
        //});
        //req.on('error', function(e) {
            //console.log("Got error: " + e.message);
        //});
        //req.end();
    } catch(err){
        console.log('youtube searchChannels err: '+err);
    }
}
Example #3
0
        self.configuration, function(error, upnpServer) {
          if (error) {
            callback(error);
            return;
          }

          self.emit("starting");

          var descURL = upnpServer.descriptionPath;
          if (descURL.charAt(0) == "/") {
            descURL = descURL.substring(1);
          }

          var ssdpServer = new SSDP({
            logLevel : self.configuration.ssdpLogLevel, // 'trace',
            log : self.configuration.ssdpLog,
            udn : upnpServer.uuid,
            description : descURL
          });
          self.ssdpServer = ssdpServer;

          ssdpServer.addUSN('upnp:rootdevice');
          ssdpServer.addUSN(upnpServer.type);

          upnpServer.services.forEach(function(service) {
            ssdpServer.addUSN(service.type);
          });

          ssdpServer.on('advertise-alive', function(heads) {
            // console.log('advertise-alive', heads);
            // Expire old devices from your cache.
            // Register advertising device somewhere (as designated in http headers
            // heads)
          });

          ssdpServer.on('advertise-bye', function(heads) {
            // console.log('advertise-bye', heads);
            // Remove specified device from cache.
          });

          var httpServer = http.createServer(function(request, response) {
            var path = url.parse(request.url).pathname;

            // console.log("Uri=" + request.url);

            try {
              upnpServer.processRequest(request, response, path, function(
                  error, processed) {
                // console.log("End of request ", error, processed);

                if (error) {
                  response.writeHead(500, 'Server error: ' + error);
                  response.end();

                  self.emit("error:500", error);
                  return;
                }

                if (!processed) {
                  response.writeHead(404, 'Resource not found: ' + path);
                  response.end();

                  self.emit("error:404", path);
                  return;
                }
              });
            } catch (x) {
              console.error("Process request exception", x);
              self.emit("error", x);
            }
          });
          self.httpServer = httpServer;

          httpServer.listen(upnpServer.port);

          var ssdpHost = self.configuration.hostname;
          if (!ssdpHost || ssdpHost == '0.0.0.0') {
            ssdpHost = nodeip.address();
          }
          ssdpServer.server(ssdpHost, upnpServer.port);

          self.emit("waiting");

          callback(null);
        });