{"record":{"id":"58fa5cf429571b2a","repo":"ytdl-org/youtube-dl","slug":"invalid-url-s-58fa5c","errorCode":null,"errorMessage":"Invalid URL: %s","messagePattern":"Invalid URL: (.+?)","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"error","filePath":"youtube_dl/extractor/youtube.py","lineNumber":2254,"sourceCode":"\n        # Wordpress \"YouTube Video Importer\" plugin\n        matches = re.findall(r'''(?x)<div[^>]+\n            class=(?P<q1>[\\'\"])[^\\'\"]*\\byvii_single_video_player\\b[^\\'\"]*(?P=q1)[^>]+\n            data-video_id=(?P<q2>[\\'\"])([^\\'\"]+)(?P=q2)''', webpage)\n        entries.extend(m[-1] for m in matches)\n\n        return entries\n\n    @staticmethod\n    def _extract_url(webpage):\n        urls = YoutubeIE._extract_urls(webpage)\n        return urls[0] if urls else None\n\n    @classmethod\n    def extract_id(cls, url):\n        mobj = re.match(cls._VALID_URL, url, re.VERBOSE)\n        if mobj is None:\n            raise ExtractorError('Invalid URL: %s' % url)\n        return mobj.group(2)\n\n    @staticmethod\n    def _extract_chapters_from_json(data, video_id, duration):\n        chapters_list = try_get(\n            data,\n            lambda x: x['playerOverlays']\n                       ['playerOverlayRenderer']\n                       ['decoratedPlayerBarRenderer']\n                       ['decoratedPlayerBarRenderer']\n                       ['playerBar']\n                       ['chapteredPlayerBarRenderer']\n                       ['chapters'],\n            list)\n        if not chapters_list:\n            return\n\n        def chapter_time(chapter):","sourceCodeStart":2236,"sourceCodeEnd":2272,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/youtube.py#L2236-L2272","documentation":"Raised by the static YoutubeIE.extract_id when the given URL does not match the (verbose) _VALID_URL regex for YouTube video URLs. It is a plain ExtractorError (not expected), signaling the caller passed something that is not a recognizable youtube.com/watch (or equivalent) URL — typically a truncated URL mangled by the shell.","triggerScenarios":"Calling YoutubeIE.extract_id('https://www.youtube.com/watch?feature=foo') — an URL whose query string was cut at '&' by an unquoted shell — or any string that does not contain a capturable 11-char video id group.","commonSituations":"Unquoted URLs in shells where & backgrounds the command and truncates the URL; programmatic callers passing already-stripped or malformed URLs; URLs from other regions/hosts not covered by _VALID_URL in the installed version.","solutions":["Quote the URL: youtube-dl \"https://www.youtube.com/watch?feature=foo&v=BaW_jenozKc\", or pass just the id: youtube-dl BaW_jenozKc.","In code, validate with YoutubeIE.suitable(url) (or re.match(_VALID_URL, url, re.VERBOSE)) before calling extract_id.","Update youtube-dl so newly added YouTube hosts/URL shapes are recognized.","Check for stray whitespace/newlines in programmatically supplied URLs."],"exampleFix":"// before\nvideo_id = YoutubeIE.extract_id('https://www.youtube.com/watch?feature=foo')\n\n// after\nvideo_id = YoutubeIE.extract_id('https://www.youtube.com/watch?feature=foo&v=BaW_jenozKc')  # quoted in shell: \"...&v=BaW_jenozKc\"","handlingStrategy":"validation","validationCode":"import re\n\ndef is_valid_youtube_url(url: str) -> bool:\n    return re.match(YoutubeIE._VALID_URL, url, re.VERBOSE) is not None\n\nassert is_valid_youtube_url(url), 'URL lacks the video id (quote it in shells!)'","typeGuard":"def extract_video_id_safe(url: str):\n    m = re.match(YoutubeIE._VALID_URL, url, re.VERBOSE)\n    return m.group(2) if m else None  # None instead of raising","tryCatchPattern":"try:\n    vid = YoutubeIE.extract_id(url)\nexcept ExtractorError as e:\n    if 'Invalid URL' in str(e):\n        raise ValueError('Not a YouTube video URL: %r — was it truncated at & ?' % url)\n    raise","preventionTips":["Always quote URLs containing & in shells.","Prefer bare 11-character ids as input to scripts and APIs."],"tags":["youtube","url-validation","shell-quoting","regex"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}