Repository: yt-dlp/yt-dlp

Issue:
facebook extractor - added handling of facebook.com/event/id
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.10.04** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Italy

### Provide a description that is worded well enough to be understood

Facebook video pages of the form
https://www.facebook.com/events/
do not get downloaded.



I made a fix for it which is in the attachment
[yt-dlp-20221025.1.diff.txt](https://github.com/yt-dlp/yt-dlp/files/9861917/yt-dlp-20221025.1.diff.txt)

which is:
```
--- /home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/extractor/facebook.py
+++ /home/mar/PycharmProjects/yt-dlp/#backup/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/extractor/facebook.py
@@ -50,6 +50,7 @@
                             )\?(?:.*?)(?:v|video_id|story_fbid)=|
                             [^/]+/videos/(?:[^/]+/)?|
                             [^/]+/posts/|
+                            events/(?:[^/]+/)?|
                             groups/[^/]+/permalink/|
                             watchparty/
                         )|
@@ -562,6 +563,15 @@
                     if not entries:
                         parse_graphql_video(video)

+                if not entries:
+                    event = data.get('event') or {}
+                    if event:
+                        cover_media_renderer = event.get('cover_media_renderer') or {}
+                        if cover_media_renderer:
+                            cover_video = cover_media_renderer.get('cover_video') or {}
+                            if cover_video:
+                                parse_graphql_video(cover_video)
+
                 if len(entries) > 1:
                     return self.playlist_result(entries, video_id)
```


I hope it helps. I prefer not to commit the patch myself.


I'd have one question.
- the path ['online_cta_renderer']['event']['live_virtual_event_info']['associated_live_videos']['edges']
  gives me a 'node' from 'canonical_url_with_fallback' which gives me an url that if I download manually with yt-dlp would give 
  me a better thumbnail. This is not important, but generally speaking, is there a way to do the same automatically from the function
  `def _extract_from_url(self, url, video_id)` ?

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/bin/python /home/mar/PycharmProjects/yt-dlp/yt-dlp/DownloadVideo.py
No module named 'selenium'
[debug] print_options: True
[debug] writeurlshortcut: True
[debug] zipsubtitles: True
[debug] writesubtitles: True
[debug] writeautomaticsub: True
[debug] allsubtitlesnormal: True
[debug] skip_download: False
[debug] subtitlesformat: srt/best
[debug] subtitleslangs: ['en', 'it', 'es', 'fr', 'pt', 'de']    ***
[debug] subtitles_converter: <function subtitles_converter at 0x7f8d6cdf3e50>
[debug] subtitles_converted_overwrite_destination: True
[debug] subtitles_converted_keep_source: True
[debug] writethumbnail: True
[debug] writelink: True    ***
[debug] writeurllink: True    ***
[debug] nooverwrites: True
[debug] writeannotations: True
[debug] postprocessor_pages: <function postprocessor_pages at 0x7f8d6519e550>
[debug] continue_dl: True
[debug] no_cache_dir: True
[debug] rm_cache_dir: True
[debug] format: best[height=460]/best[height>360]/best    ***
[debug] basePath: ~/work/files/
[debug] outtmpl: {'default': '~/work/files/videos/%(title)s/%(title)s - %(uploader)s-%(channel)s - %(playlist)s-%(playlist_index)s-%(id)s - %(extractor)s - %(format_id)s-%(height)sp-%(fps)sfps-%(asr)s.%(ext)s', 'chapter': '%(title)s - %(section_number)03d %(section_title)s [%(id)s].%(ext)s'}
[debug] outtmpl_video_files: ~/work/files/videos_pages/%(title)s/%(title)s - %(format_id)s-%(height)sp-%(fps)sfps-%(asr)s.%(ext)s
[debug] outtmpl_pages: ~/work/files/videos_pages/%(title)s/%(title)s.%(ext)s
[debug] max_dir_length: 250    ***
[debug] max_file_length: 232
[generic] 1509582499515440: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] 1509582499515440: Extracting information
ERROR: Unsupported URL: https://m.facebook.com/events/1509582499515440
Traceback (most recent call last):
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1478, in wrapper
    return func(self, *args, **kwargs)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1554, in __extract_info
    ie_result = ie.extract(url)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/extractor/common.py", line 674, in extract
    ie_result = self._real_extract(url)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/extractor/generic.py", line 2756, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://m.facebook.com/events/1509582499515440

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/DownloadVideo.py", line 706, in <module>
    main()
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/DownloadVideo.py", line 613, in main
    download_video(ydl_opts, urls)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/DownloadVideo.py", line 697, in download_video
    ydl.download(urls)           # vids
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 3316, in download
    self.__download_wrapper(self.extract_info)(
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 3291, in wrapper
    res = func(*args, **kwargs)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1467, in extract_info
    return self.__extract_info(url, self.get_info_extractor(key), download, extra_info, process)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1496, in wrapper
    self.report_error(str(e), e.format_traceback())
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 997, in report_error
    self.trouble(f'{self._format_err("ERROR:", self.Styles.ERROR)} {message}', *args, **kwargs)
  File "/home/mar/PycharmProjects/yt-dlp/yt-dlp/venv/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 937, in trouble
    raise DownloadError(message, exc_info)
yt_dlp.utils.DownloadError: ERROR: Unsupported URL: https://m.facebook.com/events/1509582499515440

Process finished with exit code 1
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/facebook.py b/yt_dlp/extractor/facebook.py
--- a/yt_dlp/extractor/facebook.py
+++ b/yt_dlp/extractor/facebook.py
@@ -53,6 +53,7 @@ class FacebookIE(InfoExtractor):
                             )\?(?:.*?)(?:v|video_id|story_fbid)=|
                             [^/]+/videos/(?:[^/]+/)?|
                             [^/]+/posts/|
