Update youtube.py

Some improvements were made to the login function.
This commit is contained in:
Josef Bohórquez 2024-06-11 23:23:06 -05:00
parent 1b599af1db
commit c85000591b

View File

@ -87,6 +87,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised. If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised.
""" """
username, password = self._get_login_info() username, password = self._get_login_info()
# No authentication to be performed # No authentication to be performed
if username is None: if username is None:
if self._LOGIN_REQUIRED and self._downloader.params.get('cookiefile') is None: if self._LOGIN_REQUIRED and self._downloader.params.get('cookiefile') is None:
@ -129,21 +130,20 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
self._downloader.report_warning(message) self._downloader.report_warning(message)
lookup_req = [ lookup_req = [
username, username, None, [], None, 'US', None, None, 2, False, True,
None, [], None, 'US', None, None, 2, False, True, [None, None, [2, 1, None, 1,
[ 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
None, None, None, [], 4], 1, [None, None, []], None, None, None, True],
[2, 1, None, 1,
'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
None, [], 4],
1, [None, None, []], None, None, None, True
],
username, username,
] ]
lookup_results = req( # --- Cambio 1: Extracción de función para mejorar la legibilidad ---
self._LOOKUP_URL, lookup_req, def perform_lookup(req):
'Looking up account info', 'Unable to look up account info') return self._download_json(
self._LOOKUP_URL, req,
'Looking up account info', 'Unable to look up account info')
lookup_results = perform_lookup(lookup_req)
if lookup_results is False: if lookup_results is False:
return False return False
@ -154,12 +154,10 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
return False return False
challenge_req = [ challenge_req = [
user_hash, user_hash, None, 1, None, [1, None, None, None, [password, None, True]],
None, 1, None, [1, None, None, None, [password, None, True]], [None, None, [2, 1, None, 1,
[ 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
None, None, [2, 1, None, 1, 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', None, [], 4], None, [], 4], 1, [None, None, []], None, None, None, True]]
1, [None, None, []], None, None, None, True
]]
challenge_results = req( challenge_results = req(
self._CHALLENGE_URL, challenge_req, self._CHALLENGE_URL, challenge_req,