"use strict";

const express = require("express");
const app = express();

// install request
const request = require('request');

const PORT = process.env.PORT || 3000;
const rovi = process.env.ROVI_APIKEY || '';


// CORS (Cross-Origin Resource Sharing) headers to support Cross-site HTTP requests
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});


// Request artist information from Rovi API
app.get('/api/:artist/:sig', (req, res) => {
  const artist = req.params.artist;
  const sig = req.params.sig;

  const url = "http://api.rovicorp.com/search/v2.1/music/search?apikey=" + rovi + "&sig=" + sig + "&query=" + artist + "&entitytype=artist&size=1&include=images,musicbio,discography,videos&formatid=62&type=main";

  console.log(url);

  request.get(url, (err, response, body) => {
    if (err) throw err;

    // res.header('Access-Control-Allow-Origin', '*');
    res.send(JSON.parse(body));
  });
});


// Request artist's video information from Rovi API
app.get('/videos/:id/:appid/:idtype', (req, res) => {
  const id = req.params.id;
  const appid = req.params.appid;
  const idtype = req.params.idtype;

  const url = "https://ee.internetvideoarchive.net/api/expressstandard/" + id + "?appid=" + appid + "&idtype=" + idtype

  // const url = "http://api.rovicorp.com/data/v1.1/name/videos?format=json&apikey=" + rovi + "&sig=" + sig + "&nameid=" + nameId;

  console.log(url);

  request.get(url, (err, response, body) => {
    if (err) throw err;

    res.send(JSON.parse(body));
  });
});


app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

@@ -207,16 +207,64 @@
  %7C%7C '';%0A
+const echo = process.env.ECHONEST_APIKEY %7C%7C '';%0A
 %0A%0A// COR
@@ -1154,25 +1154,14 @@
 os/:
-id/:appid/:idtype
+artist
 ', (
@@ -1187,96 +1187,34 @@
 nst 
-id = req.params.id;%0A  const appid = req.params.appid;%0A  const idtype = req.params.idtype
+artist = req.params.artist
 ;%0A%0A 
@@ -1223,24 +1223,25 @@
 onst url
+1
  = %22http
 s://ee.i
@@ -1236,331 +1236,402 @@
 http
-s
 ://
-ee.internetvideoarchive.net/api/expressstandard/%22 + id + %22?appid=%22 + appid + %22&idtype=%22 + idtype%0A%0A  // const url = %22http://api.rovicorp.com/data/v1.1/name/videos?format=json&apikey=%22 + rovi + %22&sig=%22 + sig + %22&nameid=%22 + nameId;%0A%0A  console.log(url);%0A%0A  request.get(url, (err, response, body) =%3E %7B%0A    if (err) throw err
+developer.echonest.com/api/v4/artist/search?api_key=%22 + echo + %22&format=json&name=%22 + artist + %22&results=1%22;%0A%0A  console.log(url);%0A%0A  request.get(url, (err, response, body) =%3E %7B%0A    if (err) throw err;%0A%0A    console.log(body);%0A%0A    const url2 = %22http://developer.echonest.com/api/v4/artist/video?api_key=%22 + echo + %22&id=ARH6W4X1187B99274F&format=json&results=3&start=0%22;%0A%0A    console.log(url2)
 ;%0A%0A 

Change video request URL