How to use the ykdl.compact.build_opener 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 coslyk / moonplayer / src / plugins / ykdl_patched.py View on Github external
proxy_handler = ProxyHandler({
            'http': args.http_proxy,
            'https': args.http_proxy
        })
        handlers.append(proxy_handler)

    elif args.socks_proxy:
        try:
            import socks
            addr, port = args.socks_proxy.split(':')
            socks.set_default_proxy(socks.SOCKS5, addr, int(port))
            socket.socket = socks.socksocket
        except:
            print('Failed to set socks5 proxy. Please install PySocks.', file=sys.stderr)

    opener = build_opener(*handlers)
    install_opener(opener)

    m, u = url_to_module(args.video_url)
    info = m.parser(u)

    # Is a playlist?
    if m.list_only():
        video_list = m.prepare_list()
        result = [ {'title': match1(get_content(url), r'<title>(.+?)</title>'), 'url': url} for url in video_list ]
    else:
        result = info.jsonlize()
    print(json.dumps(result, indent=4, sort_keys=True, ensure_ascii=False))
github ForgQi / bilibiliupload / ykdl / util / html.py View on Github external
def install_default_handlers():
    install_opener(build_opener(*default_handlers))