@@ -541,15 +541,17 @@ def acquire(
541
541
headers : Mapping [str , str ],
542
542
device_id : str ,
543
543
) -> Optional [Tuple [str , int ]]:
544
+ from exceptiongroup import BaseExceptionGroup , catch # noqa: PLC0415, I001
544
545
from streamlink .webbrowser .cdp import CDPClient , CDPClientSession , devtools # noqa: PLC0415
545
- from streamlink .webbrowser .exceptions import WebbrowserError # noqa: PLC0415
546
546
547
547
url = f"https://www.twitch.tv/{ channel } "
548
548
js_get_integrity_token = cls .JS_INTEGRITY_TOKEN \
549
549
.replace ("SCRIPT_SOURCE" , cls .URL_P_SCRIPT ) \
550
550
.replace ("HEADERS" , json_dumps (headers )) \
551
551
.replace ("DEVICE_ID" , device_id )
552
552
eval_timeout = session .get_option ("webbrowser-timeout" )
553
+ # noinspection PyUnusedLocal
554
+ client_integrity : Optional [str ] = None
553
555
554
556
async def on_main (client_session : CDPClientSession , request : devtools .fetch .RequestPaused ):
555
557
async with client_session .alter_request (request ) as cm :
@@ -563,16 +565,20 @@ async def acquire_client_integrity_token(client: CDPClient):
563
565
await client_session .loaded (frame_id )
564
566
return await client_session .evaluate (js_get_integrity_token , timeout = eval_timeout )
565
567
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 (
568
576
session ,
569
577
acquire_client_integrity_token ,
570
578
# headless mode gets detected by Twitch, so we have to disable it regardless the user config
571
579
headless = False ,
572
580
)
573
- except WebbrowserError as err :
574
- log .error (f"{ type (err ).__name__ } : { err } " )
575
- return None
581
+
576
582
if not client_integrity :
577
583
return None
578
584
0 commit comments