<commit_before>var flatiron = require('flatiron'),
    path = require('path'),
    plates = require('plates'),
    fs = require('fs'),
    ecstatic = require('ecstatic'),
    pubnub = require('pubnub'),
    events  = new (require('events').EventEmitter)(),
    settings = require('./settings.js'),
    uuid = require('node-uuid'),
    https  = require('https');

var app = flatiron.app;
app.config.file({ file: path.join(__dirname, 'config', 'config.json') });
app.use(flatiron.plugins.http);

var debug = true;

app.router.get('/viewer', function () {
  console.log('/viewer');
  var flat = this;
  fs.readFile('viewer.html', function(err, buffer) {
    //console.log(file);
    var html = buffer.toString();
    var data = { "test": "New Value" };
    var output = plates.bind(html, data); 

    flat.res.writeHead(200, { 'Content-Type': 'text/html' });
    flat.res.end(output);
  });
});

app.router.get('/commander', function () {
  console.log('/commander');
  var flat = this;
  fs.readFile('m-commander.html', function(err, buffer) {
    //console.log(file);
    var html = buffer.toString();
    var data = { "uuid": uuid.v4() };
    var output = plates.bind(html, data); 

    flat.res.writeHead(200, { 'Content-Type': 'text/html' });
    flat.res.end(output);
  });
});


app.http.before = [
  ecstatic(__dirname + '/media', {autoIndex: false})
];

function fail() {
  console.log('fail');
}



var PORT = 3000;
app.start(PORT);
console.log('BOOM port ' + PORT);


/****** PUBNUB *******/

var network = pubnub.init({
  publish_key   : settings.PUBNUB_PUBLISH_KEY,
  subscribe_key : settings.PUBNUB_SUBSCRIBE_KEY,
  secret_key    : settings.PUBNUB_SECRET_KEY,
  ssl           : false,
  origin        : "pubsub.pubnub.com" 
});

network.subscribe({
  channel  : "content_commander",
  callback : function(message) {
    if (debug) { console.log("got message: " + JSON.stringify(message)); }
    events.emit(message.name, message);
  },
  error : function(e) {
    console.log(e);
  }
});

function sendPrivateMessage(uuid, name, data) {
  var message = { "name": name, "data": data },
      channel = "content_commander_" + uuid;
  console.log("channel:");
  console.log(channel);
  network.publish({
    channel  : "content_commander_" + uuid,
    message  : message, 
    callback : function(info) {
      if (!info[0]) { console.log(info[1]); }
      if (debug) { console.log("sent message: " + JSON.stringify(message)); }
    }
  });
}

events.on("search", function(message) {
  console.log("search:");
  console.log(message.data.query);
  search_youtube(message.data.query, message.uuid);
});

function search_youtube(query, uuid) {
  //     title: { '$t': 'Washed Out - Feel it all around', type: 'text' },
  var body = '';

  https.get( {
    host: 'gdata.youtube.com',
    path: '/feeds/api/videos?q=' + query + '&alt=json&orderby=relevance',
    method: 'GET'
  }, function(response) {<commit_msg>fixed string escape bug<commit_after>var flatiron = require('flatiron'),
    path = require('path'),
    plates = require('plates'),
    fs = require('fs'),
    ecstatic = require('ecstatic'),
    pubnub = require('pubnub'),
    events  = new (require('events').EventEmitter)(),
    settings = require('./settings.js'),
    uuid = require('node-uuid'),
    https  = require('https');

var app = flatiron.app;
app.config.file({ file: path.join(__dirname, 'config', 'config.json') });
app.use(flatiron.plugins.http);

var debug = true;

app.router.get('/viewer', function () {
  console.log('/viewer');
  var flat = this;
  fs.readFile('viewer.html', function(err, buffer) {
    //console.log(file);
    var html = buffer.toString();
    var data = { "test": "New Value" };
    var output = plates.bind(html, data); 

    flat.res.writeHead(200, { 'Content-Type': 'text/html' });
    flat.res.end(output);
  });
});

app.router.get('/commander', function () {
  console.log('/commander');
  var flat = this;
  fs.readFile('m-commander.html', function(err, buffer) {
    //console.log(file);
    var html = buffer.toString();
    var data = { "uuid": uuid.v4() };
    var output = plates.bind(html, data); 

    flat.res.writeHead(200, { 'Content-Type': 'text/html' });
    flat.res.end(output);
  });
});


app.http.before = [
  ecstatic(__dirname + '/media', {autoIndex: false})
];

function fail() {
  console.log('fail');
}



var PORT = 3000;
app.start(PORT);
console.log('BOOM port ' + PORT);


/****** PUBNUB *******/

var network = pubnub.init({
  publish_key   : settings.PUBNUB_PUBLISH_KEY,
  subscribe_key : settings.PUBNUB_SUBSCRIBE_KEY,
  secret_key    : settings.PUBNUB_SECRET_KEY,
  ssl           : false,
  origin        : "pubsub.pubnub.com" 
});

network.subscribe({
  channel  : "content_commander",
  callback : function(message) {
    if (debug) { console.log("got message: " + JSON.stringify(message)); }
    events.emit(message.name, message);
  },
  error : function(e) {
    console.log(e);
  }
});

function sendPrivateMessage(uuid, name, data) {
  var message = { "name": name, "data": data },
      channel = "content_commander_" + uuid;
  console.log("channel:");
  console.log(channel);
  network.publish({
    channel  : "content_commander_" + uuid,
    message  : message, 
    callback : function(info) {
      if (!info[0]) { console.log(info[1]); }
      if (debug) { console.log("sent message: " + JSON.stringify(message)); }
    }
  });
}

events.on("search", function(message) {
  console.log("search:");
  console.log(message.data.query);
  search_youtube(message.data.query, message.uuid);
});

function search_youtube(query, uuid) {
  //     title: { '$t': 'Washed Out - Feel it all around', type: 'text' },
  var body = '';

  https.get( {
    host: 'gdata.youtube.com',
    path: '/feeds/api/videos?q=' + escape(query) + '&alt=json&orderby=relevance',
    method: 'GET'
  }, function(response) {
{'fraction_non_alphanumeric': 0.19070403280929596, 'fraction_numerical': 0.004442925495557075, 'mean_word_length': 3.502307692307692, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2387331', 'n_tokens_mistral': 2049, 'n_tokens_neox': 2004, 'n_words': 385}