1 回答
TA贡献1812条经验 获得超5个赞
您可以对 进行 monkeypatch youtube_dl.extractor._ALL_CLASSES,因此 youtube_dl 不会知道您指定的任何其他提取器。
import youtube_dl
def 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 extractors
list_of_extractors = get_list_of_extractors([youtube_dl.extractor.youtube, youtube_dl.extractor.tiktok])
youtube_dl.extractor._ALL_CLASSES = list_of_extractors
ydl = 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 list
ydl.extract_info(
'https://instagram.com/p/aye83DjauH',
download=False # We do not need to download
)
添加回答
举报