p115client 0.0.5.6__tar.gz → 0.0.5.6.1__tar.gz

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.
Files changed (22) hide show
  1. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/PKG-INFO +34 -1
  2. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/fs_files.py +24 -15
  3. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/pyproject.toml +1 -1
  4. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/readme.md +33 -0
  5. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/LICENSE +0 -0
  6. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/__init__.py +0 -0
  7. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/_upload.py +0 -0
  8. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/client.py +0 -0
  9. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/const.py +0 -0
  10. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/exception.py +0 -0
  11. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/py.typed +0 -0
  12. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/__init__.py +0 -0
  13. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/download.py +0 -0
  14. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/edit.py +0 -0
  15. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/export_dir.py +0 -0
  16. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/iterdir.py +0 -0
  17. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/life.py +0 -0
  18. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/pool.py +0 -0
  19. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/request.py +0 -0
  20. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/upload.py +0 -0
  21. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/tool/xys.py +0 -0
  22. {p115client-0.0.5.6 → p115client-0.0.5.6.1}/p115client/type.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p115client
3
- Version: 0.0.5.6
3
+ Version: 0.0.5.6.1
4
4
  Summary: Python 115 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p115client
6
6
  License: MIT
@@ -106,6 +106,39 @@ from pathlib import Path
106
106
  client = P115Client(Path("~/115-cookies.txt").expanduser(), check_for_relogin=True)
