ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.31k stars 10.03k forks source link

Facebook login TWOFACTOR functionality missing #30337

Open wsbblyy opened 2 years ago

wsbblyy commented 2 years ago

Checklist

Verbose log

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['-u', 'PRIVATE', '-p', 'PRIVATE', '-2', '721664', '-v', 'https://www.facebook.com/106937041769662/videos/601957961078153/']
[debug] Encodings: locale cp936, fs utf-8, out utf-8, pref cp936
[debug] youtube-dl version 2021.06.06
[debug] Python version 3.8.8 (CPython) - Windows-10-10.0.19041-SP0
[debug] exe versions: none
[debug] Proxy map: {}
[facebook] Downloading login page
[facebook] Logging in
[facebook] 601957961078153: Downloading webpage
ERROR: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials.
Traceback (most recent call last):
  File "c:\users\administrator\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 815, in wrapper
    return func(self, *args, **kwargs)
  File "c:\users\administrator\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 836, in __extract_info
    ie_result = ie.extract(url)
  File "c:\users\administrator\anaconda3\lib\site-packages\youtube_dl\extractor\common.py", line 534, in extract
    ie_result = self._real_extract(url)
  File "c:\users\administrator\anaconda3\lib\site-packages\youtube_dl\extractor\facebook.py", line 680, in _real_extract
    return self._extract_from_url(real_url, video_id)
  File "c:\users\administrator\anaconda3\lib\site-packages\youtube_dl\extractor\facebook.py", line 528, in _extract_from_url
    self.raise_login_required()
  File "c:\users\administrator\anaconda3\lib\site-packages\youtube_dl\extractor\common.py", line 941, in raise_login_required
    raise ExtractorError(
youtube_dl.utils.ExtractorError: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials.

Description

Trying to download a facebook post video, debug log shows I successfully logged in, but still shows This video is only available for registered users.. I went thru the facebook login code, didn't find anything about TWOFACTOR functionality, am I missing something?

october262 commented 2 years ago

see under authentication options - https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme

wsbblyy commented 2 years ago

Thanks for reply, if you see the Command-line args in my debug log, I did pass the -2 argument, and I tried multiple times, it always give me this error ERROR: This video is only available for registered users.

see under authentication options - https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme

october262 commented 2 years ago

strange, i was able to download this video - https://www.facebook.com/106937041769662/videos/601957961078153/ without any authentication. are you signed in to your facebook account ??

wsbblyy commented 2 years ago

Yes, I signed in to my Facebook account, but it didn't go thru the 2 factor approvals, the program should perform like this: sign in --> 2 factor approvals --> go download videos,
I debugged the code a little bit, I think it doesn't do anything about the 2 factor approvals part. I assume you don't have the 2 factor approvals on you facebook account that's why you can download the video. The following code is from the youtube-dl library ./extractor/facebook.py 343-360, which performs facebook login, and I didn't find anything about the 2 factor approvals.

login_results = self._download_webpage(request, None,note='Logging in', errnote='unable to fetch login page')
if re.search(r'<form(.*)name="login"(.*)</form>', login_results) is not None:
    error = self._html_search_regex(
                   r'(?s)<div[^>]+class=(["\']).*?login_error_box.*?\1[^>]*><div[^>]*>.*?</div><div[^>]*>(?P<error>.+?)</div>',
                   login_results, 'login error', default=None, group='error')
    if error:
        raise ExtractorError('Unable to login: %s' % error, expected=True)
    self._downloader.report_warning('unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.')
    return

    fb_dtsg = self._search_regex(r'name="fb_dtsg" value="(.+?)"', login_results, 'fb_dtsg', default=None)
    h = self._search_regex(r'name="h"\s+(?:\w+="[^"]+"\s+)*?value="([^"]+)"', login_results, 'h', default=None)

    if not fb_dtsg or not h:
        return

strange, i was able to download this video - https://www.facebook.com/106937041769662/videos/601957961078153/ without any authentication. are you signed in to your facebook account ??

ghost commented 2 years ago

Facebook is tricky. Even if a video can be viewed without login, the login page may be returned to youtube-dl. If there's no problem at first, the login page may be returned even to browsers after repeated attempts. Or It may be related to your location or network.

For your URL, I too can download the video without login info. If I use a proxy in other countries, sometimes login page is returned, sometimes still no problem.

What users can do would be: