aioamazondevices 3.0.2__py3-none-any.whl → 3.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aioamazondevices/__init__.py +1 -1
- aioamazondevices/api.py +29 -25
- aioamazondevices/const.py +29 -4
- {aioamazondevices-3.0.2.dist-info → aioamazondevices-3.0.3.dist-info}/METADATA +1 -1
- aioamazondevices-3.0.3.dist-info/RECORD +11 -0
- aioamazondevices-3.0.2.dist-info/RECORD +0 -11
- {aioamazondevices-3.0.2.dist-info → aioamazondevices-3.0.3.dist-info}/LICENSE +0 -0
- {aioamazondevices-3.0.2.dist-info → aioamazondevices-3.0.3.dist-info}/WHEEL +0 -0
aioamazondevices/__init__.py
CHANGED
aioamazondevices/api.py
CHANGED
@@ -18,7 +18,9 @@ import orjson
|
|
18
18
|
from aiohttp import ClientResponse, ClientSession
|
19
19
|
from babel import Locale
|
20
20
|
from bs4 import BeautifulSoup, Tag
|
21
|
-
from
|
21
|
+
from httpx import URL as HTTPX_URL
|
22
|
+
from multidict import MultiDictProxy
|
23
|
+
from yarl import URL as YARL_URL
|
22
24
|
|
23
25
|
from .const import (
|
24
26
|
_LOGGER,
|
@@ -116,7 +118,6 @@ class AmazonEchoApi:
|
|
116
118
|
self._domain = domain
|
117
119
|
self._cookies = self._build_init_cookies()
|
118
120
|
self._csrf_cookie: str | None = None
|
119
|
-
self._headers = DEFAULT_HEADERS
|
120
121
|
self._save_raw_data = save_raw_data
|
121
122
|
self._login_stored_data = login_data
|
122
123
|
self._serial = self._serial_number()
|
@@ -162,7 +163,7 @@ class AmazonEchoApi:
|
|
162
163
|
map_md_str = orjson.dumps(map_md_dict).decode("utf-8")
|
163
164
|
map_md = base64.b64encode(map_md_str.encode()).decode().rstrip("=")
|
164
165
|
|
165
|
-
return {"
|
166
|
+
return {"amzn-app-id": AMAZON_APP_ID, "frc": frc, "map-md": map_md}
|
166
167
|
|
167
168
|
def _create_code_verifier(self, length: int = 32) -> bytes:
|
168
169
|
"""Create code verifier."""
|
@@ -213,11 +214,11 @@ class AmazonEchoApi:
|
|
213
214
|
form = soup.find("form", {"name": "signIn"}) or soup.find("form")
|
214
215
|
|
215
216
|
if not isinstance(form, Tag):
|
216
|
-
raise TypeError("
|
217
|
+
raise TypeError("Unable to find form in login response")
|
217
218
|
|
218
219
|
inputs = {}
|
219
220
|
for field in form.find_all("input"):
|
220
|
-
if field.get("type"
|
221
|
+
if isinstance(field, Tag) and field.get("type", "") == "hidden":
|
221
222
|
inputs[field["name"]] = field.get("value", "")
|
222
223
|
|
223
224
|
return inputs
|
@@ -227,15 +228,22 @@ class AmazonEchoApi:
|
|
227
228
|
_LOGGER.debug("Get request data from HTML source")
|
228
229
|
form = soup.find("form", {"name": "signIn"}) or soup.find("form")
|
229
230
|
if isinstance(form, Tag):
|
230
|
-
method = form
|
231
|
-
url = form
|
231
|
+
method = form.get("method")
|
232
|
+
url = form.get("action")
|
232
233
|
if isinstance(method, str) and isinstance(url, str):
|
233
234
|
return method, url
|
234
|
-
raise TypeError("Unable to extract form data from response
|
235
|
+
raise TypeError("Unable to extract form data from response")
|
235
236
|
|
236
|
-
def _extract_code_from_url(self, url:
|
237
|
+
def _extract_code_from_url(self, url: YARL_URL | HTTPX_URL) -> str:
|
237
238
|
"""Extract the access token from url query after login."""
|
238
|
-
parsed_url =
|
239
|
+
parsed_url: dict[str, list[str]] = {}
|
240
|
+
if isinstance(url.query, bytes):
|
241
|
+
parsed_url = parse_qs(url.query.decode())
|
242
|
+
elif isinstance(url.query, MultiDictProxy):
|
243
|
+
for key, value in url.query.items():
|
244
|
+
parsed_url[key] = [value]
|
245
|
+
else:
|
246
|
+
raise TypeError(f"Unable to extract authorization code from url: {url}")
|
239
247
|
return parsed_url["openid.oa2.authorization_code"][0]
|
240
248
|
|
241
249
|
def _client_session(self) -> None:
|
@@ -281,9 +289,13 @@ class AmazonEchoApi:
|
|
281
289
|
_LOGGER.debug("Adding %s to headers", json_header)
|
282
290
|
headers.update(json_header)
|
283
291
|
|
292
|
+
_url: YARL_URL | str = url
|
293
|
+
if LIBRARY == "aiohttp":
|
294
|
+
_url = YARL_URL(url, encoded=True)
|
295
|
+
|
284
296
|
resp = await self.session.request(
|
285
297
|
method,
|
286
|
-
|
298
|
+
_url,
|
287
299
|
data=input_data if not json_data else orjson.dumps(input_data),
|
288
300
|
cookies=self._load_website_cookies(),
|
289
301
|
headers=headers,
|
@@ -325,7 +337,8 @@ class AmazonEchoApi:
|
|
325
337
|
base_filename = url
|
326
338
|
fullpath = Path(output_dir, base_filename + extension)
|
327
339
|
|
328
|
-
|
340
|
+
data: str
|
341
|
+
if isinstance(raw_data, dict):
|
329
342
|
data = orjson.dumps(raw_data, option=orjson.OPT_INDENT_2).decode("utf-8")
|
330
343
|
elif extension in [HTML_EXTENSION, BIN_EXTENSION]:
|
331
344
|
data = raw_data
|
@@ -484,22 +497,13 @@ class AmazonEchoApi:
|
|
484
497
|
url=login_url,
|
485
498
|
input_data=login_inputs,
|
486
499
|
)
|
500
|
+
_LOGGER.debug("Login response url:%s", login_resp.url)
|
487
501
|
|
488
|
-
|
489
|
-
_LOGGER.debug("Login
|
490
|
-
if b"openid.oa2.authorization_code" in login_resp.url.query:
|
491
|
-
authcode_url = login_resp.url
|
492
|
-
elif len(login_resp.history) > 0:
|
493
|
-
for history in login_resp.history:
|
494
|
-
if b"openid.oa2.authorization_code" in history.url.query:
|
495
|
-
authcode_url = history.url
|
496
|
-
break
|
497
|
-
|
498
|
-
if authcode_url is None:
|
499
|
-
raise CannotAuthenticate
|
502
|
+
authcode = self._extract_code_from_url(login_resp.url)
|
503
|
+
_LOGGER.debug("Login extracted authcode: %s", authcode)
|
500
504
|
|
501
505
|
device_login_data = {
|
502
|
-
"authorization_code":
|
506
|
+
"authorization_code": authcode,
|
503
507
|
"code_verifier": code_verifier,
|
504
508
|
"domain": self._domain,
|
505
509
|
}
|
aioamazondevices/const.py
CHANGED
@@ -42,6 +42,7 @@ DEFAULT_HEADERS = {
|
|
42
42
|
),
|
43
43
|
"Accept-Language": "en-US",
|
44
44
|
"Accept-Encoding": "gzip",
|
45
|
+
"Connection": "keep-alive",
|
45
46
|
}
|
46
47
|
CSRF_COOKIE = "csrf"
|
47
48
|
|
@@ -75,13 +76,17 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
|
|
75
76
|
"hw_version": "Gen3",
|
76
77
|
},
|
77
78
|
"A1Q6UGEXJZWJQ0": {
|
78
|
-
"model": "Fire TV Stick",
|
79
|
-
"hw_version": "
|
79
|
+
"model": "Fire TV Stick 4K",
|
80
|
+
"hw_version": "Gen2",
|
80
81
|
},
|
81
82
|
"A1RABVCI4QCIKC": {
|
82
83
|
"model": "Echo Dot",
|
83
84
|
"hw_version": "Gen3",
|
84
85
|
},
|
86
|
+
"A271DR1789MXDS": {
|
87
|
+
"model": "Fire Tablet 7",
|
88
|
+
"hw_version": "Gen12",
|
89
|
+
},
|
85
90
|
"A2DS1Q2TPDJ48U": {
|
86
91
|
"model": "Echo Dot Clock",
|
87
92
|
"hw_version": "Gen5",
|
@@ -95,8 +100,8 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
|
|
95
100
|
"hw_version": "Gen2",
|
96
101
|
},
|
97
102
|
"A2M4YX06LWP8WI": {
|
98
|
-
"model": "Fire Tablet",
|
99
|
-
"hw_version": "
|
103
|
+
"model": "Fire Tablet 7",
|
104
|
+
"hw_version": "Gen5",
|
100
105
|
},
|
101
106
|
"A2U21SRK4QGSE1": {
|
102
107
|
"model": "Echo Dot Clock",
|
@@ -106,6 +111,10 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
|
|
106
111
|
"model": "Echo Auto",
|
107
112
|
"hw_version": "Gen1",
|
108
113
|
},
|
114
|
+
"A30YDR2MK8HMRV": {
|
115
|
+
"model": "Echo Dot",
|
116
|
+
"hw_version": "Gen3",
|
117
|
+
},
|
109
118
|
"A32DDESGESSHZA": {
|
110
119
|
"model": "Echo Dot",
|
111
120
|
"hw_version": "Gen3",
|
@@ -126,6 +135,10 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
|
|
126
135
|
"model": "Echo Dot",
|
127
136
|
"hw_version": "Gen2",
|
128
137
|
},
|
138
|
+
"A3VRME03NAXFUB": {
|
139
|
+
"model": "Echo Flex",
|
140
|
+
"hw_version": "None",
|
141
|
+
},
|
129
142
|
"A4ZP7ZC4PI6TO": {
|
130
143
|
"model": "Echo Show 3",
|
131
144
|
"hw_version": "Gen1",
|
@@ -146,6 +159,18 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
|
|
146
159
|
"model": "Echo Dot",
|
147
160
|
"hw_version": "Gen1",
|
148
161
|
},
|
162
|
+
"AKPGW064GI9HE": {
|
163
|
+
"model": " Fire TV Stick 4K",
|
164
|
+
"hw_version": "Gen1",
|
165
|
+
},
|
166
|
+
"ATNLRCEBX3W4P": {
|
167
|
+
"model": "Fire Tablet HD 10",
|
168
|
+
"hw_version": "Gen11",
|
169
|
+
},
|
170
|
+
"AVU7CPPF2ZRAS": {
|
171
|
+
"model": "Fire Tablet HD 8 Plus",
|
172
|
+
"hw_version": "Gen10",
|
173
|
+
},
|
149
174
|
"G2A0V704840708AP": {
|
150
175
|
"model": "Echo Plus",
|
151
176
|
"hw_version": "Gen2",
|
@@ -0,0 +1,11 @@
|
|
1
|
+
aioamazondevices/__init__.py,sha256=nEAsrc5ZTGKGwy4iz0FCgwhpIpf4QdOR6-lw6S78AaI,276
|
2
|
+
aioamazondevices/api.py,sha256=ukafvMs2E5O43IRbukqL_uUzryFsy-PsWMqn9Yyw_Ho,29633
|
3
|
+
aioamazondevices/const.py,sha256=2CmH1FgtClknhfPLlYOMNfECoYXH683stK5wA67KiZc,4217
|
4
|
+
aioamazondevices/exceptions.py,sha256=qK_Hak9pc-lC2FPW-0i4rYIwNpEOHMmA9Rii8F2lkQo,1260
|
5
|
+
aioamazondevices/httpx.py,sha256=DyuD2HD3GGGbBq65qcjPCCxeuSkALKzDAdrUSeZcRMM,4935
|
6
|
+
aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
|
8
|
+
aioamazondevices-3.0.3.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
9
|
+
aioamazondevices-3.0.3.dist-info/METADATA,sha256=qwudvH288TF_xstQxY2vn0fSgi_KR99lw8fikgne3VA,5447
|
10
|
+
aioamazondevices-3.0.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
+
aioamazondevices-3.0.3.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
aioamazondevices/__init__.py,sha256=zjA4W3vrHIpsxi9TL3jWP28CK-ZT7v4OvuHbU5YTrb0,276
|
2
|
-
aioamazondevices/api.py,sha256=tUaSzMqsGnWU59A9M7bzBFZU5KgN_Jp2Igx4zvRga6s,29451
|
3
|
-
aioamazondevices/const.py,sha256=wdzjLvZBJsP8b0bH26t5JuCiKdjA_YzpGrKFy--u2jQ,3601
|
4
|
-
aioamazondevices/exceptions.py,sha256=qK_Hak9pc-lC2FPW-0i4rYIwNpEOHMmA9Rii8F2lkQo,1260
|
5
|
-
aioamazondevices/httpx.py,sha256=DyuD2HD3GGGbBq65qcjPCCxeuSkALKzDAdrUSeZcRMM,4935
|
6
|
-
aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
|
8
|
-
aioamazondevices-3.0.2.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
9
|
-
aioamazondevices-3.0.2.dist-info/METADATA,sha256=MohjIhW2nhJZWOLdhDuxMj5aK8Rb6BiTiH_1lburYl8,5447
|
10
|
-
aioamazondevices-3.0.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
-
aioamazondevices-3.0.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|