Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

I haven't changed my code at all, and it worked perfectly, but recently it has started throwing an error. Does anyone know what could cause this? [closed]

$
0
0

I am currently testing the functionality of the discord-youtube-api, and the code below worked perfectly, downloading and storing the YouTube video into an mp4, but no changes were made to the code and it somehow started returning an error. I have tried debugging the issue, but it isn't making any sense how this could be happening if no changes were made to any of the code.Code:

const ytdl = require('ytdl-core');const Youtube = require('discord-youtube-api');const YouTube = new Youtube('XXXXXXXXXXXXXXXXXXXXXXX'); //ACTUAL TOKEN NOT SHOWNasync function download(videoDetails){    return ytdl(videoDetails.url);}var videoDetails = {};console.log("Starting...");YouTube.searchVideos("ink in motion").then(results => { // Search for a video    videoDetails = results; console.log(videoDetails) // Get the video details    console.log("ID of the video: " + videoDetails.id); // Print the video title    download(videoDetails).then(promise => {        //pipe the video to an output file        promise.pipe(fs.createWriteStream('output.mp4'));    });

Error:

Error: Couldn't retrieve video    at YouTube.searchVideos (/Users/sam/Desktop/Testing/node_modules/discord-youtube-api/src/YouTube.js:37:10)    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The error is thrown in the function below:

    async searchVideos(query) {        const max = 1;        const part = "snippet";        const type = "video";        try {            const res = await snekfetch.get(`${this.base}/search?part=${part}&key=${this.key}&maxResults=${max}&type=${type}&q=${query}`);            return await this.getVideoByID(JSON.parse(res.text).items[0].id.videoId);        } catch (err) {            throw new Error("Couldn't retrieve video");        }    }

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>