ybd-project / ytdl-core

Fast and secure YouTube downloader for JavaScript and TypeScript
MIT License
28 stars 5 forks source link

Proxies and Mp3 #17

Closed VenomSA closed 2 months ago

VenomSA commented 2 months ago

I need an example on how to use proxies on this updated package.

const ytdl = new YtdlCore({
    agent: ytdl.createProxyAgent({ uri: 'my.proxy.server' }),
});

This throws 'Can't access ytdl before initialisation' which is correct.

Also, would be nice to know how to turn videos to mp3, distube repo had the audioonly filter but for this package I couldn't find anything similar, so any help would be appreciated!

And sorry if I created an issue with the purpose of asking questions.

ybd-project commented 2 months ago

Change ytdl to the YtdlCore class. It can be used as a static method.

ybd-project commented 2 months ago

Is the problem resolved? If you continue to receive no reply, I will close this issue as resolved.

VenomSA commented 2 months ago

Ok I managed to do this and its working, and how to apply the audioonly filter for mp3 download now?

            const ytdl = new YtdlCore({
                agent: YtdlCore.createProxyAgent({ uri: getRandomProxyAgent() }),
            });

Before I had something like this

        const audioStream = ytdl(videoURL, { filter: "audioonly" });

        const chunks = [];

        audioStream.on("data", (chunk) => {
            chunks.push(chunk);
        });

        audioStream.on("end", () => {
            const buffer = Buffer.concat(chunks);
            resolve({ base64: buffer.toString("base64"), title: videoTitle });
        });

        audioStream.on("error", (err) => {
            reject(err);
        });```

Thanks!

ybd-project commented 2 months ago

https://github.com/ybd-project/ytdl-core/tree/main/examples/Download Please refer to this.

VenomSA commented 2 months ago

Thank you! You can close it.

ybd-project commented 2 months ago

The issue has been resolved and the issue is closed.