Skip to main content
se añadieron 2443 caracteres en el cuerpo
Origen Enlace

EDIT: Así queda el archivo "search.json" si se coloca "mercury" por ejemplo:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/BuzsAU-m_62qbjZxWe6680bPe38\"",
 "nextPageToken": "CAUQAA",
 "regionCode": "CO",
 "pageInfo": {
  "totalResults": 1000000,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/vX41eMGILhhOwRj1Lg_UWz-OuBY\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "31j4DIpgY9U"
   },
   "snippet": {
    "publishedAt": "2017-09-08T09:50:10.000Z",
    "channelId": "UCkQ62tvPlVVb2WLppjRfPdQ",
    "title": "GHOSTEMANE - Mercury",
    "description": "CHECK OUT OUR STORE https://trash.clothing TRASH Official Spotify Playlist: ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/31j4DIpgY9U/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/31j4DIpgY9U/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/31j4DIpgY9U/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "TRASH 新 ドラゴン",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/5Wnqe81_9i8hfOrQRztIQTyXCcA\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "V2t0FU1XeDE"
   },
   "snippet": {
    "publishedAt": "2017-10-30T12:00:01.000Z",
    "channelId": "UCnWT-K6shcsSkfJGkpYZC1w",
    "title": "GHOSTEMANE - Mercury [Lyrics / Lyric Video]",
    "description": "You are listening to: GHOSTEMANE - Mercury   Support the Artist(s) below: GHOSTEMANE   ○https://soundcloud.com/ghostemane ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/V2t0FU1XeDE/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/V2t0FU1XeDE/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/V2t0FU1XeDE/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "RapLayer",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

Estoy intentando sacar el "videoId" para colocar el enlace tipo https://www.youtube.com/watch?v=${videoId}

EDIT: Así queda el archivo "search.json" si se coloca "mercury" por ejemplo:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/BuzsAU-m_62qbjZxWe6680bPe38\"",
 "nextPageToken": "CAUQAA",
 "regionCode": "CO",
 "pageInfo": {
  "totalResults": 1000000,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/vX41eMGILhhOwRj1Lg_UWz-OuBY\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "31j4DIpgY9U"
   },
   "snippet": {
    "publishedAt": "2017-09-08T09:50:10.000Z",
    "channelId": "UCkQ62tvPlVVb2WLppjRfPdQ",
    "title": "GHOSTEMANE - Mercury",
    "description": "CHECK OUT OUR STORE https://trash.clothing TRASH Official Spotify Playlist: ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/31j4DIpgY9U/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/31j4DIpgY9U/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/31j4DIpgY9U/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "TRASH 新 ドラゴン",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/5Wnqe81_9i8hfOrQRztIQTyXCcA\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "V2t0FU1XeDE"
   },
   "snippet": {
    "publishedAt": "2017-10-30T12:00:01.000Z",
    "channelId": "UCnWT-K6shcsSkfJGkpYZC1w",
    "title": "GHOSTEMANE - Mercury [Lyrics / Lyric Video]",
    "description": "You are listening to: GHOSTEMANE - Mercury   Support the Artist(s) below: GHOSTEMANE   ○https://soundcloud.com/ghostemane ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/V2t0FU1XeDE/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/V2t0FU1XeDE/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/V2t0FU1XeDE/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "RapLayer",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

Estoy intentando sacar el "videoId" para colocar el enlace tipo https://www.youtube.com/watch?v=${videoId}

Origen Enlace

Unexpected end of JSON input - Discord.js

estoy haciendo un bot de Discord con Discord.js, el punto es que estoy haciendo un comando que reproduzca una canción de YouTube colocando el nombre de la canción y reproduzca el primer resultado. El problema es que al intentar sacar la ID del vídeo del archivo "search.json" me devuelve el siguiente error:

UnhandledPromiseRejectionWarning: SyntaxError: F:\Bot\json\search.json: Unexpected end of JSON input

Aquí hay una parte del código. Agradecería demasiado si lograran ayudarme. (;

var videoSearch = args.slice(0).join(' ');
         youtube.search.list({
            part: 'snippet',
            q: videoSearch
            }, function (err, data) {
              if (err) {
                 console.error('Error: ' + err);
              }
              if (data) {
                 console.log(data.config.url);
                 var jsonSearch = fs.createWriteStream('./json/search.json', "utf-8");
                 var request = https.get(data.config.url, function(response) {
                    response.pipe(jsonSearch);
                 });
                 let vidId = require('../../json/search.json');
                 console.log(`\n${vidId.items[0].id.videoId}\n`);