Skip to content

Instantly share code, notes, and snippets.

@dexeonify
Last active March 25, 2023 10:19
Show Gist options
  • Save dexeonify/a362d8a843dafea2905bb8fd6a425ea2 to your computer and use it in GitHub Desktop.
Save dexeonify/a362d8a843dafea2905bb8fd6a425ea2 to your computer and use it in GitHub Desktop.
Download Facebook videos manually using DevTools, without using yt-dlp. Works best for login-protected videos.

Download Facebook videos - The Manual Way

The manual way, also the safest way for YOUR account. This method doesn't use external programs that utilises the cookies of your Facebook session, nor does it involve running some unreliable JS codes that is likely to break every time Facebook updates its backend or frontend code. Instead, it makes use of your browser's DevTools Network panel to intercept and extract video streams from the Facebook page.

Why not yt-dlp?

Read the full story at yt-dlp/yt-dlp#4311.

TL;DR: Whenever you pass your cookies to yt-dlp through the --cookies or --cookies-from-browser flags, Facebook actively locks your account under the pretext of "detecting suspicious activities". Furthermore, others have noted that Facebook may ban your IP, if you download the same video too frequently, even for public videos. While I can't verify the latter, it is clear that yt-dlp is unreliable at downloading Facebook videos.

Some anecdotes of mine: My account had been locked account 3 times, each time shortly after I had used yt-dlp. Even if I hadn't downloaded the video, they can still lock you out just by letting yt-dlp request the video link using your cookies file. While I can successfully unlock my account on all occasions, I would rather not give them my ID in the future. Facebook may lock your account as they please, although I've made it apparent that the additional logins are from me.

Thus, it's with my conscience that using yt-dlp or any other services that requires your login credentials/cookies file to download Facebook videos should be AVOIDED.

Using the DevTools' Network Panel

So, how should you download it exactly?

  1. Login to your Facebook, navigate to your private group, find the video/live stream bla, bla... Steps that shouldn't need to be mentioned.

  2. Open your browser's DevTools (usually the F12 key) and navigate to the Network tab.

  3. Before reloading, filter the logs by "Media" OR by .mp41. Facebook is notorious for making a shitload of requests per page load, even moreso without an Ad-blocker.

  4. Randomly select an mp4 fragment that matches the video you want, to the best of your ability. This is especially tough if there are multiple videos on the page.

    If you want to change the quality, change it now. Perhaps seek the video to force a new chunk to be downloaded. Then, pick one of the most recently logged requests.

  5. Open the selected fragment in a new tab. The video will not play. This is where you have to modify the URL to not include the &bytestart=...&byteend=... parameter.

    A handy tip:

    Since the parameters are usually located at the end of the URL, and the URLs are so long that it's unwieldy to edit, focus the address bar and press End on your keyboard. This will immediately bring you to the end of the URL, from then on you can easily remove the parameters above.

  6. The video should now play. You can now download the video normally using your browser's "Save Video As" function.

    If your browser showed an audio stream instead, download them the same. You picked a special one!

  7. But wait! You are only downloading the video stream. The video you downloaded won't contain audio (or the audio you downloaded won't contain a video stream). What to do next?

  8. Simple, you have to download the audio/video file separately. Redo each step starting from Step 4. Except this time, you can be a little smarter. You don't have to reload, you shouldn't pick the same URL again (the network panel should show you that), if you get a video stream again then restart the process. By using the process of elimination, you ought to be able to locate the remaining missing stream.

  9. Now that you have downloaded the files, how do you combine them to form a complete media file? You use ffmpeg for that. If you don't have one set-up already, then you need to search for instructions online to guide you through.

    A simple ffmpeg command to merge video and audio files:

    ffmpeg -i <video_file> -i <audio_file> -c copy output.mp4
  10. You have successfully downloaded a complete video from Facebook, safe and sound! You may now delete your individual video and audio streams files after ffmpeg has remuxed cleanly.

Using the View Page Source method

This is an alternative method for those who are more technically inclined. As I had previously discovered, the parameters in the URL don't correspond to whether it's an audio file or video file. Consequently, getting the correct combination of video and audio streams may need some trial-and-error. However, with this method, you can extract your desired video and audio stream precisely and accurately, provided that you are skilled in sifting information and are not easily overwhelmed by walls-of-text.

  1. As usual, open the Facebook page.

  2. Right-click on the webpage and click "View Page Source", or press its keybind Ctrl+U.

  3. Open the Findbar (Ctrl+F) in the page source tab and search for FBQualityLabel. The highlight should hopefully make them stand out more amist the walls-of-text.

  4. Start searching for the quality you want and pin-point the location of it.

  5. Near the FBQualityLabel tag, there's a BaseURL tag. Copy the URL inside that tag until the next closing BaseURL tag.

    Warning Don't copy the \u003C character together with the URL.

    The unescaped URL look something like this (shorten):

    https:\/\/scontent.fkul16-1.fna.fbcdn.net\/v\/...;oe=642421C9
    

    Note Due to the backslash escaping, it might be challenging to spot the closing BaseURL tag. Use your browser's findbar to highlight all matches of BaseURL for easier identification.

  6. If you open the URL in a new tab, you will get an Unsigned URL message. To fix the URL, simply copy it into a text editor, then replace all instances of \/ with / and all matches of ; with &.

  7. Paste the fixed URL to your browser. If done correctly, the video should play and you can download it straight away.

  8. Like the previous method, you also have to find the audio stream. Return to the Page Source tab, and search for audio/mp4. Unlike FBQualityLabel where they are concentrated in one place, there may be multiple matches of audio\/mp4 across the page. Choose the one that's closer to the previous FBQualityLabel tag.

  9. Again, copy the URL, paste it into your text editor, find-and-replace the \/ and ; symbols, then open it in your browser.

  10. The rest of the steps shouldn't need to be repeated. Refer to Step 9 from the previous method if necessary.

Although it may appear that there are more steps involved, but you can control the quality of the streams downloaded. With practice, it ought to be quicker than the trial-and-error method. 😉

Footnotes

  1. For some reason, Edge doesn't constitutes mp4 fragments as "Media".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment