[youtube] Better message when login required

This commit is contained in:
pukkandan 2021-05-19 19:11:44 +05:30
parent 98784ef8d6
commit 9d5d4d64f8
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698
2 changed files with 24 additions and 10 deletions

View File

@ -422,6 +422,14 @@ class InfoExtractor(object):
_GEO_IP_BLOCKS = None _GEO_IP_BLOCKS = None
_WORKING = True _WORKING = True
_LOGIN_HINTS = {
'any': 'Use --cookies, --username and --password or --netrc to provide account credentials',
'cookies': (
'Use --cookies for the authentication. '
'See https://github.com/ytdl-org/youtube-dl#how-do-i-pass-cookies-to-youtube-dl for how to pass cookies'),
'password': 'Use --username and --password or --netrc to provide account credentials',
}
def __init__(self, downloader=None): def __init__(self, downloader=None):
"""Constructor. Receives an optional downloader.""" """Constructor. Receives an optional downloader."""
self._ready = False self._ready = False
@ -978,12 +986,11 @@ def report_login(self):
self.to_screen('Logging in') self.to_screen('Logging in')
def raise_login_required( def raise_login_required(
self, msg='This video is only available for registered users', metadata_available=False): self, msg='This video is only available for registered users',
metadata_available=False, method='any'):
if metadata_available and self.get_param('ignore_no_formats_error'): if metadata_available and self.get_param('ignore_no_formats_error'):
self.report_warning(msg) self.report_warning(msg)
raise ExtractorError( raise ExtractorError('%s. %s' % (msg, self._LOGIN_HINTS[method]), expected=True)
'%s. Use --cookies, --username and --password or --netrc to provide account credentials' % msg,
expected=True)
def raise_geo_restricted( def raise_geo_restricted(
self, msg='This video is not available from your location due to geo restriction', self, msg='This video is not available from your location due to geo restriction',

View File

@ -85,7 +85,20 @@ def _login(self):
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.
""" """
def warn(message):
self.report_warning(message)
# username+password login is broken
if self._LOGIN_REQUIRED and self.get_param('cookiefile') is None:
self.raise_login_required(
'Login details are needed to download this content', method='cookies')
username, password = self._get_login_info() username, password = self._get_login_info()
if username:
warn('Logging in using username and password is broken. %s' % self._LOGIN_HINTS['cookies'])
return
# Everything below this is broken!
# No authentication to be performed # No authentication to be performed
if username is None: if username is None:
if self._LOGIN_REQUIRED and self.get_param('cookiefile') is None: if self._LOGIN_REQUIRED and self.get_param('cookiefile') is None:
@ -126,9 +139,6 @@ def req(url, f_req, note, errnote):
'Google-Accounts-XSRF': 1, 'Google-Accounts-XSRF': 1,
}) })
def warn(message):
self.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,
@ -4018,9 +4028,6 @@ class YoutubeFeedsInfoExtractor(YoutubeTabIE):
def IE_NAME(self): def IE_NAME(self):
return 'youtube:%s' % self._FEED_NAME return 'youtube:%s' % self._FEED_NAME
def _real_initialize(self):
self._login()
def _real_extract(self, url): def _real_extract(self, url):
return self.url_result( return self.url_result(
'https://www.youtube.com/feed/%s' % self._FEED_NAME, 'https://www.youtube.com/feed/%s' % self._FEED_NAME,