+                            events/(?:[^/]+/)?|
                             groups/[^/]+/(?:permalink|posts)/|
                             watchparty/
                         )|
@@ -381,6 +382,18 @@ class FacebookIE(InfoExtractor):
         },
         'playlist_count': 1,
         'skip': 'Requires logging in',
+    }, {
+        # data.event.cover_media_renderer.cover_video
+        'url': 'https://m.facebook.com/events/1509582499515440',
+        'info_dict': {
+            'id': '637246984455045',
+            'ext': 'mp4',
+            'title': 'ANALISI IN CAMPO OSCURO " Coaguli nel sangue dei vaccinati"',
+            'description': 'Other event by Comitato Liberi Pensatori on Tuesday, October 18 2022',
+            'thumbnail': r're:^https?://.*',
+            'uploader': 'Comitato Liberi Pensatori',
+            'uploader_id': '100065709540881',
+        },
     }]
     _SUPPORTED_PAGLETS_REGEX = r'(?:pagelet_group_mall|permalink_video_pagelet|hyperfeed_story_id_[0-9a-f]+)'
     _api_config = {
@@ -455,38 +468,10 @@ def extract_metadata(webpage):
                 r'data-sjs>({.*?ScheduledServerJS.*?})</script>', webpage)]
             post = traverse_obj(post_data, (
                 ..., 'require', ..., ..., ..., '__bbox', 'require', ..., ..., ..., '__bbox', 'result', 'data'), expected_type=dict) or []
-
-            automatic_captions, subtitles = {}, {}
-            subs_data = traverse_obj(post, (..., 'video', ..., 'attachments', ..., lambda k, v: (
-                k == 'media' and str(v['id']) == video_id and v['__typename'] == 'Video')))
-            is_video_broadcast = get_first(subs_data, 'is_video_broadcast', expected_type=bool)
-            captions = get_first(subs_data, 'video_available_captions_locales', 'captions_url')
-            if url_or_none(captions):  # if subs_data only had a 'captions_url'
-                locale = self._html_search_meta(['og:locale', 'twitter:locale'], webpage, 'locale', default='en_US')
-                subtitles[locale] = [{'url': captions}]
-            # or else subs_data had 'video_available_captions_locales', a list of dicts
-            for caption in traverse_obj(captions, (
-                {lambda x: sorted(x, key=lambda c: c['locale'])}, lambda _, v: v['captions_url'])
-            ):
-                lang = caption.get('localized_language') or ''
-                subs = {
-                    'url': caption['captions_url'],
-                    'name': format_field(caption, 'localized_country', f'{lang} (%s)', default=lang),
-                }
-                if caption.get('localized_creation_method') or is_video_broadcast:
-                    automatic_captions.setdefault(caption['locale'], []).append(subs)
-                else:
-                    subtitles.setdefault(caption['locale'], []).append(subs)
-
             media = traverse_obj(post, (..., 'attachments', ..., lambda k, v: (
                 k == 'media' and str(v['id']) == video_id and v['__typename'] == 'Video')), expected_type=dict)
             title = get_first(media, ('title', 'text'))
             description = get_first(media, ('creation_story', 'comet_sections', 'message', 'story', 'message', 'text'))
-            uploader_data = (
-                get_first(media, ('owner', {dict}))
-                or get_first(post, (..., 'video', lambda k, v: k == 'owner' and v['name']))
-                or get_first(post, ('node', 'actors', ..., {dict})) or {})
-
             page_title = title or self._html_search_regex((
                 r'<h2\s+[^>]*class="uiHeaderTitle"[^>]*>(?P<content>[^<]*)</h2>',
                 r'(?s)<span class="fbPhotosPhotoCaption".*?id="fbPhotoPageCaption"><span class="hasCaption">(?P<content>.*?)</span>',
@@ -495,11 +480,15 @@ def extract_metadata(webpage):
             description = description or self._html_search_meta(
                 ['description', 'og:description', 'twitter:description'],
                 webpage, 'description', default=None)
+            uploader_data = (
+                get_first(media, ('owner', {dict}))
+                or get_first(post, (..., 'video', lambda k, v: k == 'owner' and v['name']))
+                or get_first(post, ('node', 'actors', ..., {dict}))
+                or get_first(post, ('event', 'event_creator', {dict})) or {})
             uploader = uploader_data.get('name') or (
                 clean_html(get_element_by_id('fbPhotoPageAuthorName', webpage))
                 or self._search_regex(
                     (r'ownerName\s*:\s*"([^"]+)"', *self._og_regexes('title')), webpage, 'uploader', fatal=False))
-
             timestamp = int_or_none(self._search_regex(
                 r'<abbr[^>]+data-utime=["\'](\d+)', webpage,
                 'timestamp', default=None))
@@ -521,8 +510,6 @@ def extract_metadata(webpage):
                     webpage, 'view count', default=None)),
                 'concurrent_view_count': get_first(post, (
                     ('video', (..., ..., 'attachments', ..., 'media')), 'liveViewerCount', {int_or_none})),
-                'automatic_captions': automatic_captions,
-                'subtitles': subtitles,
             }
 
             info_json_ld = self._search_json_ld(webpage, video_id, default={})
@@ -616,6 +603,29 @@ def parse_graphql_video(video):
                                 'url': playable_url,
                             })
                     extract_dash_manifest(video, formats)
+
+                    automatic_captions, subtitles = {}, {}
+                    is_broadcast = traverse_obj(video, ('is_video_broadcast', {bool}))
+                    for caption in traverse_obj(video, (
+                        'video_available_captions_locales',
+                        {lambda x: sorted(x, key=lambda c: c['locale'])},
+                        lambda _, v: url_or_none(v['captions_url'])
+                    )):
+                        lang = caption.get('localized_language') or 'und'
+                        subs = {
+                            'url': caption['captions_url'],
+                            'name': format_field(caption, 'localized_country', f'{lang} (%s)', default=lang),
+                        }
+                        if caption.get('localized_creation_method') or is_broadcast:
+                            automatic_captions.setdefault(caption['locale'], []).append(subs)
+                        else:
+                            subtitles.setdefault(caption['locale'], []).append(subs)
+                    captions_url = traverse_obj(video, ('captions_url', {url_or_none}))
+                    if captions_url and not automatic_captions and not subtitles:
+                        locale = self._html_search_meta(
+                            ['og:locale', 'twitter:locale'], webpage, 'locale', default='en_US')
+                        (automatic_captions if is_broadcast else subtitles)[locale] = [{'url': captions_url}]
+
                     info = {
                         'id': v_id,
                         'formats': formats,
@@ -625,6 +635,8 @@ def parse_graphql_video(video):
                         'timestamp': traverse_obj(video, 'publish_time', 'creation_time', expected_type=int_or_none),
                         'duration': (float_or_none(video.get('playable_duration_in_ms'), 1000)
                                      or float_or_none(video.get('length_in_second'))),
+                        'automatic_captions': automatic_captions,
+                        'subtitles': subtitles,
                     }
                     process_formats(info)
                     description = try_get(video, lambda x: x['savable_description']['text'])
@@ -659,7 +671,8 @@ def parse_attachment(attachment, key='media'):
                 for edge in edges:
                     parse_attachment(edge, key='node')
 
-                video = data.get('video') or {}
+                video = traverse_obj(data, (
+                    'event', 'cover_media_renderer', 'cover_video'), 'video', expected_type=dict) or {}
                 if video:
                     attachments = try_get(video, [
                         lambda x: x['story']['attachments'],


Test patch: