Skip to content

Commit 90fe9e4

Browse files
committed
plugins.twitch: update CI-token error handling
1 parent 1a7295b commit 90fe9e4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/streamlink/plugins/twitch.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,17 @@ def acquire(
541541
headers: Mapping[str, str],
542542
device_id: str,
543543
) -> Optional[Tuple[str, int]]:
544+
from exceptiongroup import BaseExceptionGroup, catch # noqa: PLC0415, I001
544545
from streamlink.webbrowser.cdp import CDPClient, CDPClientSession, devtools # noqa: PLC0415
545-
from streamlink.webbrowser.exceptions import WebbrowserError # noqa: PLC0415
546546

547547
url = f"https://www.twitch.tv/{channel}"
548548
js_get_integrity_token = cls.JS_INTEGRITY_TOKEN \
549549
.replace("SCRIPT_SOURCE", cls.URL_P_SCRIPT) \
550550
.replace("HEADERS", json_dumps(headers)) \
551551
.replace("DEVICE_ID", device_id)
552552
eval_timeout = session.get_option("webbrowser-timeout")
553+
# noinspection PyUnusedLocal
554+
client_integrity: Optional[str] = None
553555

554556
async def on_main(client_session: CDPClientSession, request: devtools.fetch.RequestPaused):
555557
async with client_session.alter_request(request) as cm:
@@ -563,16 +565,20 @@ async def acquire_client_integrity_token(client: CDPClient):
563565
await client_session.loaded(frame_id)
564566
return await client_session.evaluate(js_get_integrity_token, timeout=eval_timeout)
565567

566-
try:
567-
client_integrity: Optional[str] = CDPClient.launch(
568+
def handle_error(exc_grp: BaseExceptionGroup) -> None:
569+
for err in exc_grp.exceptions:
570+
log.error(f"{type(err).__name__}: {err}")
571+
572+
with catch({ # type: ignore[dict-item] # bug in exceptiongroup==1.2.0
573+
Exception: handle_error, # type: ignore[dict-item] # bug in exceptiongroup==1.2.0
574+
}):
575+
client_integrity = CDPClient.launch(
568576
session,
569577
acquire_client_integrity_token,
570578
# headless mode gets detected by Twitch, so we have to disable it regardless the user config
571579
headless=False,
572580
)
573-
except WebbrowserError as err:
574-
log.error(f"{type(err).__name__}: {err}")
575-
return None
581+
576582
if not client_integrity:
577583
return None
578584

0 commit comments

Comments
 (0)