|
8 | 8 | import logging |
9 | 9 | import re |
10 | 10 | from threading import Event |
| 11 | +from urllib.parse import urljoin |
11 | 12 |
|
| 13 | +from streamlink.exceptions import FatalPluginError |
12 | 14 | from streamlink.plugin import Plugin, PluginArgument, PluginArguments, PluginError, pluginmatcher |
13 | 15 | from streamlink.plugin.api import useragents, validate |
14 | 16 | from streamlink.plugin.api.websocket import WebsocketClient |
@@ -253,19 +255,38 @@ def niconico_web_login(self): |
253 | 255 |
|
254 | 256 | elif email is not None and password is not None: |
255 | 257 | log.info("Logging in via provided email and password") |
256 | | - msg = self.session.http.post( |
| 258 | + root = self.session.http.post( |
257 | 259 | self.LOGIN_URL, |
258 | 260 | data={"mail_tel": email, "password": password}, |
259 | 261 | params=self.LOGIN_URL_PARAMS, |
260 | | - schema=validate.Schema( |
261 | | - validate.parse_html(), |
262 | | - validate.xml_xpath_string(".//p[@class='notice__text']/text()") |
263 | | - ) |
264 | | - ) |
265 | | - |
| 262 | + schema=validate.Schema(validate.parse_html())) |
| 263 | + |
| 264 | + input_with_value = {} |
| 265 | + for elem in root.xpath(".//input"): |
| 266 | + if elem.attrib.get("value"): |
| 267 | + input_with_value[elem.attrib.get("name")] = elem.attrib.get("value") |
| 268 | + else: |
| 269 | + if elem.attrib.get("id") == "oneTimePw": |
| 270 | + maxlength = int(elem.attrib.get("maxlength")) |
| 271 | + try: |
| 272 | + oneTimePw = self.input_ask("Enter the 6 digit number included in email") |
| 273 | + if len(oneTimePw) > maxlength: |
| 274 | + log.error("invalid user input") |
| 275 | + return |
| 276 | + except FatalPluginError: |
| 277 | + return |
| 278 | + input_with_value[elem.attrib.get("name")] = oneTimePw |
| 279 | + else: |
| 280 | + log.debug(f"unknown input: {elem.attrib.get('name')}") |
| 281 | + |
| 282 | + root = self.session.http.post( |
| 283 | + urljoin("https://account.nicovideo.jp", root.xpath("string(.//form[@action]/@action)")), |
| 284 | + data=input_with_value, |
| 285 | + schema=validate.Schema(validate.parse_html())) |
266 | 286 | log.debug(f"Cookies: {self.session.http.cookies.get_dict()}") |
267 | 287 | if self.session.http.cookies.get("user_session") is None: |
268 | | - log.warning(f"Login failed: {msg or 'unknown reason'}") |
| 288 | + error = root.xpath("string(//div[@class='formError']/div/text())") |
| 289 | + log.warning(f"Login failed: {error or 'unknown reason'}") |
269 | 290 | else: |
270 | 291 | log.info("Logged in.") |
271 | 292 | self.save_cookies() |
|
0 commit comments