How to use the youtube-dl.youtube_dl.compat.compat_urlparse.urlparse function in youtube_dl

To help you get started, we’ve selected a few youtube_dl 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 joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / extractor / tvplay.py View on Github external
})
                formats.append(fmt)

        if not formats and video.get('is_geo_blocked'):
            self.raise_geo_restricted(
                'This content might not be available in your country due to copyright reasons')

        self._sort_formats(formats)

        # TODO: webvtt in m3u8
        subtitles = {}
        sami_path = video.get('sami_path')
        if sami_path:
            lang = self._search_regex(
                r'_([a-z]{2})\.xml', sami_path, 'lang',
                default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1])
            subtitles[lang] = [{
                'url': sami_path,
            }]

        series = video.get('format_title')
        episode_number = int_or_none(video.get('format_position', {}).get('episode'))
        season = video.get('_embedded', {}).get('season', {}).get('title')
        season_number = int_or_none(video.get('format_position', {}).get('season'))

        return {
            'id': video_id,
            'title': title,
            'description': video.get('description'),
            'series': series,
            'episode_number': episode_number,
            'season': season,
github joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / extractor / francetv.py View on Github external
def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_id = mobj.group('id')
        catalog = mobj.group('catalog')

        if not video_id:
            qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
            video_id = qs.get('idDiffusion', [None])[0]
            catalog = qs.get('catalogue', [None])[0]
            if not video_id:
                raise ExtractorError('Invalid URL', expected=True)

        return self._extract_video(video_id, catalog)
github joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / extractor / yahoo.py View on Github external
smuggle_url(bc_url, {'geo_countries': [mobj.group('country')]}),
                BrightcoveNewIE.ie_key())

        # Look for Brightcove New Studio embeds
        bc_url = BrightcoveNewIE._extract_url(self, webpage)
        if bc_url:
            return brightcove_url_result(bc_url)

        brightcove_iframe = self._search_regex(
            r'(]+data-video-id=["\']\d+[^>]+>)', webpage,
            'brightcove iframe', default=None)
        if brightcove_iframe:
            attr = extract_attributes(brightcove_iframe)
            src = attr.get('src')
            if src:
                parsed_src = compat_urlparse.urlparse(src)
                qs = compat_urlparse.parse_qs(parsed_src.query)
                account_id = qs.get('accountId', ['2376984109001'])[0]
                brightcove_id = attr.get('data-video-id') or qs.get('videoId', [None])[0]
                if account_id and brightcove_id:
                    return brightcove_url_result(
                        'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
                        % (account_id, brightcove_id))

        # Query result is often embedded in webpage as JSON. Sometimes explicit requests
        # to video API results in a failure with geo restriction reason therefore using
        # embedded query result when present sounds reasonable.
        config_json = self._search_regex(
            r'window\.Af\.bootstrap\[[^\]]+\]\s*=\s*({.*?"applet_type"\s*:\s*"td-applet-videoplayer".*?});(?:|$)',
            webpage, 'videoplayer applet', default=None)
        if config_json:
            config = self._parse_json(config_json, display_id, fatal=False)
github joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / utils.py View on Github external
def proxy_open(self, req, proxy, type):
        req_proxy = req.headers.get('Ytdl-request-proxy')
        if req_proxy is not None:
            proxy = req_proxy
            del req.headers['Ytdl-request-proxy']

        if proxy == '__noproxy__':
            return None  # No Proxy
        if compat_urlparse.urlparse(proxy).scheme.lower() in ('socks', 'socks4', 'socks4a', 'socks5'):
            req.add_header('Ytdl-socks-proxy', proxy)
            # youtube-dl's http/https handlers do wrapping the socket with socks
            return None
        return compat_urllib_request.ProxyHandler.proxy_open(
            self, req, proxy, type)
github joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / utils.py View on Github external
def make_socks_conn_class(base_class, socks_proxy):
    assert issubclass(base_class, (
        compat_http_client.HTTPConnection, compat_http_client.HTTPSConnection))

    url_components = compat_urlparse.urlparse(socks_proxy)
    if url_components.scheme.lower() == 'socks5':
        socks_type = ProxyType.SOCKS5
    elif url_components.scheme.lower() in ('socks', 'socks4'):
        socks_type = ProxyType.SOCKS4
    elif url_components.scheme.lower() == 'socks4a':
        socks_type = ProxyType.SOCKS4A

    def unquote_if_non_empty(s):
        if not s:
            return s
        return compat_urllib_parse_unquote_plus(s)

    proxy_args = (
        socks_type,
        url_components.hostname, url_components.port or 1080,
        True,  # Remote DNS
github joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / extractor / kaltura.py View on Github external
try:
                    _, info, flavor_assets, captions = self._get_video_info(
                        entry_id, partner_id)
                except ExtractorError:
                    # Regular scenario failed but we already have everything
                    # extracted apart from captions and can process at least
                    # with this
                    pass
            else:
                raise ExtractorError('Invalid URL', expected=True)
            ks = params.get('flashvars[ks]', [None])[0]

        source_url = smuggled_data.get('source_url')
        if source_url:
            referrer = base64.b64encode(
                '://'.join(compat_urlparse.urlparse(source_url)[:2])
                .encode('utf-8')).decode('utf-8')
        else:
            referrer = None

        def sign_url(unsigned_url):
            if ks:
                unsigned_url += '/ks/%s' % ks
            if referrer:
                unsigned_url += '?referrer=%s' % referrer
            return unsigned_url

        data_url = info['dataUrl']
        if '/flvclipper/' in data_url:
            data_url = re.sub(r'/flvclipper/.*', '/serveFlavor', data_url)

        formats = []
github joegesualdo / get-youtube-subtitle-url-node / youtube-dl / youtube_dl / utils.py View on Github external
def update_url_query(url, query):
    if not query:
        return url
    parsed_url = compat_urlparse.urlparse(url)
    qs = compat_parse_qs(parsed_url.query)
    qs.update(query)
    return compat_urlparse.urlunparse(parsed_url._replace(
        query=compat_urllib_parse_urlencode(qs, True)))