如何从youtube dl/yt dlp隐藏错误消息



我正在使用yt-dlp(在Python中(从Twitch视频中提取信息。

如果我试图从不存在的视频或私人视频中提取信息,我会得到一个例外,那就是预期行为。但如果我设置为";安静";模式,如果我捕捉到潜在的异常,并且我仍然会记录错误。这是代码:

import yt_dlp as youtube_dl
from yt_dlp.utils import DownloadError

url = "https://www.twitch.tv/videos/1410795876"
options = {
"quiet": True,
"format": "bestaudio/worst",
}
with youtube_dl.YoutubeDL(options) as ydl:
try:
info = ydl.extract_info(url, download=False)
except DownloadError:
print("An exception has been caught")

使用此脚本时,输出如下:

ERROR: [twitch:vod] 1410795876: Failed to download m3u8 information: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on  https://github.com/yt-dlp/yt-dlp , filling out the "Broken site" issue template properly. Confirm you are on the latest version using -U (caused by <HTTPError 403: 'Forbidden'>); please report this issue on  https://github.com/yt-dlp/yt-dlp , filling out the "Broken site" issue template properly. Confirm you are on the latest version using -U
An exception has been caught

有没有办法隐藏这个错误日志?如果没有,是否有一种方法可以使用yt-dlp来检查视频是否可访问,这样如果视频不可访问,我就不会调用extract_info?非常感谢。

我想隐藏所有日志错误的最简单方法是实现自己的日志处理程序。考虑一下对代码的以下更改,我相信你会从这里找到如何实现你想要的:

import yt_dlp as youtube_dl
from yt_dlp.utils import DownloadError

url = "https://www.twitch.tv/videos/1410795876"
class loggerOutputs:
def error(msg):
print("Captured Error: "+msg)
def warning(msg):
print("Captured Warning: "+msg)
def debug(msg):
print("Captured Log: "+msg)

options = {
"quiet": True,
"format": "bestaudio/worst",
"logger": loggerOutputs,
}
with youtube_dl.YoutubeDL(options) as ydl:
try:
info = ydl.extract_info(url, download=False)
except DownloadError:
print("An exception has been caught")

在下面的例子中,它们通过实现";FakeLogger":https://github.com/ytdl-org/youtube-dl/blob/master/test/test_http.py

相关内容

  • 没有找到相关文章

最新更新