yt-dlp 下载 YouTube 视频时出现“需要登录”

问题描述 投票:0回答:1

我尝试使用 yt-dlp 从 YouTube Shorts 视频下载音频,但我不断遇到错误,提示“登录以确认您不是机器人”。我想知道如何解决这个问题,以便我可以成功下载音频。

使用的命令 这是我在终端中执行的命令:

yt-dlp --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.3" -f bestaudio -o "output.mp3" "https://youtube.com/shorts/V7YCOMkQtMI?si=otM-DOvIV7ZZas4N"


ERROR: [youtube] V7YCOMkQtMI: Sign in to confirm you’re not a bot. This helps protect our community.

const downloadAudio = async (url, outputFilePath) => {
    console.log('Attempting to download audio from URL:', url); // Log the URL

    const ytDlpCommand = [
        'yt-dlp',
        
        '--user-agent',
        '"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.3"',
        '-f', 'bestaudio',
        '-o', outputFilePath,
        '--restrict-filenames',
        '--no-mtime',
        '-v', 
        url 
    ];


    const commandString = ytDlpCommand.join(' ');

    try {
        console.log('Executing command:', commandString); // Log the command being executed
        const { stdout, stderr } = await execPromise(commandString); //

        // Log stdout and stderr for debugging
        console.log('yt-dlp stdout:', stdout);
        if (stderr) {
            console.error('yt-dlp stderr:', stderr); 
            throw new Error(`yt-dlp stderr output indicates a problem: ${stderr}`);
        }

        return stdout; // Return the standard output
    } catch (error) {
     
        console.error('Error in downloadAudio:', error.message);
        console.error('Full command executed:', commandString); 
        throw new Error('Failed to download audio'); 
    }
};

尝试不同的网址:我测试了多个 YouTube 视频,包括常规视频和 Shorts 视频,但错误仍然存在。 更改用户代理:我使用了不同的用户代理字符串,但仍然收到相同的错误。 检查网络和代理设置:我确保我的网络连接稳定并且没有代理干扰请求。 在另一台设备上测试:我尝试在也安装了 yt-dlp 的另一台设备上下载相同的视频,但遇到了相同的错误

ytdl
1个回答
0
投票

在我的个人笔记本电脑上,yt-dlp 开箱即用。在我的 oracle vps 上,您也遇到过相同的登录请求问题。在 YouTube 打击机器人之后,近几个月来,网上似乎有很多关于数据中心 IP 遇到此问题的报告。

有人建议采用浏览器 cookie 作为解决方案,并标记为“绝对不要这样做”,因为它会标记您的帐户……我无法证明这一点。

但是我确实通过使用这个 oauth 插件成功解决了这个问题。鉴于 cookie 解决方案上的警告,建议使用第二个帐户而不是主帐户可能是谨慎的做法。

https://github.com/coletdjnz/yt-dlp-youtube-oauth2

© www.soinside.com 2019 - 2024. All rights reserved.