亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將允許的服務列表傳遞給 youtube-dl?

如何將允許的服務列表傳遞給 youtube-dl?

撒科打諢 2022-12-27 17:18:12
我希望 youtube-dl 只能從允許的服務列表中下載內容。像 ['youtube','twitch']。還有什么方法可以設置自定義錯誤消息?
查看完整描述

1 回答

?
慕雪6442864

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

)


查看完整回答
反對 回復 2022-12-27
  • 1 回答
  • 0 關注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號