From c555e5e478b3d9bc5861bcbd4a9cfe5d61958758 Mon Sep 17 00:00:00 2001 From: dirkf Date: Tue, 19 Apr 2022 12:57:22 +0100 Subject: [PATCH] [Facebook] Check for redirection to URL with `login`, or not a permalink, or not including the ID --- youtube_dl/extractor/facebook.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/facebook.py b/youtube_dl/extractor/facebook.py index a3f1bd325..389d1f7bf 100644 --- a/youtube_dl/extractor/facebook.py +++ b/youtube_dl/extractor/facebook.py @@ -410,8 +410,15 @@ class FacebookIE(InfoExtractor): self._login() def _extract_from_url(self, url, video_id): - webpage = self._download_webpage( + webpage, urlh = self._download_webpage_handle( url.replace('://m.facebook.com/', '://www.facebook.com/'), video_id) + login_or_id_check = re.search(r'(?P\blogin\b)|/permalink/|[/=?]' + video_id, urlh.geturl()) + if login_or_id_check and login_or_id_check.group('login'): + self.raise_login_required() + elif not login_or_id_check: + raise ExtractorError( + 'Facebook redirected to a generic page (%s): the video may be unavailable or you may need to log in.' % urlh.geturl(), + expected=True) def extract_metadata(webpage): video_title = self._html_search_regex(