fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.48k stars 790 forks source link

500 Internal Server Error When Streaming Audio from YouTube URL #1304

Open fsholehan opened 1 month ago

fsholehan commented 1 month ago

I have an endpoint that streams audio from a YouTube URL using ytdl-core. It works fine locally, but I encounter a 500 Internal Server Error on the server. Here's my code:

const express = require('express');
const ytdl = require('ytdl-core');

const app = express();

app.get('/audio', (req, res) => {
    const videoUrl = req.query.url;

    if (!videoUrl) {
        return res.status(400).send('Video URL is required');
    }

    res.header('Content-Type', 'audio/mpeg');

    ytdl(videoUrl, { filter: 'audioonly' })
        .on('error', (err) => {
            console.error('Error:', err);
            res.status(500).send('Error streaming audio');
        })
        .pipe(res);
});

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

Could someone help identify potential causes and solutions for this issue?

Dmytro-Tihunov commented 1 month ago

everyone almost have the same, it happened because youtube ask for captcha #1295