1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-25 03:32:05 +00:00

[niconico] Check login errors (#12486)

This commit is contained in:
Yen Chi Hsuan 2017-06-07 14:47:25 +08:00
parent c3c94ca4a4
commit bb13949197

View file

@ -1,23 +1,22 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
import json import json
import datetime import datetime
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_parse_qs,
compat_urlparse, compat_urlparse,
) )
from ..utils import ( from ..utils import (
determine_ext,
ExtractorError, ExtractorError,
int_or_none, int_or_none,
parse_duration, parse_duration,
parse_iso8601, parse_iso8601,
sanitized_Request,
xpath_text,
determine_ext,
urlencode_postdata, urlencode_postdata,
xpath_text,
) )
@ -101,19 +100,24 @@ class NiconicoIE(InfoExtractor):
return True return True
# Log in # Log in
login_ok = True
login_form_strs = { login_form_strs = {
'mail': username, 'mail_tel': username,
'password': password, 'password': password,
} }
login_data = urlencode_postdata(login_form_strs) urlh = self._request_webpage(
request = sanitized_Request( 'https://account.nicovideo.jp/api/v1/login', None,
'https://secure.nicovideo.jp/secure/login', login_data) note='Logging in', errnote='Unable to log in',
login_results = self._download_webpage( data=urlencode_postdata(login_form_strs))
request, None, note='Logging in', errnote='Unable to log in') if urlh is False:
if re.search(r'(?i)<h1 class="mb8p4">Log in error</h1>', login_results) is not None: login_ok = False
else:
parts = compat_urlparse.urlparse(urlh.geturl())
if compat_parse_qs(parts.query).get('message', [None])[0] == 'cant_login':
login_ok = False
if not login_ok:
self._downloader.report_warning('unable to log in: bad username or password') self._downloader.report_warning('unable to log in: bad username or password')
return False return login_ok
return True
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)