<commit_before>'use strict';
var bodyparser = require('body-parser');
var http = require('http');
var request = require('request');
module.exports = function (router) {
  router.use(bodyparser.json());

  // takes user's artist and gets a list of matches
  router.get('/discovery/artist/:name', function(req, res) {
    request({
      url: 'https://api.spotify.com/v1/search',
      qs: {q:'artist:' + req.params.name, type:'artist', limit: 10 },
      method: 'GET'}, function(err, response, body) {
        if(err) {
          console.log(err);
          return res.status(500).json({msg: 'internal server error'});
        }
        else {
          var array = JSON.parse(body);
          var results = [];
          array.artists.items.forEach(function(data) {
            var artist = {};
            artist.id = data.id;
            artist.name = data.name;
            artist.popularity = data.popularity;
            if(data.images[0]) {
              if(data.images[data.images.length - 2]) artist.url = data.images[data.images.length - 2].url;
              else artist.url = data.images[data.images.length - 1].url;
            }
            results.push(artist);
          });
          res.json({artists: results});
        }
      }
    );
    });

    router.get('/discovery/genre/:genre', function(req, res) {
      request({
        url: 'https://api.spotify.com/v1/search',
        qs: {q:'genre:' + req.params.genre, type:'artist', limit: 10 },
        method: 'GET'}, function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
          else {
            var array = JSON.parse(body);
            var results = [];
            array.artists.items.forEach(function(data) {
              var artist = {};
              artist.id = data.id;
              artist.name = data.name;
              artist.popularity = data.popularity;
              if(data.images[0]) {
                if(data.images[data.images.length - 2]) artist.url = data.images[data.images.length - 2].url;
                else artist.url = data.images[data.images.length - 1].url;
              }
              results.push(artist);
            });
            res.json({artists: results});
        }
      });
    });

    router.get('/discovery/related/:id', function(req, res) {
      request({
        url: 'https://api.spotify.com/v1/artists/' + req.params.id + '/related-artists',
        method: 'GET'}, function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
            var array = JSON.parse(body);
            var results = [];
            if(array.error) return res.status(404).json({msg: 'artist not found'});
            array.artists.forEach(function(data) {
              var artist = {};
              artist.id = data.id;
              artist.name = data.name;
              artist.popularity = data.popularity;
              if(data.images[0]) {
                if(data.images[data.images.length - 2]) artist.url = data.images[data.images.length - 2].url;
                else artist.url = data.images[data.images.length - 1].url;
              }
              results.push(artist);
            });
            res.json({artists: results});
      });
    });

    router.get('/discovery/top-tracks/:id', function(req, res) {
      request({
        url: 'https://api.spotify.com/v1/artists/' + req.params.id + '/top-tracks',
        qs: {country: 'US'},
        method: 'GET' } ,function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
          var array = JSON.parse(body);
          var results = [];
          if(array.error) return res.status(404).json({msg: 'artist not found'});
          array.tracks.forEach(function(data) {
            var track = {};
            track.id = data.id;
            track.name = data.name;
            track.popularity = data.popularity;
            results.push(track);
          });
          res.json({tracks: results});
      });
    });

    router.get('/discovery/youtube/:q', function(req, res) {
      request({
        url: 'https://www.googleapis.com/youtube/v3/search',
        qs: {part: 'snippet', q: req.params.q, type:'video', key: process.env.YOUTUBE_API_KEY},
        method: 'GET' } , function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
          var results = [];
          var array = JSON.parse(body);
          array.items.forEach(function(data) {
            var video = {};
            video.id = data.id.videoId;
            video.title = data.snippet.title;
            video.thumb = data.snippet.thumbnails.default.url;
            results.push(video);
          });
          res.json({videos: results});
        });
      });
};
<commit_msg>more big pics<commit_after>'use strict';
var bodyparser = require('body-parser');
var http = require('http');
var request = require('request');
module.exports = function (router) {
  router.use(bodyparser.json());

  // takes user's artist and gets a list of matches
  router.get('/discovery/artist/:name', function(req, res) {
    request({
      url: 'https://api.spotify.com/v1/search',
      qs: {q:'artist:' + req.params.name, type:'artist', limit: 10 },
      method: 'GET'}, function(err, response, body) {
        if(err) {
          console.log(err);
          return res.status(500).json({msg: 'internal server error'});
        }
        else {
          var array = JSON.parse(body);
          var results = [];
          array.artists.items.forEach(function(data) {
            var artist = {};
            artist.id = data.id;
            artist.name = data.name;
            artist.popularity = data.popularity;
            if(data.images[0]) artist.url = data.images[0].url;
            results.push(artist);
          });
          res.json({artists: results});
        }
      }
    );
    });

    router.get('/discovery/genre/:genre', function(req, res) {
      request({
        url: 'https://api.spotify.com/v1/search',
        qs: {q:'genre:' + req.params.genre, type:'artist', limit: 10 },
        method: 'GET'}, function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
          else {
            var array = JSON.parse(body);
            var results = [];
            array.artists.items.forEach(function(data) {
              var artist = {};
              artist.id = data.id;
              artist.name = data.name;
              artist.popularity = data.popularity;
              if(data.images[0]) artist.url = data.images[0].url;
              results.push(artist);
            });
            res.json({artists: results});
        }
      });
    });

    router.get('/discovery/related/:id', function(req, res) {
      request({
        url: 'https://api.spotify.com/v1/artists/' + req.params.id + '/related-artists',
        method: 'GET'}, function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
            var array = JSON.parse(body);
            var results = [];
            if(array.error) return res.status(404).json({msg: 'artist not found'});
            array.artists.forEach(function(data) {
              var artist = {};
              artist.id = data.id;
              artist.name = data.name;
              artist.popularity = data.popularity;
              if(data.images[0]) artist.url = data.images[0].url;
              results.push(artist);
            });
            res.json({artists: results});
      });
    });

    router.get('/discovery/top-tracks/:id', function(req, res) {
      request({
        url: 'https://api.spotify.com/v1/artists/' + req.params.id + '/top-tracks',
        qs: {country: 'US'},
        method: 'GET' } ,function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
          var array = JSON.parse(body);
          var results = [];
          if(array.error) return res.status(404).json({msg: 'artist not found'});
          array.tracks.forEach(function(data) {
            var track = {};
            track.id = data.id;
            track.name = data.name;
            track.popularity = data.popularity;
            results.push(track);
          });
          res.json({tracks: results});
      });
    });

    router.get('/discovery/youtube/:q', function(req, res) {
      request({
        url: 'https://www.googleapis.com/youtube/v3/search',
        qs: {part: 'snippet', q: req.params.q, type:'video', key: process.env.YOUTUBE_API_KEY},
        method: 'GET' } , function(err, response, body) {
          if(err) {
            console.log(err);
            return res.status(500).json({msg: 'internal server error'});
          }
          var results = [];
          var array = JSON.parse(body);
          array.items.forEach(function(data) {
            var video = {};
            video.id = data.id.videoId;
            video.title = data.snippet.title;
            video.thumb = data.snippet.thumbnails.high.url;
            results.push(video);
          });
          res.json({videos: results});
        });
      });
};

{'fraction_non_alphanumeric': 0.15978791974217693, 'fraction_numerical': 0.008108951034411062, 'mean_word_length': 1.7493569591311804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, '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': '6170582', 'n_tokens_mistral': 2902, 'n_tokens_neox': 2821, 'n_words': 521}