How to use the ykdl.util.html.get_location function in ykdl

To help you get started, we’ve selected a few ykdl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ForgQi / bilibiliupload / ykdl / extractors / weibo.py View on Github external
def l_assert(self):
        if self.url.startswith('http://'):
            self.url = self.url.replace('http://', 'https://', 1)
        self.url = get_location(self.url)

        if 'passport.weibo.com' in self.url:
            query = urlsplit(self.url).query
            self.url = parse_qs(query)['url'][0]
            return self.l_assert()

        # Mobile ver.
        if 'm.weibo.cn' in self.url:
            self.title_patterns = '"content2": "(.+?)",', '"status_title": "(.+?)",'
            self.url_patterns = '"stream_url_hd": "([^"]+)', '"stream_url": "([^"]+)'
            return

        if '/tv/v/' in self.url or 'fid=' not in self.url:
            self.title_patterns = 'class="info_txt \w+">([^<]+)]+>\s*(?:)?\s*([^<]+)'
            self.url_patterns = 'video-sources\s*=\s*".+?(?:&\d+=http.+?)*&\d+=(http.+?[^=])(?:&\d+=)*&qType=\w+"',
            return
github ForgQi / bilibiliupload / ykdl / common.py View on Github external
else:
        short_name = host_list[-2]
    logger.debug('video_host> ' + video_host)
    logger.debug('short_name> ' + short_name)
    if short_name in alias.keys():
        short_name = alias[short_name]
    try:
        m = import_module('.'.join(['ykdl','extractors', short_name]))
        if hasattr(m, "get_extractor"):
            site, url = m.get_extractor(url)
        else:
            site = m.site
        return site, url
    except(ImportError):
        logger.debug('> Try HTTP Redirection!')
        new_url = get_location(url, headers = {})
        if new_url == url:
            logger.debug('> NO HTTP Redirection')
            logger.debug('> Go Generalembed')
            return import_module('ykdl.extractors.generalembed').site, url
        else:
            logger.debug('> new url ' + new_url)
            return url_to_module(new_url)
github ForgQi / bilibiliupload / ykdl / extractors / bilibili / __init__.py View on Github external
return s.site, url
    elif 'vc.bilibili' in url:
        from . import vc as s
        return s.site, url
    elif '/bangumi/' in url:
        from . import bangumi as s
        return s.site, url

    av_id = match1(url, '(?:/av|aid=)(\d+)')
    page_index = match1(url, '(?:page|\?p)=(\d+)', 'index_(\d+)\.') or '1'
    if page_index == '1':
        url = 'https://www.bilibili.com/av{}/'.format(av_id)
    else:
        url = 'https://www.bilibili.com/av{}/?p={}'.format(av_id, page_index)
    add_header('Referer', 'https://www.bilibili.com/')
    url = get_location(url)

    if '/bangumi/' in url:
        from . import bangumi as s
    else:
        from . import video as s

    return s.site, url