<commit_before>var router = require('express').Router();
var request = require('request');
var ytapi = require('./tools/YTAPI.js');

router.get('/:query', function(req, res){
  var host = "https://www.googleapis.com/youtube/v3/search?part=id,snippet&maxResults=50&type=video&videoEmbeddable=true&q=";
  var req_string = host + req.params.query+"&key="+global.config.Keys.YoutubeAPI;
  ytapi.compileResults(req_string, null, 50, function(err, results){
    if(err){
      console.log(err);
      return res.send({Success: false, Error: err});
    }
    var ids = "";
    var cleanvids = {};
    results.forEach(function(result){
      var body = {
        ID: result.id.videoId,
        Title: result.snippet.title,
        Poster: result.snippet.channelTitle,
        Thumbnails: result.snippet.thumbnails
      };
      cleanvids[body.ID] = body;
      ids += body.ID+",";
    });
    ids = ids.substring(0,ids.length-1);
    var qstring = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&maxResults=50&id="+ids+"&key="+global.config.Keys.YoutubeAPI;
    ytapi.compileResults(qstring, null, 25, function(err, innerresults){
      if(err){
        console.log(err);
        return res.send({Success: false, Error: err});
      }<commit_msg>double check that the result is valid<commit_after>var router = require('express').Router();
var request = require('request');
var ytapi = require('./tools/YTAPI.js');

router.get('/:query', function(req, res){
  var host = "https://www.googleapis.com/youtube/v3/search?part=id,snippet&maxResults=50&type=video&videoEmbeddable=true&q=";
  var req_string = host + req.params.query+"&key="+global.config.Keys.YoutubeAPI;
  ytapi.compileResults(req_string, null, 50, function(err, results){
    if(err){
      console.log(err);
      return res.send({Success: false, Error: err});
    }
    var ids = "";
    var cleanvids = {};
    results.forEach(function(result){
      if(!result || !result.id || !result.id.videoId){
        return
      }
      var body = {
        ID: result.id.videoId,
        Title: result.snippet.title,
        Poster: result.snippet.channelTitle,
        Thumbnails: result.snippet.thumbnails
      };
      cleanvids[body.ID] = body;
      ids += body.ID+",";
    });
    ids = ids.substring(0,ids.length-1);
    var qstring = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&maxResults=50&id="+ids+"&key="+global.config.Keys.YoutubeAPI;
    ytapi.compileResults(qstring, null, 25, function(err, innerresults){
      if(err){
        console.log(err);
        return res.send({Success: false, Error: err});
      }
{'fraction_non_alphanumeric': 0.16743119266055045, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 3.4735042735042736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '607274', 'n_tokens_mistral': 888, 'n_tokens_neox': 864, 'n_words': 144}