Raising error only if video parsing fails

This commit is contained in:
ringus1 2024-02-05 11:45:23 +01:00
parent 0a8b675da9
commit eb0cfc7420

View file

@ -445,10 +445,9 @@ def _perform_login(self, username, password):
try:
login_results = self._download_webpage(request, None,
note='Logging in', errnote='unable to fetch login page')
if "Your Request Couldn" in login_results:
raise ExtractorError('Failed to perform login request.')
if re.search(r'<form(.*)name="login"(.*)</form>', login_results) is not None:
if 'Your Request Couldn' in login_results:
self.raise_login_required('Failed to login with credentials', method='cookies')
elif 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')
@ -481,7 +480,10 @@ def _perform_login(self, username, password):
return
def _extract_from_url(self, url, video_id):
cookies = self._get_cookies(url) # Saving before making first request, as they might get discarded
cookies = self._get_cookies(url)
# user passed logged-in cookies or attempted to login
login_data = cookies.get('c_user') and cookies.get('xs')
logged_in = False
webpage = self._download_webpage(
url.replace('://m.facebook.com/', '://www.facebook.com/'), video_id)
@ -489,17 +491,17 @@ def _extract_from_url(self, url, video_id):
sjs_data = [self._parse_json(j, video_id, fatal=False) for j in re.findall(
r'data-sjs>({.*?ScheduledServerJS.*?})</script>', webpage)]
if cookies.get('c_user') and cookies.get('xs'): # user passed logged-in cookies or attempted to login:
if get_first(sjs_data, (
if login_data:
logged_in = get_first(sjs_data, (
'require', ..., ..., ..., '__bbox', 'define',
lambda _, v: 'CurrentUserInitialData' in v, ..., 'ACCOUNT_ID'), default='0') == '0':
raise ExtractorError('Failed to login with provided data.', expected=True)
if any(content in webpage for content in ['180 days left to appeal', 'suspended your account']):
raise ExtractorError('Your account is suspended', expected=True)
if 'send a code to confirm the mobile number you give us' in webpage:
raise ExtractorError('Facebook is requiring mobile number confirmation', expected=True)
if 'your account has been locked' in webpage:
raise ExtractorError('Your account has been locked', expected=True)
lambda _, v: 'CurrentUserInitialData' in v, ..., 'ACCOUNT_ID'), default='0') != '0'
if logged_in:
if any(content in webpage for content in ['180 days left to appeal', 'suspended your account']):
raise ExtractorError('Your account is suspended', expected=True)
if 'send a code to confirm the mobile number you give us' in webpage:
raise ExtractorError('Facebook is requiring mobile number confirmation', expected=True)
if 'your account has been locked' in webpage:
raise ExtractorError('Your account has been locked', expected=True)
if props := get_first(sjs_data, (
'require', ..., ..., ..., '__bbox', 'require', ..., ..., ..., 'rootView',
@ -821,6 +823,10 @@ def parse_attachment(attachment, key='media'):
video_data = extract_from_jsmods_instances(tahoe_js_data)
if not video_data:
if not login_data:
raise ExtractorError('Cannot parse data. Try logging in.', expected=True)
if not logged_in:
raise ExtractorError('Failed to login with provided data.', expected=True)
raise ExtractorError('Cannot parse data')
if len(video_data) > 1: