|
|
@ -42,19 +42,11 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|
|
|
# If True it will raise an error if no login info is provided
|
|
|
|
# If True it will raise an error if no login info is provided
|
|
|
|
_LOGIN_REQUIRED = False
|
|
|
|
_LOGIN_REQUIRED = False
|
|
|
|
|
|
|
|
|
|
|
|
def report_lang(self):
|
|
|
|
|
|
|
|
"""Report attempt to set language."""
|
|
|
|
|
|
|
|
self.to_screen(u'Setting language')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_language(self):
|
|
|
|
def _set_language(self):
|
|
|
|
request = compat_urllib_request.Request(self._LANG_URL)
|
|
|
|
return bool(self._download_webpage(
|
|
|
|
try:
|
|
|
|
self._LANG_URL, None,
|
|
|
|
self.report_lang()
|
|
|
|
note=u'Setting language', errnote='unable to set language',
|
|
|
|
self._download_webpage(self._LANG_URL, None, False)
|
|
|
|
fatal=False))
|
|
|
|
except ExtractorError as err:
|
|
|
|
|
|
|
|
self._downloader.report_warning(u'unable to set language: %s' % compat_str(err.cause))
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _login(self):
|
|
|
|
def _login(self):
|
|
|
|
(username, password) = self._get_login_info()
|
|
|
|
(username, password) = self._get_login_info()
|
|
|
@ -64,8 +56,12 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|
|
|
raise ExtractorError(u'No login info available, needed for using %s.' % self.IE_NAME, expected=True)
|
|
|
|
raise ExtractorError(u'No login info available, needed for using %s.' % self.IE_NAME, expected=True)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
login_page = self._download_webpage(self._LOGIN_URL, None, False,
|
|
|
|
login_page = self._download_webpage(
|
|
|
|
u'Unable to fetch login page')
|
|
|
|
self._LOGIN_URL, None,
|
|
|
|
|
|
|
|
note=u'Downloading login page',
|
|
|
|
|
|
|
|
errnote=u'unable to fetch login page', fatal=False)
|
|
|
|
|
|
|
|
if login_page is False:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
galx = self._search_regex(r'(?s)<input.+?name="GALX".+?value="(.+?)"',
|
|
|
|
galx = self._search_regex(r'(?s)<input.+?name="GALX".+?value="(.+?)"',
|
|
|
|
login_page, u'Login GALX parameter')
|
|
|
|
login_page, u'Login GALX parameter')
|
|
|
@ -95,26 +91,28 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|
|
|
# chokes on unicode
|
|
|
|
# chokes on unicode
|
|
|
|
login_form = dict((k.encode('utf-8'), v.encode('utf-8')) for k,v in login_form_strs.items())
|
|
|
|
login_form = dict((k.encode('utf-8'), v.encode('utf-8')) for k,v in login_form_strs.items())
|
|
|
|
login_data = compat_urllib_parse.urlencode(login_form).encode('ascii')
|
|
|
|
login_data = compat_urllib_parse.urlencode(login_form).encode('ascii')
|
|
|
|
request = compat_urllib_request.Request(self._LOGIN_URL, login_data)
|
|
|
|
|
|
|
|
try:
|
|
|
|
req = compat_urllib_request.Request(self._LOGIN_URL, login_data)
|
|
|
|
self.report_login()
|
|
|
|
login_results = self._download_webpage(
|
|
|
|
login_results = self._download_webpage(request, None, False)
|
|
|
|
req, None,
|
|
|
|
if re.search(r'(?i)<form[^>]* id="gaia_loginform"', login_results) is not None:
|
|
|
|
note=u'Logging in', errnote=u'unable to log in', fatal=False)
|
|
|
|
self._downloader.report_warning(u'unable to log in: bad username or password')
|
|
|
|
if login_results is False:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
except ExtractorError as err:
|
|
|
|
if re.search(r'(?i)<form[^>]* id="gaia_loginform"', login_results) is not None:
|
|
|
|
self._downloader.report_warning(u'unable to log in: %s' % compat_str(err.cause))
|
|
|
|
self._downloader.report_warning(u'unable to log in: bad username or password')
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def _confirm_age(self):
|
|
|
|
def _confirm_age(self):
|
|
|
|
age_form = {
|
|
|
|
age_form = {
|
|
|
|
'next_url': '/',
|
|
|
|
'next_url': '/',
|
|
|
|
'action_confirm': 'Confirm',
|
|
|
|
'action_confirm': 'Confirm',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
request = compat_urllib_request.Request(self._AGE_URL, compat_urllib_parse.urlencode(age_form))
|
|
|
|
req = compat_urllib_request.Request(self._AGE_URL, compat_urllib_parse.urlencode(age_form))
|
|
|
|
self.report_age_confirmation()
|
|
|
|
|
|
|
|
self._download_webpage(request, None, False, u'Unable to confirm age')
|
|
|
|
self._download_webpage(
|
|
|
|
|
|
|
|
req, None,
|
|
|
|
|
|
|
|
note=u'Confirming age', errnote=u'Unable to confirm age')
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def _real_initialize(self):
|
|
|
|
def _real_initialize(self):
|
|
|
@ -1736,11 +1734,14 @@ class YoutubeSearchIE(SearchInfoExtractor):
|
|
|
|
|
|
|
|
|
|
|
|
while (50 * pagenum) < limit:
|
|
|
|
while (50 * pagenum) < limit:
|
|
|
|
result_url = self._API_URL % (compat_urllib_parse.quote_plus(query), (50*pagenum)+1)
|
|
|
|
result_url = self._API_URL % (compat_urllib_parse.quote_plus(query), (50*pagenum)+1)
|
|
|
|
data = self._download_webpage(result_url, u'query "%s"' % query,
|
|
|
|
data_json = self._download_webpage(
|
|
|
|
u'Downloading page %s' % pagenum, u'Unable to download API page')
|
|
|
|
result_url, video_id=u'query "%s"' % query,
|
|
|
|
api_response = json.loads(data)['data']
|
|
|
|
note=u'Downloading page %s' % (pagenum + 1),
|
|
|
|
|
|
|
|
errnote=u'Unable to download API page')
|
|
|
|
if not 'items' in api_response:
|
|
|
|
data = json.loads(data_json)
|
|
|
|
|
|
|
|
api_response = data['data']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'items' not in api_response:
|
|
|
|
raise ExtractorError(u'[youtube] No video results')
|
|
|
|
raise ExtractorError(u'[youtube] No video results')
|
|
|
|
|
|
|
|
|
|
|
|
new_ids = list(video['id'] for video in api_response['items'])
|
|
|
|
new_ids = list(video['id'] for video in api_response['items'])
|
|
|
|