{"record":{"id":"8fac498d662f3519","repo":"ytdl-org/youtube-dl","slug":"invalid-url-r-call-youtube-dl-like-this-you","errorCode":null,"errorMessage":"Invalid URL:  %r . Call youtube-dl like this:  youtube-dl -v \"https://www.youtube.com/watch?v=BaW_jenozKc\"  ","messagePattern":"Invalid URL:  %r \\. Call youtube-dl like this:  youtube-dl -v \"https://www\\.youtube\\.com/watch\\?v=BaW_jenozKc\"  ","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"warning","filePath":"youtube_dl/extractor/generic.py","lineNumber":2546,"sourceCode":"\n    def _real_extract(self, url):\n        if url.startswith('//'):\n            return self.url_result(self.http_scheme() + url)\n\n        parsed_url = compat_urlparse.urlparse(url)\n        if not parsed_url.scheme:\n            default_search = self._downloader.params.get('default_search')\n            if default_search is None:\n                default_search = 'fixup_error'\n\n            if default_search in ('auto', 'auto_warning', 'fixup_error'):\n                if re.match(r'^[^\\s/]+\\.[^\\s/]+/', url):\n                    self._downloader.report_warning('The url doesn\\'t specify the protocol, trying with http')\n                    return self.url_result('http://' + url)\n                elif default_search != 'fixup_error':\n                    if default_search == 'auto_warning':\n                        if re.match(r'^(?:url|URL)$', url):\n                            raise ExtractorError(\n                                'Invalid URL:  %r . Call youtube-dl like this:  youtube-dl -v \"https://www.youtube.com/watch?v=BaW_jenozKc\"  ' % url,\n                                expected=True)\n                        else:\n                            self._downloader.report_warning(\n                                'Falling back to youtube search for  %s . Set --default-search \"auto\" to suppress this warning.' % url)\n                    return self.url_result('ytsearch:' + url)\n\n            if default_search in ('error', 'fixup_error'):\n                raise ExtractorError(\n                    '%r is not a valid URL. '\n                    'Set --default-search \"ytsearch\" (or run  youtube-dl \"ytsearch:%s\" ) to search YouTube'\n                    % (url, url), expected=True)\n            else:\n                if ':' not in default_search:\n                    default_search += ':'\n                return self.url_result(default_search + url)\n\n        url, smuggled_data = unsmuggle_url(url)","sourceCodeStart":2528,"sourceCodeEnd":2564,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/generic.py#L2528-L2564","documentation":"Raised by the generic extractor when the URL has no scheme, default_search is 'auto_warning', and the input is literally 'url' or 'URL'. youtube-dl interprets a bare 'url' as a likely mistyped placeholder and refuses to fall back to a YouTube search for it. Marked expected=True.","triggerScenarios":"Invoking the CLI with the literal argument url or URL (e.g. youtube-dl $(cat cmd.txt) where the file contained the word 'url') while --default-search is auto_warning, and the input matches neither the domain regex ^[^\\s/]+\\.[^\\s/]+/ nor a scheme.","commonSituations":"Shell scripts templating a URL variable that expanded to the placeholder 'url', copy-paste of an example command without substitution, or CI configs passing an unset variable defaulting to 'url'.","solutions":["Pass a real URL including the scheme: youtube-dl \"https://www.youtube.com/watch?v=BaW_jenozKc\"","Fix the script/variable that substituted the literal string 'url'","Set --default-search explicitly if you really want search behavior"],"exampleFix":"# before\nyoutube-dl url\n# after\nyoutube-dl \"https://www.youtube.com/watch?v=BaW_jenozKc\"","handlingStrategy":"validation","validationCode":"import re\ndef valid_cli_url(u):\n    return bool(re.match(r'^[a-zA-Z][a-zA-Z0-9+.-]*://', u)) or bool(re.match(r'^[^\\s/]+\\.[^\\s/]+/', u))\nif not valid_cli_url(arg) or arg.lower() in ('url',):\n    raise SystemExit(f'not a real URL: {arg!r}')","typeGuard":"def is_placeholder_url(u):\n    return u.strip().lower() in ('url', 'http://url', 'https://url')","tryCatchPattern":"try:\n    ydl.download([arg])\nexcept DownloadError:\n    # expected=True error; correct the argument, no need to log as a bug\n    print('pass a full URL, not the literal placeholder \"url\"')","preventionTips":["Quote URLs in shell commands","Fail fast in scripts on unset URL variables: : \"${URL:?URL not set}\"","Never template example commands without replacing placeholders"],"tags":["generic","cli-usage","url-validation"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}