Repository: yt-dlp/yt-dlp

Issue:
[Facebook] HTTP Error 403 Forbidden when downloading large video formats
### 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'm running yt-dlp version **2023.09.24** ([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 [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

United States

### Provide a description that is worded well enough to be understood

I've made attempts with several different combinations of commands which have resulted in 403 Forbidden. 

### 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 -vU -f 404735044080801v --user-agent Mozilla/5.0 https://www.facebook.com/phish/videos/152808949678554/ -o %(title)s-%(id)s.%(ext)s
[debug] Command-line config: ['-vU', '-f', '404735044080801v', '--user-agent', 'Mozilla/5.0', 'https://www.facebook.com/phish/videos/152808949678554/', '-o', '%(title)s-%(id)s.%(ext)s']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2023.09.24.003044 [de015e930] (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.19.0, brotli-1.1.0, certifi-2023.07.22, mutagen-1.47.0, sqlite3-3.35.5, websockets-11.0.3
[debug] Proxy map: {}
[debug] Loaded 1886 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Available version: nightly@2023.09.24.003044, Current version: nightly@2023.09.24.003044
Current Build Hash: ae626af90fddd3d68a288ab85854c1a264ceee75fbbc2a2a5a47f14b06e7ab13
yt-dlp is up to date (nightly@2023.09.24.003044)
[facebook] Extracting URL: https://www.facebook.com/phish/videos/152808949678554/
[facebook] 152808949678554: 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
[info] 152808949678554: Downloading 1 format(s): 404735044080801v
[debug] Invoking http downloader on "https://video-sea1-1.xx.fbcdn.net/o1/v/t29/f1/m49/404735044080801.mp4?efg=eyJ2ZW5jb2RlX3RhZyI6ImRhc2hfbGl2ZV9oZDJfZnJhZ18yX3ZpZGVvIn0&_nc_ht=video-sea1-1.xx.fbcdn.net&_nc_cat=111&strext=1&ccb=9-4&oh=00_AfCgaATXWZBjt82KYLAp2rGk_pExXFOwgjV7vY6hyOcG7A&oe=65124D28&_nc_sid=9ca052"
ERROR: unable to download video data: HTTP Error 403: Forbidden
Traceback (most recent call last):
  File "yt_dlp\networking\_urllib.py", line 410, in _send
  File "urllib\request.py", line 531, in open
  File "urllib\request.py", line 640, in http_response
  File "urllib\request.py", line 569, in error
  File "urllib\request.py", line 502, in _call_chain
  File "urllib\request.py", line 649, in http_error_default
urllib.error.HTTPError: HTTP Error 403: Forbidden

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 4051, in urlopen
  File "yt_dlp\networking\common.py", line 114, in send
  File "yt_dlp\networking\_helper.py", line 204, in wrapper
  File "yt_dlp\networking\common.py", line 325, in send
  File "yt_dlp\networking\_urllib.py", line 415, in _send
yt_dlp.networking.exceptions.HTTPError: HTTP Error 403: Forbidden

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 3387, in process_info
  File "yt_dlp\YoutubeDL.py", line 3108, in dl
  File "yt_dlp\downloader\common.py", line 455, in download
  File "yt_dlp\downloader\http.py", line 364, in real_download
  File "yt_dlp\downloader\http.py", line 120, in establish_connection
  File "yt_dlp\YoutubeDL.py", line 4070, in urlopen
yt_dlp.networking.exceptions._CompatHTTPError: HTTP Error 403: Forbidden
```



Discussion:
Don't pass cookies
Ok, here is the same command without passing cookies

```
yt-dlp -vU -f 404735044080801v --user-agent Mozilla/5.0 https://www.facebook.com/phish/videos/152808949678554/ -o %(title)s-%(id)s.%(ext)s
[debug] Command-line config: ['-vU', '-f', '404735044080801v', '--user-agent', 'Mozilla/5.0', 'https://www.facebook.com/phish/videos/152808949678554/', '-o', '%(title)s-%(id)s.%(ext)s']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2023.09.24.003044 [de015e930] (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.19.0, brotli-1.1.0, certifi-2023.07.22, mutagen-1.47.0, sqlite3-3.35.5, websockets-11.0.3
[debug] Proxy map: {}
[debug] Loaded 1886 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Available version: nightly@2023.09.24.003044, Current version: nightly@2023.09.24.003044
Current Build Hash: ae626af90fddd3d68a288ab85854c1a264ceee75fbbc2a2a5a47f14b06e7ab13
yt-dlp is up to date (nightly@2023.09.24.003044)
[facebook] Extracting URL: https://www.facebook.com/phish/videos/152808949678554/
[facebook] 152808949678554: 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
[info] 152808949678554: Downloading 1 format(s): 404735044080801v
[debug] Invoking http downloader on "https://video-sea1-1.xx.fbcdn.net/o1/v/t29/f1/m49/404735044080801.mp4?efg=eyJ2ZW5jb2RlX3RhZyI6ImRhc2hfbGl2ZV9oZDJfZnJhZ18yX3ZpZGVvIn0&_nc_ht=video-sea1-1.xx.fbcdn.net&_nc_cat=111&strext=1&ccb=9-4&oh=00_AfCgaATXWZBjt82KYLAp2rGk_pExXFOwgjV7vY6hyOcG7A&oe=65124D28&_nc_sid=9ca052"
ERROR: unable to download video data: HTTP Error 403: Forbidden
Traceback (most recent call last):
  File "yt_dlp\networking\_urllib.py", line 410, in _send
  File "urllib\request.py", line 531, in open
  File "urllib\request.py", line 640, in http_response
  File "urllib\request.py", line 569, in error
  File "urllib\request.py", line 502, in _call_chain
  File "urllib\request.py", line 649, in http_error_default
urllib.error.HTTPError: HTTP Error 403: Forbidden

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 4051, in urlopen
  File "yt_dlp\networking\common.py", line 114, in send
  File "yt_dlp\networking\_helper.py", line 204, in wrapper
  File "yt_dlp\networking\common.py", line 325, in send
  File "yt_dlp\networking\_urllib.py", line 415, in _send
yt_dlp.networking.exceptions.HTTPError: HTTP Error 403: Forbidden

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 3387, in process_info
  File "yt_dlp\YoutubeDL.py", line 3108, in dl
  File "yt_dlp\downloader\common.py", line 455, in download
  File "yt_dlp\downloader\http.py", line 364, in real_download
  File "yt_dlp\downloader\http.py", line 120, in establish_connection
  File "yt_dlp\YoutubeDL.py", line 4070, in urlopen
yt_dlp.networking.exceptions._CompatHTTPError: HTTP Error 403: Forbidden
```
This issue seems to impact archived Facebook livestreams with large video formats (>500MB).

The 720p format from the OP's link downloads just fine. It's only the 1080p format that gives the 403 error.

Another link: https://www.facebook.com/DreamDefenders/videos/615123319385564/
Same deal: archived livestream, >500MB, 720p format gives 403 error, smaller resolution downloads fine
Any idea how to fix this? Running into the same issue
Encountering the same issue with this URL (720p): https://www.facebook.com/nugsnet/videos/1374984386226941/

Input/Flags:
yt-dlp --cookies-from-browser firefox "https://www.facebook.com/nugsnet/videos/1374984386226941/"
yt-dlp --cookies-from-browser chrome "https://www.facebook.com/nugsnet/videos/1374984386226941/"
yt-dlp "https://www.facebook.com/nugsnet/videos/1374984386226941/"

![2024-01-03 15_39_48-PowerShell 7 (x64)](https://github.com/yt-dlp/yt-dlp/assets/5742251/85302c72-e995-4c1d-ba6c-5c2d2ddd1fce)


[facebook] Extracting URL: https://www.facebook.com/nugsnet/videos/1374984386226941/
[facebook] 1374984386226941: Downloading webpage
WARNING: [facebook] unable to extract uploader; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
[info] 1374984386226941: Downloading 1 format(s): 299141044763999v+290189965625216a
[download] Destination: Facebook Live [1374984386226941].f299141044763999v.mp4
[download]   0.7% of    1.61GiB at   68.57MiB/s ETA 00:23[download] Got error: 16056320 bytes read, 1713937240 more expected. Retrying (1/10)...
[download] Destination: Facebook Live [1374984386226941].f299141044763999v.mp4
[download]   0.8% of    1.61GiB at   35.07MiB/s ETA 00:46[download] Got error: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)). Retrying (2/10)...
ERROR: unable to download video data: HTTP Error 403: Forbidden
Verbose output:

 yt-dlp --verbose "https://www.facebook.com/watch/live/?ref=watch_permalink&v=1374984386226941"
[debug] Command-line config: ['--verbose', 'https://www.facebook.com/watch/live/?ref=watch_permalink&v=1374984386226941']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.12.30 from yt-dlp/yt-dlp [f10589e34] (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: ffmpeg 2023-08-23-git-5f5a1ccd04-full_build-www.gyan.dev (setts), ffprobe 2023-08-23-git-5f5a1ccd04-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.19.1, brotli-1.1.0, certifi-2023.11.17, mutagen-1.47.0, requests-2.31.0, sqlite3-3.35.5, urllib3-2.1.0, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1798 extractors
[facebook] Extracting URL: https://www.facebook.com/watch/live/?ref=watch_permalink&v=1374984386226941
[facebook] 1374984386226941: 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] 1374984386226941: Downloading 1 format(s): 299141044763999v+290189965625216a
[debug] Invoking http downloader on "https://video-den2-1.xx.fbcdn.net/o1/v/t29/f1/m49/299141044763999.mp4?efg=eyJ2ZW5jb2RlX3RhZyI6ImRhc2hfbGl2ZV9oZDFfZnJhZ18yX3ZpZGVvIn0&_nc_ht=video-den2-1.xx.fbcdn.net&_nc_cat=104&strext=1&ccb=9-4&oh=00_AfBVq8hMmYxyxoR9-YA4pkaXY_d4DdnbaHKL2IsTpdFo5Q&oe=65977D5C&_nc_sid=9ca052"
[download] Resuming download at byte 251854848
[download] Got error: 0 bytes read, 1478138712 more expected. Retrying (1/10)...
[download] Got error: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)). Retrying (2/10)...
ERROR: unable to download video data: HTTP Error 403: Forbidden
Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 4082, in urlopen
  File "yt_dlp\networking\common.py", line 114, in send
  File "yt_dlp\networking\_helper.py", line 204, in wrapper
  File "yt_dlp\networking\common.py", line 325, in send
  File "yt_dlp\networking\_requests.py", line 343, in _send
yt_dlp.networking.exceptions.HTTPError: HTTP Error 403: Forbidden

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 3400, in process_info
  File "yt_dlp\YoutubeDL.py", line 3139, in dl
  File "yt_dlp\downloader\common.py", line 455, in download
  File "yt_dlp\downloader\http.py", line 364, in real_download
  File "yt_dlp\downloader\http.py", line 120, in establish_connection
  File "yt_dlp\YoutubeDL.py", line 4114, in urlopen
yt_dlp.networking.exceptions._CompatHTTPError: HTTP Error 403: Forbidden
can someone try and confirm whether download is successful with "--http-chunk-size 250M"?

e.g.:
```
yt-dlp -f bv+ba --http-chunk-size 250M "https://www.facebook.com/phish/videos/152808949678554/"
```


_(please ensure it encounters 403 before try)_
e.g.:   yt-dlp -f bv+ba "https://www.facebook.com/phish/videos/152808949678554/"
> can someone try and confirm whether download is successful with "--http-chunk-size 250M"?
> 
> e.g.:
> 
> ```
> yt-dlp -f bv+ba --http-chunk-size 250M "https://www.facebook.com/phish/videos/152808949678554/"
> ```
> 
> _(please ensure it encounters 403 before try)_ e.g.: yt-dlp -f bv+ba "https://www.facebook.com/phish/videos/152808949678554/"

Nice this worked for the videos I was trying to download 👍 
@kclauhk good idea

we could do this
```diff
diff --git a/yt_dlp/extractor/facebook.py b/yt_dlp/extractor/facebook.py
index a07a0d344..979187c77 100644
--- a/yt_dlp/extractor/facebook.py
+++ b/yt_dlp/extractor/facebook.py
@@ -542,10 +542,12 @@ def extract_dash_manifest(video, formats):
                     mpd_url=video.get('dash_manifest_url')))
 
         def process_formats(info):
-            # Downloads with browser's User-Agent are rate limited. Working around
-            # with non-browser User-Agent.
             for f in info['formats']:
+                # Downloads with browser's User-Agent are rate limited. Working around
+                # with non-browser User-Agent.
                 f.setdefault('http_headers', {})['User-Agent'] = 'facebookexternalhit/1.1'
+                # Formats larger than ~500MB will return error 403 unless chunk size is regulated
+                f.setdefault('downloader_options', {})['http_chunk_size'] = 250 << 20
 
         def extract_relay_data(_filter):
             return self._parse_json(self._search_regex(
```

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
@@ -564,7 +564,11 @@ def process_formats(info):
             # Downloads with browser's User-Agent are rate limited. Working around
             # with non-browser User-Agent.
             for f in info['formats']:
+                # Downloads with browser's User-Agent are rate limited. Working around
+                # with non-browser User-Agent.
                 f.setdefault('http_headers', {})['User-Agent'] = 'facebookexternalhit/1.1'
+                # Formats larger than ~500MB will return error 403 unless chunk size is regulated
+                f.setdefault('downloader_options', {})['http_chunk_size'] = 250 << 20
 
         def extract_relay_data(_filter):
             return self._parse_json(self._search_regex(


Test patch: