Repository: yt-dlp/yt-dlp

Issue:
Facebook Pages videos are only downloaded in SD quality, but on FB page HD is available
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

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

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [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 [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and 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)
- [ ] 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

Worldwide, it's a public Facebook Page

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

Hello, I'm experiencing an issue since some days ago, while trying to download a video from Facebook. The quality downloaded is 360, but the best available should be 720 (you can verify it from the Facebook Video Player). So I ran the "--print formats_table" in order to verify which quality alternatives is yt-dlp seeing for this video, and then I realize that it is only one SD alternative (which surely is the 360p previously downloaded), and the 720p alternative is not shown on the table.
Example: yt-dlp.exe -vU --print formats_table https://facebook.com/475841587884690/videos/744372871141776

Is this a bug from yt-dlp that will get fixed soon?
Thanks in advance.
Regards


### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
yt-dlp.exe -vU --print formats_table https://facebook.com/475841587884690/videos/744372871141776

[debug] Command-line config: ['-vU', '--print', 'formats_table', 'https://facebook.com/475841587884690/videos/744372871141776']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2024.04.18.232703 from yt-dlp/yt-dlp-nightly-builds [c9ce57d9b] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: none
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.02.02, curl_cffi-0.5.10, mutagen-1.47.0, requests-2.31.0, sqlite3-3.35.5, urllib3-2.2.1, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets, curl_cffi
[debug] Loaded 1810 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Latest version: nightly@2024.04.18.232703 from yt-dlp/yt-dlp-nightly-builds
yt-dlp is up to date (nightly@2024.04.18.232703 from yt-dlp/yt-dlp-nightly-builds)
[facebook] Extracting URL: https://facebook.com/475841587884690/videos/744372871141776
[facebook] 744372871141776: Downloading webpage
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, size, br, asr, proto, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 744372871141776: Downloading 1 format(s): sd
ID EXT RESOLUTION │ PROTO │ VCODEC  ACODEC
───────────────────────────────────────────
sd mp4 unknown    │ https │ unknown unknown
```



Discussion:
this seems to fix it:
```diff
diff --git a/yt_dlp/extractor/facebook.py b/yt_dlp/extractor/facebook.py
index 834b1df18..b76407a5c 100644
--- a/yt_dlp/extractor/facebook.py
+++ b/yt_dlp/extractor/facebook.py
@@ -560,7 +560,7 @@ def extract_from_jsmods_instances(js_data):
                     js_data, lambda x: x['jsmods']['instances'], list) or [])
 
         def extract_dash_manifest(video, formats):
-            dash_manifest = video.get('dash_manifest')
+            dash_manifest = traverse_obj(video, 'dash_manifest', 'playlist', expected_type=str)
             if dash_manifest:
                 formats.extend(self._parse_mpd_formats(
                     compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
```
```shell
$ yt-dlp -F https://facebook.com/475841587884690/videos/744372871141776
[facebook] Extracting URL: https://facebook.com/475841587884690/videos/744372871141776
[facebook] 744372871141776: Downloading webpage
[info] Available formats for 744372871141776:
ID                EXT RESOLUTION │   FILESIZE  TBR PROTO │ VCODEC       VBR ACODEC     ABR ASR MORE INFO
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2890193591132187a m4a audio only │ ~ 10.64MiB  65k https │ audio only       mp4a.40.5  65k 48k DASH audio, m4a_dash
sd                mp4 unknown    │                 https │ unknown          unknown
308764358916363v  mp4 256x144    │ ~ 10.46MiB  64k https │ avc1.4D400C  64k video only         DASH video, mp4_dash
454016937233089v  mp4 426x240    │ ~ 23.25MiB 142k https │ avc1.4D4015 142k video only         DASH video, mp4_dash
7151401058299907v mp4 640x360    │ ~ 40.43MiB 248k https │ avc1.4D401E 248k video only         DASH video, mp4_dash
442595941470298v  mp4 854x480    │ ~ 65.56MiB 402k https │ avc1.4D401F 402k video only         DASH video, mp4_dash
448319621059078v  mp4 1280x720   │ ~111.09MiB 681k https │ avc1.4D4020 681k video only         DASH video, mp4_dash
```
hello @bashonly , thanks for your fast reply and for your fix, but I'm not very familiar with Python, neither with the yt-dlp workflow. Is there anything I can do to apply your patch or it will be released soon in some specific version of yp-dlp?
Thanks. Regards
> this seems to fix it:
> 
> ```diff
> diff --git a/yt_dlp/extractor/facebook.py b/yt_dlp/extractor/facebook.py
> index 834b1df18..b76407a5c 100644
> --- a/yt_dlp/extractor/facebook.py
> +++ b/yt_dlp/extractor/facebook.py
> @@ -560,7 +560,7 @@ def extract_from_jsmods_instances(js_data):
>                      js_data, lambda x: x['jsmods']['instances'], list) or [])
>  
>          def extract_dash_manifest(video, formats):
> -            dash_manifest = video.get('dash_manifest')
> +            dash_manifest = traverse_obj(video, 'dash_manifest', 'playlist', expected_type=str)
>              if dash_manifest:
>                  formats.extend(self._parse_mpd_formats(
>                      compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
> ```
> 

I'm also very interested in this fix, but I don't understand where I need to insert this code snippet to make it work.
i have the same problem too.

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
@@ -560,7 +560,7 @@ def extract_from_jsmods_instances(js_data):
                     js_data, lambda x: x['jsmods']['instances'], list) or [])
 
         def extract_dash_manifest(video, formats):
-            dash_manifest = video.get('dash_manifest')
+            dash_manifest = traverse_obj(video, 'dash_manifest', 'playlist', expected_type=str)
             if dash_manifest:
                 formats.extend(self._parse_mpd_formats(
                     compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),


Test patch: