def _has_suitable_extractor(url): """ Tests wheater youtube-dl has a suitable extractor for the given url. If so, returns true, otherwise false. The "generic" extractor is ingored. """ for extractor in youtube_dl.list_extractors(18): if extractor.suitable(url): # Skip the generic downloader if(extractor.IE_NAME == 'generic'): continue return True return False
def main(): with open('supportedsites.html.in', 'r', encoding='utf-8') as tmplf: template = tmplf.read() ie_htmls = [] for ie in youtube_dl.list_extractors(age_limit=None): ie_html = '<b>{}</b>'.format(ie.IE_NAME) ie_desc = getattr(ie, 'IE_DESC', None) if ie_desc is False: continue elif ie_desc is not None: ie_html += ': {}'.format(ie.IE_DESC) if not ie.working(): ie_html += ' (Currently broken)' ie_htmls.append('<li>{}</li>'.format(ie_html)) template = template.replace('@SITES@', textwrap.indent('\n'.join(ie_htmls), '\t')) with open('supportedsites.html', 'w', encoding='utf-8') as sitesf: sitesf.write(template)
#!/usr/bin/env python3 import youtube_dl import tornado.ioloop import tornado.web import urllib.error import math import re ydl = youtube_dl.YoutubeDL({}) all_extractors = youtube_dl.list_extractors(math.inf) supported = [] supported_re = [r"https?://(?:www\.)?cbsnews\.com"] bad_extractors = ["generic"] for extractor in all_extractors: if extractor.IE_NAME in bad_extractors: continue if not isinstance(extractor, youtube_dl.extractor.common.SearchInfoExtractor): supported.append(extractor.IE_NAME) supported_re.append(extractor._VALID_URL) def any_extractor(url): for extractor_re in supported_re: if re.search(extractor_re, url): return True return False