ytdl-org/youtube-dl · error · ExtractorError

Invalid URL

Error message

Invalid URL

What it means

Raised by BokeCCIE._real_extract after matching the _VALID_URL: it re-parses the captured query string with compat_parse_qs and requires both 'vid' and 'uid' parameters to be present. If either is missing from the URL's query, it raises 'Invalid URL' (expected=True) before any network request is made. Note the URL must still have matched the extractor's regex, so this fires for URLs shaped right but lacking the required params.

Source

Thrown at youtube_dl/extractor/bokecc.py:50


class BokeCCIE(BokeCCBaseIE):
    IE_DESC = 'CC视频'
    _VALID_URL = r'https?://union\.bokecc\.com/playvideo\.bo\?(?P<query>.*)'

    _TESTS = [{
        'url': 'http://union.bokecc.com/playvideo.bo?vid=E0ABAE9D4F509B189C33DC5901307461&uid=FE644790DE9D154A',
        'info_dict': {
            'id': 'FE644790DE9D154A_E0ABAE9D4F509B189C33DC5901307461',
            'ext': 'flv',
            'title': 'BokeCC Video',
        },
    }]

    def _real_extract(self, url):
        qs = compat_parse_qs(re.match(self._VALID_URL, url).group('query'))
        if not qs.get('vid') or not qs.get('uid'):
            raise ExtractorError('Invalid URL', expected=True)

        video_id = '%s_%s' % (qs['uid'][0], qs['vid'][0])

        webpage = self._download_webpage(url, video_id)

        return {
            'id': video_id,
            'title': 'BokeCC Video',  # no title provided in the webpage
            'formats': self._extract_bokecc_formats(webpage, video_id),
        }

View on GitHub (pinned to 956b8c5855)

Solutions

  1. Fix the URL: ensure both query parameters are present, e.g. http://union.bokecc.com/playvideo.bo?vid=<video>&uid=<user>.
  2. If you control link generation, never emit bokecc links missing either param.
  3. Validate the query string with parse_qs yourself before handing the URL to the extractor.
  4. Check for HTML-entity-encoded ampersands (&amp;) in copied URLs — decode them first.

Example fix

// before - caller passes a URL missing uid
YoutubeDL().extract_info('http://union.bokecc.com/playvideo.bo?vid=E0ABAE9D4F509B189C33DC5901307461')

// after - validate required params first
from urllib.parse import urlparse, parse_qs
u = 'http://union.bokecc.com/playvideo.bo?vid=E0ABAE9D4F509B189C33DC5901307461'
q = parse_qs(urlparse(u).query)
if not (q.get('vid') and q.get('uid')):
    raise SystemExit('bokecc URL must include both vid and uid')
YoutubeDL().extract_info(u)
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse, parse_qs

def bokecc_url_is_valid(url):
    q = parse_qs(urlparse(url).query)
    return bool(q.get('vid')) and bool(q.get('uid'))

Try / catch

try:
    ydl.extract_info(url)
except ExtractorError as e:
    if str(e) == 'Invalid URL':
        raise ValueError('bokecc URL must include both vid and uid query params: %s' % url) from e
    raise

Prevention

When it happens

Trigger: Passing a union.bokecc.com/playvideo.bo URL whose query string omits vid or uid, e.g. '?vid=...' alone, an empty '?', or params misspelled ('videoId' instead of 'vid'). The regex group 'query' captures whatever follows so parse_qs yields a dict without the required keys.

Common situations: Hand-copied URLs truncated at '?' or '&'; embedding templates that drop empty parameters; upstream pages generating bokecc links with only one param after API changes; URL-encoded ampersands splitting into a single malformed param.

Related errors


AI-assisted analysis of ytdl-org/youtube-dl@956b8c5855 (2026-08-14). Data as JSON: /api/errors/ea1daeacedf1ffad. Report an issue: GitHub.