107
107
  ```
108
108
 
109
+ 如果你有一个申请通过的开放接口的应用,则可以创建开放接口的客户端实例
110
+
111
+ 你可以直接从一个 `P115Client` 实例拿到授权(自动扫码登录并授权)
112
+
113
+ ```python
114
+ app_id = <开放接口应用的 AppID>
115
+ client_open = client.login_another_open(app_id)
116
+ ```
117
+
118
+ 也可以用一个已经授权得到的 `refresh_token` (一次性使用)
119
+
120
+ ```python
121
+ from p115client import P115OpenClient
122
+
123
+ client_open = P115OpenClient(refresh_token)
124
+ ```
125
+
126
+ 或者手动扫码登录
127
+
128
+ ```python
129
+ client_open = P115OpenClient(app_id)
130
+ ```
131
+
132
+ 所以综上,推荐的初始化代码为
133
+
134
+ ```python
135
+ from p115client import P115Client, P115OpenClient
136
+ from pathlib import Path
137
+
138
+ client = P115Client(Path("~/115-cookies.txt").expanduser(), check_for_relogin=True)
139
+ client_open = client.login_another_open(app_id)
140
+ ```
141
+
109
142
  ### 2. 接口调用
110
143
 
111
144
  所有需要直接或间接执行 HTTP 请求的接口,都有同步和异步的调用方式
@@ -19,7 +19,7 @@ from typing import cast, overload, Any, Final, Literal
19
19
  from warnings import warn
20
20
 
21
21
  from iterutils import run_gen_step, run_gen_step_iter, Yield
22
- from p115client import check_response, P115Client
22
+ from p115client import check_response, P115Client, P115OpenClient
23
23
  from p115client.client import get_status_code
24
24
  from p115client.exception import BusyOSError, DataError, P115Warning
25
25
 
@@ -42,7 +42,7 @@ def is_timeouterror(exc: BaseException, /) -> bool:
42
42
 
43
43
  @overload
44
44
  def iter_fs_files(
45
- client: str | P115Client,
45
+ client: str | P115Client | P115OpenClient,
46
46
  payload: int | str | dict = 0,
47
47
  /,
48
48
  first_page_size: int = 0,
@@ -58,7 +58,7 @@ def iter_fs_files(
58
58
  ...
59
59
  @overload
60
60
  def iter_fs_files(
61
- client: str | P115Client,
61
+ client: str | P115Client | P115OpenClient,
62
62
  payload: int | str | dict = 0,
63
63
  /,
64
64
  first_page_size: int = 0,
@@ -73,7 +73,7 @@ def iter_fs_files(
73
73
  ) -> AsyncIterator[dict]:
74
74
  ...
75
75
  def iter_fs_files(
76
- client: str | P115Client,
76
+ client: str | P115Client | P115OpenClient,
77
77
  payload: int | str | dict = 0,
78
78
  /,
79
79
  first_page_size: int = 0,
@@ -101,7 +101,7 @@ def iter_fs_files(
101
101
 
102
102
  :return: 迭代器,每次返回一次接口调用的结果
103
103
  """
104
- if not isinstance(client, P115Client):
104
+ if isinstance(client, str):
105
105
  client = P115Client(client, check_for_relogin=True)
106
106
  if page_size <= 0:
107
107
  page_size = 10_000
@@ -114,17 +114,20 @@ def iter_fs_files(
114
114
  "limit": first_page_size, "show_dir": 1, **payload,
115
115
  }
116
116
  cid = int(payload["cid"])
117
- if app in ("", "web", "desktop", "harmony"):
117
+ if isinstance(client, P115OpenClient):
118
+ request_kwargs.setdefault("base_url", get_proapi_origin)
119
+ fs_files = partial(client.fs_files, **request_kwargs)
120
+ elif app in ("", "web", "desktop", "harmony"):
118
121
  request_kwargs.setdefault("base_url", get_webapi_origin)
119
- fs_files = partial(client.fs_files, async_=async_, **request_kwargs)
122
+ fs_files = partial(client.fs_files, **request_kwargs)
120
123
  else:
121
124
  request_kwargs.setdefault("base_url", get_proapi_origin)
122
- fs_files = partial(client.fs_files_app, app=app, async_=async_, **request_kwargs)
125
+ fs_files = partial(client.fs_files_app, app=app, **request_kwargs)
123
126
  def get_files(payload: dict, /):
124
127
  nonlocal count
125
128
  while True:
126
129
  try:
127
- resp = yield fs_files(payload)
130
+ resp = yield fs_files(payload, async_=async_)
128
131
  check_response(resp)
129
132
  except DataError:
130
133
  if payload["limit"] <= 1150:
@@ -166,7 +169,7 @@ def iter_fs_files(
166
169
 
167
170
 
168
171
  def iter_fs_files_threaded(
169
- client: str | P115Client,
172
+ client: str | P115Client | P115OpenClient,
170
173
  payload: int | str | dict = 0,
171
174
  /,
172
175
  page_size: int = 7_000,
@@ -195,7 +198,7 @@ def iter_fs_files_threaded(
195
198
 
196
199
  :return: 迭代器
197
200
  """
198
- if not isinstance(client, P115Client):
201
+ if isinstance(client, str):
199
202
  client = P115Client(client, check_for_relogin=True)
200
203
  if page_size <= 0:
201
204
  page_size = 7_000
@@ -206,7 +209,10 @@ def iter_fs_files_threaded(
206
209
  "limit": page_size, "show_dir": 1, **payload,
207
210
  }
208
211
  cid = int(payload["cid"])
209
- if app in ("", "web", "desktop", "harmony"):
212
+ if isinstance(client, P115OpenClient):
213
+ request_kwargs.setdefault("base_url", get_proapi_origin)
214
+ fs_files = partial(client.fs_files, **request_kwargs)
215
+ elif app in ("", "web", "desktop", "harmony"):
210
216
  page_size = min(page_size, 1150)
211
217
  request_kwargs.setdefault("base_url", get_webapi_origin)
212
218
  fs_files = partial(client.fs_files, **request_kwargs)
@@ -280,7 +286,7 @@ def iter_fs_files_threaded(
280
286
 
281
287
 
282
288
  async def iter_fs_files_asynchronized(
283
- client: str | P115Client,
289
+ client: str | P115Client | P115OpenClient,
284
290
  payload: int | str | dict = 0,
285
291
  /,
286
292
  page_size: int = 7_000,
@@ -307,7 +313,7 @@ async def iter_fs_files_asynchronized(
307
313
 
308
314
  :return: 迭代器
309
315
  """
310
- if not isinstance(client, P115Client):
316
+ if isinstance(client, str):
311
317
  client = P115Client(client, check_for_relogin=True)
312
318
  if page_size <= 0:
313
319
  page_size = 7_000
@@ -318,7 +324,10 @@ async def iter_fs_files_asynchronized(
318
324
  "limit": page_size, "show_dir": 1, **payload,
319
325
  }
320
326
  cid = int(payload["cid"])
321
- if app in ("", "web", "desktop", "harmony"):
327
+ if isinstance(client, P115OpenClient):
328
+ request_kwargs.setdefault("base_url", get_proapi_origin)
329
+ fs_files = partial(client.fs_files, **request_kwargs)
330
+ elif app in ("", "web", "desktop", "harmony"):
322
331
  page_size = min(page_size, 1150)
323
332
  request_kwargs.setdefault("base_url", get_webapi_origin)
324
333
  fs_files = partial(client.fs_files, **request_kwargs)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "p115client"
3
- version = "0.0.5.6"
3
+ version = "0.0.5.6.1"
4
4
  description = "Python 115 webdisk client."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
@@ -54,6 +54,39 @@ from pathlib import Path
54
54
  client = P115Client(Path("~/115-cookies.txt").expanduser(), check_for_relogin=True)
55
55
  ```
56
56
 
57
+ 如果你有一个申请通过的开放接口的应用,则可以创建开放接口的客户端实例
58
+
59
+ 你可以直接从一个 `P115Client` 实例拿到授权(自动扫码登录并授权)
60
+
61
+ ```python
62
+ app_id = <开放接口应用的 AppID>
63
+ client_open = client.login_another_open(app_id)
64
+ ```
65
+
66
+ 也可以用一个已经授权得到的 `refresh_token` (一次性使用)
67
+
68
+ ```python
69
+ from p115client import P115OpenClient
70
+
71
+ client_open = P115OpenClient(refresh_token)
72
+ ```
73
+
74
+ 或者手动扫码登录
75
+
76
+ ```python
77
+ client_open = P115OpenClient(app_id)
78
+ ```
79
+
80
+ 所以综上,推荐的初始化代码为
81
+
82
+ ```python
83
+ from p115client import P115Client, P115OpenClient
84
+ from pathlib import Path
85
+
86
+ client = P115Client(Path("~/115-cookies.txt").expanduser(), check_for_relogin=True)
87
+ client_open = client.login_another_open(app_id)
88
+ ```
89
+
57
90
  ### 2. 接口调用
58
91
 
59
92
  所有需要直接或间接执行 HTTP 请求的接口,都有同步和异步的调用方式
File without changes