{"record":{"id":"71ea1b9be6ba833d","repo":"yt-dlp/yt-dlp","slug":"invalid-facebook-redirect-url","errorCode":null,"errorMessage":"Invalid facebook redirect URL","messagePattern":"Invalid facebook redirect URL","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"error","filePath":"yt_dlp/extractor/facebook.py","lineNumber":954,"sourceCode":"            'tags': 'count:11',\n            'duration': 3332,\n            'live_status': 'not_live',\n            'thumbnail': r're:https?://i\\.ytimg\\.com/vi/.+',\n            'channel_url': 'https://www.youtube.com/channel/UCGBpxWJr9FNOcFYA5GkKrMg',\n            'availability': 'public',\n            'uploader_url': 'http://www.youtube.com/user/brtvofficial',\n            'upload_date': '20150917',\n            'age_limit': 0,\n            'view_count': int,\n            'like_count': int,\n        },\n        'skip': 'Youtube video is now private',\n    }]\n\n    def _real_extract(self, url):\n        redirect_url = url_or_none(parse_qs(url).get('u', [None])[-1])\n        if not redirect_url:\n            raise ExtractorError('Invalid facebook redirect URL', expected=True)\n        return self.url_result(redirect_url)\n\n\nclass FacebookReelIE(InfoExtractor):\n    _VALID_URL = r'https?://(?:[\\w-]+\\.)?facebook\\.com/reel/(?P<id>\\d+)'\n    IE_NAME = 'facebook:reel'\n    _TESTS = [{\n        'url': 'https://www.facebook.com/reel/1195289147628387',\n        'md5': 'aeb0153ecb2eaacdf2dc2bf88f593fef',\n        'info_dict': {\n            'id': '1195289147628387',\n            'ext': 'mp4',\n            'title': '9.7K views · 352 reactions | When your trying to help your partner out with an arrest and #FAAFO games begin. Let the “Slapathon” commence!! 👊👋 | Beast Camp Training',\n            'description': 'md5:5a767dc7e78718667b150a7facc4a34f',\n            'uploader': '9.7K views &#xb7; 352 reactions | When your trying to help your partner out with an arrest and #FAAFO games begin. Let the &#x201c;Slapathon&#x201d; commence!! &#x1f44a;&#x1f44b; | Beast Camp Training',\n            'uploader_id': '100040874179269',\n            'duration': 9.579,\n            'thumbnail': r're:https?://scontent\\.fitm\\d-1\\.fna\\.fbcdn\\.net/.+',","sourceCodeStart":936,"sourceCodeEnd":972,"githubUrl":"https://github.com/yt-dlp/yt-dlp/blob/81ecd58b1394793e6da9998cc19fdb45657f1685/yt_dlp/extractor/facebook.py#L936-L972","documentation":"FacebookRedirectIE handles facebook.com/l.php (and similar) outbound redirect links, taking the target from the 'u' query parameter. If that parameter is missing or empty (url_or_none returns None), the URL cannot be resolved and this expected error is raised. The link is malformed — nothing to redirect to.","triggerScenarios":"Matching a facebook.com/l.php URL whose query string lacks u= (or has it empty), e.g. truncated copy-paste, sanitized referrer-stripped links, or hand-built l.php URLs.","commonSituations":"URLs mangled by chat clients that strip query parameters; scraping pipelines that drop query strings; users hand-editing FB links.","solutions":["Get the full original link including its query string and retry.","Better: open the l.php link once in a browser and copy the final destination URL; pass that directly to yt-dlp.","In scripts, validate that the redirect URL has a non-empty 'u' query param before handing it to yt-dlp."],"exampleFix":"# before\nyt-dlp 'https://www.facebook.com/l.php'\n# ERROR: [facebook:redirect] Invalid facebook redirect URL\n\n# after\nyt-dlp 'https://www.facebook.com/l.php?u=https%3A%2F%2Fexample.com%2Fvideo'","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse, parse_qs\n\ndef resolve_fb_redirect(url: str):\n    q = parse_qs(urlparse(url).query)\n    target = q.get('u', [None])[-1]\n    if not target:\n        raise ValueError(f'{url} is a facebook redirect link without a u= target')\n    return target  # hand THIS to yt-dlp","typeGuard":null,"tryCatchPattern":"from yt_dlp.utils import ExtractorError\n\ntry:\n    info = ydl.extract_info(url, download=True)\nexcept ExtractorError as e:\n    if e.expected and 'Invalid facebook redirect URL' in str(e):\n        notify_user('The facebook.com/l.php link lost its u= parameter; re-copy the full link')\n        raise","preventionTips":["Dereference facebook l.php links (extract u= and URL-decode) before passing them to yt-dlp.","Avoid pipelines that strip query strings when normalizing URLs."],"tags":["facebook","invalid-url","redirect","expected"],"backgroundTag":"invalid-url","analyzedSha":"81ecd58b1394793e6da9998cc19fdb45657f1685","analyzedAt":"2026-08-22T12:21:25.439Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}