首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何向youtube-dl /yt隐藏错误信息?

如何向youtube-dl /yt隐藏错误信息?
EN

Stack Overflow用户
提问于 2022-03-02 16:31:55
回答 1查看 1.5K关注 0票数 1

我正在使用yt(在Python中)从to视频中提取信息。

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

代码语言:javascript
运行
复制
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")

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

代码语言:javascript
运行
复制
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检查视频是否是可访问的,这样如果视频不是,我就不会调用extract_info?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-02 18:12:22

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

代码语言:javascript
运行
复制
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禁用日志记录

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71326109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档