distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
289 stars 50 forks source link

YouTube videos downloaded only 0 bytes #115

Closed arcovoltaico closed 1 month ago

arcovoltaico commented 1 month ago

Describe the bug

My code has been working for months, but since recently, no YouTube video has been downloaded, and I am not even getting any error. I see that the file is created but remains 0 bytes. This has started happening recently in my 2 well-tested different systems, without changing any code, no matter what video you try.

I have tried this fix https://github.com/XM4ZE/ytdl-core , but it's not helping.

My code runs in the main.js Electron.

ytdl.getInfo(url).then((info: videoInfo) => { const formats = ytdl.filterFormats(info.formats, 'audioandvideo'); if (formats.length < 1) { notifyYoutubeDownloadError(id); }

    console.log("FORMATS: " + formats.length);
    const downloadOptions = {
        quality: 'highest', format: formats[0]
    };

    ytdl.downloadFromInfo(info, downloadOptions).pipe(file);
}).catch((error) => {
    notifyYoutubeDownloadError(id);
});

I have tried also the suggested code with the same result : const ytdl = require('@distube/ytdl-core');

  // Download a video
  ytdl('http://www.youtube.com/watch?v=aqz-KE-bpKQ').pipe(
    require('fs').createWriteStream('§.mp4'),
  );

Environment

arcovoltaico commented 1 month ago

solved by using "github:XM4ZE/ytdl-core" }

AmitDJagtap commented 1 month ago

yep same issue .

The error seems to start in video.getInfo function. when ytdl tries to access relatedVideoData etc

LucaFontanot commented 1 month ago

Same issue. But on windows is working fine, with same IP and everything

XM4ZE commented 1 month ago

Try using this. Video in buffer results

let ytdl = require("ytdl-core")
let fs = require("fs")

async function ytdlcore(url) {
    try {
        const agent = ytdl.createAgent(JSON.parse(fs.readFileSync("cookies.json")));
        const {
            videoDetails
        } = await ytdl.getInfo(url, {
            lang: "id",
            agent
        });
        const stream = ytdl(url, {
            filter: 'videoandaudio',
            agent
        });
        const chunks = [];
        stream.on("data", (chunk) => {
            chunks.push(chunk);
        });
        await new Promise((resolve, reject) => {
            stream.on("end", resolve);
            stream.on("error", reject);
        });
        const buffer = Buffer.concat(chunks);
        return {
            meta: {
                title: videoDetails.title,
                channel: videoDetails.author.name,
                seconds: videoDetails.lengthSeconds,
                description: videoDetails.description,
                image: videoDetails.thumbnails.slice(-1)[0].url,
                resolusi: videoDetails.embed,
            },
            buffer: buffer,
            size: buffer.length,
        };
    } catch (error) {
        throw error;
    }
}

return await ytdlcore("https://youtu.be/pvlDjh_UgvA")
ghost commented 1 month ago

Is the cookie designation still valid? In my case, it works locally, but when deployed to a server, it is no longer available, so I created my own fork to support various methods other than cookies. https://github.com/ybd-project-ver1/ytdl-core