Add support for clock adjustment for Sec-MS-GEC token (#309)

This should help when a user might have his clock skewed by more than
5 minutes. The server allows for a bit more than ~5 minutes of skew.

Signed-off-by: rany <rany2@riseup.net>
This commit is contained in:
Rany
2024-11-11 13:03:40 +02:00
committed by GitHub
parent 16c973bec8
commit dc8ac2ea7a
7 changed files with 193 additions and 41 deletions

View File

@@ -27,8 +27,8 @@ from xml.sax.saxutils import escape
import aiohttp
import certifi
from .constants import WSS_HEADERS, WSS_URL
from .drm import generate_sec_ms_gec_token, generate_sec_ms_gec_version
from .constants import SEC_MS_GEC_VERSION, WSS_HEADERS, WSS_URL
from .drm import DRM
from .exceptions import (
NoAudioReceived,
UnexpectedResponse,
@@ -367,8 +367,8 @@ class Communicate:
trust_env=True,
timeout=self.session_timeout,
) as session, session.ws_connect(
f"{WSS_URL}&Sec-MS-GEC={generate_sec_ms_gec_token()}"
f"&Sec-MS-GEC-Version={generate_sec_ms_gec_version()}"
f"{WSS_URL}&Sec-MS-GEC={DRM.generate_sec_ms_gec()}"
f"&Sec-MS-GEC-Version={SEC_MS_GEC_VERSION}"
f"&ConnectionId={connect_id()}",
compress=15,
proxy=self.proxy,
@@ -498,8 +498,16 @@ class Communicate:
# Stream the audio and metadata from the service.
for self.state["partial_text"] in self.texts:
async for message in self.__stream():
yield message
try:
async for message in self.__stream():
yield message
except aiohttp.ClientResponseError as e:
if e.status != 403:
raise
DRM.handle_client_response_error(e)
async for message in self.__stream():
yield message
async def save(
self,