如何将允许的服务列表传递给 youtube-dl?

我希望 youtube-dl 只能从允许的服务列表中下载内容。像 ['youtube','twitch']。

还有什么方法可以设置自定义错误消息?


撒科打诨
浏览 73回答 1
1回答

慕雪6442864

您可以对 进行 monkeypatch youtube_dl.extractor._ALL_CLASSES,因此 youtube_dl 不会知道您指定的任何其他提取器。import youtube_dldef get_list_of_extractors(extractor_modules):    extractors = []    for module in extractor_modules:        list_of_extractors = [            getattr(module, name) for name in dir(module)             if name.endswith('IE') and name != 'GenericIE' and name.find("Base") == -1        ]        extractors = extractors + list_of_extractors    return extractorslist_of_extractors = get_list_of_extractors([youtube_dl.extractor.youtube, youtube_dl.extractor.tiktok])youtube_dl.extractor._ALL_CLASSES = list_of_extractorsydl = youtube_dl.YoutubeDL({})ydl.extract_info(    'https://www.youtube.com/watch?v=BaW_jenozKc',    download=False # We do not need to download)# causes youtube_dl.utils.DownloadError, because instagram extractor is not in the listydl.extract_info(    'https://instagram.com/p/aye83DjauH',    download=False # We do not need to download)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python