deezer-python-gql 0.17.1__py3-none-any.whl → 0.17.2__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.
- deezer_python_gql/base_client.py +35 -3
- deezer_python_gql/generated/base_client.py +35 -3
- {deezer_python_gql-0.17.1.dist-info → deezer_python_gql-0.17.2.dist-info}/METADATA +12 -5
- {deezer_python_gql-0.17.1.dist-info → deezer_python_gql-0.17.2.dist-info}/RECORD +7 -7
- {deezer_python_gql-0.17.1.dist-info → deezer_python_gql-0.17.2.dist-info}/WHEEL +1 -1
- {deezer_python_gql-0.17.1.dist-info → deezer_python_gql-0.17.2.dist-info}/licenses/LICENSE +0 -0
- {deezer_python_gql-0.17.1.dist-info → deezer_python_gql-0.17.2.dist-info}/top_level.txt +0 -0
deezer_python_gql/base_client.py
CHANGED
|
@@ -8,9 +8,13 @@ import logging
|
|
|
8
8
|
import time
|
|
9
9
|
from base64 import urlsafe_b64decode
|
|
10
10
|
from dataclasses import dataclass
|
|
11
|
-
from typing import Any, ClassVar, Self, cast
|
|
11
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Self, cast
|
|
12
12
|
|
|
13
13
|
from aiohttp import ClientSession, ClientTimeout
|
|
14
|
+
from yarl import URL
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from aiohttp import ClientResponse
|
|
14
18
|
|
|
15
19
|
logger = logging.getLogger(__name__)
|
|
16
20
|
|
|
@@ -137,6 +141,9 @@ class DeezerBaseClient:
|
|
|
137
141
|
self._arl = arl
|
|
138
142
|
self._session = session
|
|
139
143
|
self._owns_session = session is None
|
|
144
|
+
# An external session may be shared by clients for different Deezer accounts.
|
|
145
|
+
# Keep Deezer's response cookies per client instead of trusting that shared jar.
|
|
146
|
+
self._cookies: dict[str, str] = {}
|
|
140
147
|
self._jwt: str | None = None
|
|
141
148
|
self._jwt_expires_at: float = 0
|
|
142
149
|
self._jwt_lock = asyncio.Lock()
|
|
@@ -167,6 +174,21 @@ class DeezerBaseClient:
|
|
|
167
174
|
"""Exit the async context manager, closing internal resources."""
|
|
168
175
|
await self.close()
|
|
169
176
|
|
|
177
|
+
def _request_cookies(self, url: str, *, include_arl: bool = False) -> dict[str, str]:
|
|
178
|
+
"""Return account-local cookies while neutralizing a shared session's jar."""
|
|
179
|
+
session = self._get_session()
|
|
180
|
+
blanked = dict.fromkeys(session.cookie_jar.filter_cookies(URL(url)), "")
|
|
181
|
+
cookies = blanked | self._cookies
|
|
182
|
+
if include_arl:
|
|
183
|
+
cookies["arl"] = self._arl
|
|
184
|
+
return cookies
|
|
185
|
+
|
|
186
|
+
def _store_cookies(self, response: ClientResponse) -> None:
|
|
187
|
+
"""Remember response cookies for this client instead of relying on the session jar."""
|
|
188
|
+
self._cookies.update(
|
|
189
|
+
{name: morsel.value for name, morsel in response.cookies.items() if name != "arl"}
|
|
190
|
+
)
|
|
191
|
+
|
|
170
192
|
async def execute(
|
|
171
193
|
self,
|
|
172
194
|
query: str,
|
|
@@ -189,6 +211,8 @@ class DeezerBaseClient:
|
|
|
189
211
|
headers["Authorization"] = f"Bearer {jwt}"
|
|
190
212
|
headers["Content-Type"] = "application/json"
|
|
191
213
|
kwargs.setdefault("timeout", ClientTimeout(total=self.REQUEST_TIMEOUT_SECONDS))
|
|
214
|
+
request_cookies = self._request_cookies(self.url)
|
|
215
|
+
request_cookies.update(kwargs.pop("cookies", None) or {})
|
|
192
216
|
|
|
193
217
|
payload: dict[str, Any] = {"query": query}
|
|
194
218
|
if operation_name:
|
|
@@ -203,7 +227,14 @@ class DeezerBaseClient:
|
|
|
203
227
|
}
|
|
204
228
|
|
|
205
229
|
session = self._get_session()
|
|
206
|
-
async with session.post(
|
|
230
|
+
async with session.post(
|
|
231
|
+
self.url,
|
|
232
|
+
json=payload,
|
|
233
|
+
headers=headers,
|
|
234
|
+
cookies=request_cookies,
|
|
235
|
+
**kwargs,
|
|
236
|
+
) as resp:
|
|
237
|
+
self._store_cookies(resp)
|
|
207
238
|
body = await resp.read()
|
|
208
239
|
gql_response = GQLResponse(
|
|
209
240
|
status=resp.status,
|
|
@@ -321,9 +352,10 @@ class DeezerBaseClient:
|
|
|
321
352
|
async with session.post(
|
|
322
353
|
self.AUTH_URL,
|
|
323
354
|
params=params,
|
|
324
|
-
cookies=
|
|
355
|
+
cookies=self._request_cookies(self.AUTH_URL, include_arl=True),
|
|
325
356
|
timeout=ClientTimeout(total=10),
|
|
326
357
|
) as resp:
|
|
358
|
+
self._store_cookies(resp)
|
|
327
359
|
status = resp.status
|
|
328
360
|
is_success = resp.ok
|
|
329
361
|
# Response body is text/plain containing JSON
|
|
@@ -10,9 +10,13 @@ import logging
|
|
|
10
10
|
import time
|
|
11
11
|
from base64 import urlsafe_b64decode
|
|
12
12
|
from dataclasses import dataclass
|
|
13
|
-
from typing import Any, ClassVar, Self, cast
|
|
13
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Self, cast
|
|
14
14
|
|
|
15
15
|
from aiohttp import ClientSession, ClientTimeout
|
|
16
|
+
from yarl import URL
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from aiohttp import ClientResponse
|
|
16
20
|
|
|
17
21
|
logger = logging.getLogger(__name__)
|
|
18
22
|
|
|
@@ -139,6 +143,9 @@ class DeezerBaseClient:
|
|
|
139
143
|
self._arl = arl
|
|
140
144
|
self._session = session
|
|
141
145
|
self._owns_session = session is None
|
|
146
|
+
# An external session may be shared by clients for different Deezer accounts.
|
|
147
|
+
# Keep Deezer's response cookies per client instead of trusting that shared jar.
|
|
148
|
+
self._cookies: dict[str, str] = {}
|
|
142
149
|
self._jwt: str | None = None
|
|
143
150
|
self._jwt_expires_at: float = 0
|
|
144
151
|
self._jwt_lock = asyncio.Lock()
|
|
@@ -169,6 +176,21 @@ class DeezerBaseClient:
|
|
|
169
176
|
"""Exit the async context manager, closing internal resources."""
|
|
170
177
|
await self.close()
|
|
171
178
|
|
|
179
|
+
def _request_cookies(self, url: str, *, include_arl: bool = False) -> dict[str, str]:
|
|
180
|
+
"""Return account-local cookies while neutralizing a shared session's jar."""
|
|
181
|
+
session = self._get_session()
|
|
182
|
+
blanked = dict.fromkeys(session.cookie_jar.filter_cookies(URL(url)), "")
|
|
183
|
+
cookies = blanked | self._cookies
|
|
184
|
+
if include_arl:
|
|
185
|
+
cookies["arl"] = self._arl
|
|
186
|
+
return cookies
|
|
187
|
+
|
|
188
|
+
def _store_cookies(self, response: ClientResponse) -> None:
|
|
189
|
+
"""Remember response cookies for this client instead of relying on the session jar."""
|
|
190
|
+
self._cookies.update(
|
|
191
|
+
{name: morsel.value for name, morsel in response.cookies.items() if name != "arl"}
|
|
192
|
+
)
|
|
193
|
+
|
|
172
194
|
async def execute(
|
|
173
195
|
self,
|
|
174
196
|
query: str,
|
|
@@ -191,6 +213,8 @@ class DeezerBaseClient:
|
|
|
191
213
|
headers["Authorization"] = f"Bearer {jwt}"
|
|
192
214
|
headers["Content-Type"] = "application/json"
|
|
193
215
|
kwargs.setdefault("timeout", ClientTimeout(total=self.REQUEST_TIMEOUT_SECONDS))
|
|
216
|
+
request_cookies = self._request_cookies(self.url)
|
|
217
|
+
request_cookies.update(kwargs.pop("cookies", None) or {})
|
|
194
218
|
|
|
195
219
|
payload: dict[str, Any] = {"query": query}
|
|
196
220
|
if operation_name:
|
|
@@ -205,7 +229,14 @@ class DeezerBaseClient:
|
|
|
205
229
|
}
|
|
206
230
|
|
|
207
231
|
session = self._get_session()
|
|
208
|
-
async with session.post(
|
|
232
|
+
async with session.post(
|
|
233
|
+
self.url,
|
|
234
|
+
json=payload,
|
|
235
|
+
headers=headers,
|
|
236
|
+
cookies=request_cookies,
|
|
237
|
+
**kwargs,
|
|
238
|
+
) as resp:
|
|
239
|
+
self._store_cookies(resp)
|
|
209
240
|
body = await resp.read()
|
|
210
241
|
gql_response = GQLResponse(
|
|
211
242
|
status=resp.status,
|
|
@@ -323,9 +354,10 @@ class DeezerBaseClient:
|
|
|
323
354
|
async with session.post(
|
|
324
355
|
self.AUTH_URL,
|
|
325
356
|
params=params,
|
|
326
|
-
cookies=
|
|
357
|
+
cookies=self._request_cookies(self.AUTH_URL, include_arl=True),
|
|
327
358
|
timeout=ClientTimeout(total=10),
|
|
328
359
|
) as resp:
|
|
360
|
+
self._store_cookies(resp)
|
|
329
361
|
status = resp.status
|
|
330
362
|
is_success = resp.ok
|
|
331
363
|
# Response body is text/plain containing JSON
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deezer-python-gql
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.2
|
|
4
4
|
Summary: Async typed Python client for Deezer's Pipe GraphQL API.
|
|
5
5
|
Author-email: Julian Daberkow <jdaberkow@users.noreply.github.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -13,15 +13,16 @@ Description-Content-Type: text/markdown
|
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: aiohttp>=3.13.5
|
|
15
15
|
Requires-Dist: pydantic>=2.0.0
|
|
16
|
+
Requires-Dist: yarl>=1.22.0
|
|
16
17
|
Provides-Extra: test
|
|
17
|
-
Requires-Dist: codespell==2.4.
|
|
18
|
-
Requires-Dist: mypy==2.1
|
|
19
|
-
Requires-Dist: pre-commit==4.6.
|
|
18
|
+
Requires-Dist: codespell==2.4.3; extra == "test"
|
|
19
|
+
Requires-Dist: mypy==2.3.1; extra == "test"
|
|
20
|
+
Requires-Dist: pre-commit==4.6.2; extra == "test"
|
|
20
21
|
Requires-Dist: pre-commit-hooks==6.0.0; extra == "test"
|
|
21
22
|
Requires-Dist: pytest==9.1.1; extra == "test"
|
|
22
23
|
Requires-Dist: pytest-asyncio==1.4.0; extra == "test"
|
|
23
24
|
Requires-Dist: pytest-cov==7.1.0; extra == "test"
|
|
24
|
-
Requires-Dist: ruff==0.
|
|
25
|
+
Requires-Dist: ruff==0.16.5; extra == "test"
|
|
25
26
|
Provides-Extra: dev
|
|
26
27
|
Requires-Dist: ariadne-codegen[subscriptions]; extra == "dev"
|
|
27
28
|
Dynamic: license-file
|
|
@@ -47,6 +48,7 @@ import asyncio
|
|
|
47
48
|
|
|
48
49
|
from deezer_python_gql import DeezerGQLClient
|
|
49
50
|
|
|
51
|
+
|
|
50
52
|
async def main():
|
|
51
53
|
client = DeezerGQLClient(arl="YOUR_ARL_COOKIE")
|
|
52
54
|
|
|
@@ -74,6 +76,7 @@ async def main():
|
|
|
74
76
|
results = await client.search(query="Daft Punk")
|
|
75
77
|
print(len(results.tracks.edges), "tracks found")
|
|
76
78
|
|
|
79
|
+
|
|
77
80
|
asyncio.run(main())
|
|
78
81
|
```
|
|
79
82
|
|
|
@@ -252,6 +255,10 @@ The Pipe API uses short-lived JWTs obtained from an ARL cookie. The base client
|
|
|
252
255
|
handles token acquisition and refresh automatically — you only need to supply a
|
|
253
256
|
valid ARL value.
|
|
254
257
|
|
|
258
|
+
An external `aiohttp.ClientSession` may be shared by clients for different Deezer
|
|
259
|
+
accounts. Each client keeps Deezer's response cookies locally and masks cookies from
|
|
260
|
+
the shared session jar, so authentication state cannot cross between those accounts.
|
|
261
|
+
|
|
255
262
|
If the ARL is rejected (bad or expired), the client raises
|
|
256
263
|
`GraphQLClientAuthError` — catch it to prompt for a new ARL instead of retrying.
|
|
257
264
|
Transient server errors raise `GraphQLClientHttpError` instead.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
deezer_python_gql/__init__.py,sha256=kwp838G6q8HnV_R0B0zWRBagYXt0rqfXY1IsyX8XDIo,641
|
|
2
|
-
deezer_python_gql/base_client.py,sha256=
|
|
2
|
+
deezer_python_gql/base_client.py,sha256=gQkxDs1S9rwL1xMaxivHzVtPE6SeJqlP-oBRdmjb7sc,17160
|
|
3
3
|
deezer_python_gql/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
deezer_python_gql/generated/__init__.py,sha256=j94LW-zhLB0wF4Oz8ynwhWBnqRkvs0xGRHBkYfILhVU,47886
|
|
5
5
|
deezer_python_gql/generated/add_album_to_favorite.py,sha256=hprfZkN_jIEl3N_zw962GAL_7XhW6odh_rBldgZ0brM,596
|
|
@@ -9,7 +9,7 @@ deezer_python_gql/generated/add_playlist_to_favorite.py,sha256=t-5sZc1KR6Kmxmih-
|
|
|
9
9
|
deezer_python_gql/generated/add_podcast_to_favorite.py,sha256=bMJAZVtlrsJ7xnk48mqrDzsNiCZ9u_2By0QLdhWInik,705
|
|
10
10
|
deezer_python_gql/generated/add_track_to_favorite.py,sha256=EUB2jNV5XzbsqntfS6UZwkPhEuOipn-We0PTgHStQtA,558
|
|
11
11
|
deezer_python_gql/generated/add_tracks_to_playlist.py,sha256=S_AGBUnOV_YP7zdyYpCxWIeJpBuae-r5VOH8HjDcqeM,933
|
|
12
|
-
deezer_python_gql/generated/base_client.py,sha256=
|
|
12
|
+
deezer_python_gql/generated/base_client.py,sha256=dh7AkMdv6xYqwcToC1RbD5Q-tBv54blJE_WJKIUPjPY,17192
|
|
13
13
|
deezer_python_gql/generated/base_model.py,sha256=S-phq2fzKu2Kuct1dUnbyvMPT5k7TsfqOkCf_3yZ19I,640
|
|
14
14
|
deezer_python_gql/generated/bookmark_podcast_episode.py,sha256=qYVJJscm66dOlLZkY6Kcfng9wpZCd3dWwF3DW4NpX2I,773
|
|
15
15
|
deezer_python_gql/generated/client.py,sha256=vIyXbOj-Mx_oFRCPzZwHMKPmgKr-Lklmnqm3ptK4PO4,130689
|
|
@@ -74,8 +74,8 @@ deezer_python_gql/generated/search.py,sha256=kPv15TlizBCX2bRzetB_OCiMgC34rcVcYoz
|
|
|
74
74
|
deezer_python_gql/generated/search_flows.py,sha256=0tD9TQCw0LH4khT53j_WhSl4Fip0cRH2_4lSDLzRRA4,1740
|
|
75
75
|
deezer_python_gql/generated/unbookmark_podcast_episode.py,sha256=-GjprmbpIjzyTsx9ELneKG_TAas5fsMJgFUywuGo-VM,666
|
|
76
76
|
deezer_python_gql/generated/update_playlist.py,sha256=L9w-b_8CLdsW4qwN0ZgcGuutyUhGQPRf9va1XlSwZhQ,534
|
|
77
|
-
deezer_python_gql-0.17.
|
|
78
|
-
deezer_python_gql-0.17.
|
|
79
|
-
deezer_python_gql-0.17.
|
|
80
|
-
deezer_python_gql-0.17.
|
|
81
|
-
deezer_python_gql-0.17.
|
|
77
|
+
deezer_python_gql-0.17.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
78
|
+
deezer_python_gql-0.17.2.dist-info/METADATA,sha256=a5OyLVdgdfoAtTOFYIdFf1oN_aEKqdq4ZIby82ky0Xk,14145
|
|
79
|
+
deezer_python_gql-0.17.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
80
|
+
deezer_python_gql-0.17.2.dist-info/top_level.txt,sha256=Yf7lMr1RCsfdcASo4pLoZIzA5aTa-cqzUePMX-A0QOM,18
|
|
81
|
+
deezer_python_gql-0.17.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|