Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c19548d

Browse files
authored
plugins.nicolive: fix login via email (#4380)
Add user input for confirmation codes
1 parent ce70388 commit c19548d

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

src/streamlink/plugins/nicolive.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import logging
99
import re
1010
from threading import Event
11+
from urllib.parse import urljoin
1112

13+
from streamlink.exceptions import FatalPluginError
1214
from streamlink.plugin import Plugin, PluginArgument, PluginArguments, PluginError, pluginmatcher
1315
from streamlink.plugin.api import useragents, validate
1416
from streamlink.plugin.api.websocket import WebsocketClient
@@ -253,19 +255,38 @@ def niconico_web_login(self):
253255

254256
elif email is not None and password is not None:
255257
log.info("Logging in via provided email and password")
256-
msg = self.session.http.post(
258+
root = self.session.http.post(
257259
self.LOGIN_URL,
258260
data={"mail_tel": email, "password": password},
259261
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()))
266286
log.debug(f"Cookies: {self.session.http.cookies.get_dict()}")
267287
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'}")
269290
else:
270291
log.info("Logged in.")
271292
self.save_cookies()

0 commit comments

Comments
 (0)