In the orchestra I am member of we recently realised that we are missing original videos in our video archive, the only copy we have of the videos are either on our either on our fan page or in our private Facebook group. Hence my task was to retreive the videos in the best possible quality.
Usage: youtube-dl.exe [OPTIONS] URL [URL...]
Downloading a public video
Downloading a public video from Facebook is rather easy using youtube-dl. Get the URL of the video to download. Let’s use this video as an example.
The output should look something like below, and you now have a video file saved in the folder.
youtube-dl https://www.facebook.com/LudvikaSS/videos/luss-måndagsträning-219-2020/2783077575293555/ [facebook] 2783077575293555: Downloading webpage [download] Destination: Facebook video #2783077575293555-2783077575293555.f431509714569993v.mp4 [download] 100% of 10.33MiB in 00:00 [download] Destination: Facebook video #2783077575293555-2783077575293555.f326406205105276a.m4a [download] 100% of 126.29KiB in 00:00 [ffmpeg] Merging formats into "Facebook video #2783077575293555-2783077575293555.mp4" Deleting original file Facebook video #2783077575293555-2783077575293555.f431509714569993v.mp4 (pass -k to keep) Deleting original file Facebook video #2783077575293555-2783077575293555.f326406205105276a.m4a (pass -k to keep)
Downloading a private video
Downloading a private video is a tad more challenging. Trying to download a video that requies authentication might give you one of the following errors:
ERROR: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials. ERROR: Cannot parse data; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
If you don’t have 2 factor authentication, it might work to just provide your account credentials using the
--username and --password flags, but for me this doesn’t work. The workaround in this case is using cookies.
- We log into Facebook using our authentication details and navigate to the video we want to download.
- Next is to find the request headers of the page.
- This is easily done in Firefox and Chrome by opening Developer Tools and navigating to Network Tab
- If there are requests in the list, clear them so you have an empty list.
- Reload the page.
- Select the correct request. This is usually the first request with a 200 response,
- Select Headers tab
- Navigate to the section cookies
- Copy the whole cookie header
For me the cookie header looks something along the following lines:
Cookie: datr=Z21_X3Ch3********lud6NC; fr=1HS4RVaK2Rd9TIzRl.AWWYeTbPI31GF_WAI********.Bgg-cQ.Qs.AAA.0.0.Bgg-cQ.AWUN2qmLGnk; sb=kG1_Xx5EHSyzL1xoLFh6iRtO; c_user=167304****; xs=28%3AEJgSdW-4dQ0Ysg%3A2%3A1602**********%3A6762%3A%3AAcULoH7o********GZt210lhg; _fbp=fb.1.16157245128********4; presence=C%7B%2**************2u.602371828%22%7D%2C%7B%22i%22%3A%22u.100003394271915%22%7D%2C%7B%22i%22%3A%22u.138954************1%7D; wd=18*****8; spin=r.1003**********3_b.trunk_t.1619201242_s****.2_
Then you paste the cookie string into the download request using the argument
youtube-dl --add-header "Cookie:COOKIE-STRING" "URL-TO-FILE
youtube-dl.exe --add-header "Cookie: datr=Z21_X3 **TRUNKATED-COOKIE-STRING**" https://www.facebook.com/ajain93/videos/10204772647150690 [facebook] 10204772647150690: Downloading webpage [download] Downloading playlist: 10204772647150690 [facebook] playlist 10204772647150690: Collected 1 video ids (downloading 1 of them) [download] Downloading video 1 of 1 [download] Destination: Facebook video #10204772647150690-10204772647150690.f10204772743233092v.mp4 [download] 100% of 563.85KiB in 00:00 [download] Destination: Facebook video #10204772647150690-10204772647150690.f10204772743193091a.m4a [download] 100% of 71.20KiB in 00:00 [ffmpeg] Merging formats into "Facebook video #10204772647150690-10204772647150690.mp4" Deleting original file Facebook video #10204772647150690-10204772647150690.f10204772743233092v.mp4 (pass -k to keep) Deleting original file Facebook video #10204772647150690-10204772647150690.f10204772743193091a.m4a (pass -k to keep) [download] Finished downloading playlist: 10204772647150690