有没有办法阻止 youtube_dl 将其状态打印到控制台?

Is there a way to keep youtube_dl from printing its status to the console?

当我在 Python 脚本中使用 youtube_dl 库下载视频时,它会在控制台中打印以下内容:

[youtube] [video]: Downloading webpage
[youtube] Downloading just video [video] because of --no-playlist
[download] Destination: [destination]
[download] 100% of 3.00MiB in 00:00
[ffmpeg] Post-process file [destination] exists, skipping

有没有办法阻止它这样做?

youtube_dl 似乎没有使用标准的 Python logging 库,所以我不能这样做:

youtube_logger = logging.getLogger('youtube_dl')
youtube_logger.setLevel(logging.WARNING)

有什么方法可以阻止 youtube_dl 打印到控制台吗?

您可以使用静音选项:

ydl_opts = {
    'quiet': True
}


youtube_dl_manager = youtube_dl.YoutubeDL(ydl_opts)

原来有一个名为 Quiet Mode 的选项可以做到这一点!运作方式如下:

ydl_opts = {
    'quiet': True
}

youtube_dl_manager = youtube_dl.YoutubeDL(ydl_opts)

然后您就可以正常使用 YoutubeDL 对象,而无需将其打印到控制台!