p123client 0.0.6.6__py3-none-any.whl → 0.0.6.9__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.
p123client/client.py CHANGED
@@ -374,7 +374,7 @@ class P123OpenClient:
374
374
  check_response(resp)
375
375
  self.token = resp["data"]["accessToken"]
376
376
  return resp
377
- return run_gen_step(gen_step, async_=async_)
377
+ return run_gen_step(gen_step, async_)
378
378
 
379
379
  @overload
380
380
  @staticmethod
@@ -1215,6 +1215,8 @@ class P123OpenClient:
1215
1215
  })
1216
1216
  return self.request(api, params=payload, async_=async_, **request_kwargs)
1217
1217
 
1218
+ fs_list_v2 = fs_list
1219
+
1218
1220
  @overload
1219
1221
  def fs_list_v1(
1220
1222
  self,
@@ -1261,7 +1263,7 @@ class P123OpenClient:
1261
1263
  :payload:
1262
1264
  - limit: int = 100 💡 分页大小,最多 100
1263
1265
  - orderBy: str = "file_id" 💡 排序依据
1264
-
1266
+
1265
1267
  - "file_id": 文件 id
1266
1268
  - "file_name": 文件名
1267
1269
  - "size": 文件大小
@@ -2860,7 +2862,7 @@ class P123OpenClient:
2860
2862
  "duplicate": duplicate,
2861
2863
  "slice_size": slice_size,
2862
2864
  }) from e
2863
- return run_gen_step(gen_step, async_=async_)
2865
+ return run_gen_step(gen_step, async_)
2864
2866
 
2865
2867
  @overload
2866
2868
  def share_create(
@@ -4216,7 +4218,7 @@ class P123OpenClient:
4216
4218
  "duplicate": duplicate,
4217
4219
  "slice_size": slice_size,
4218
4220
  }) from e
4219
- return run_gen_step(gen_step, async_=async_)
4221
+ return run_gen_step(gen_step, async_)
4220
4222
 
4221
4223
  @overload
4222
4224
  def user_info(
@@ -4288,6 +4290,7 @@ class P123OpenClient:
4288
4290
  fs_detail_open = fs_detail
4289
4291
  fs_info_open = fs_info
4290
4292
  fs_list_open = fs_list
4293
+ fs_list_v2_open = fs_list_v2
4291
4294
  fs_list_v1_open = fs_list_v1
4292
4295
  fs_mkdir_open = fs_mkdir
4293
4296
  fs_move_open = fs_move
@@ -4418,7 +4421,7 @@ class P123Client(P123OpenClient):
4418
4421
  check_response(resp)
4419
4422
  self.token = resp["data"]["token"]
4420
4423
  return resp
4421
- return run_gen_step(gen_step, async_=async_)
4424
+ return run_gen_step(gen_step, async_)
4422
4425
 
4423
4426
  @overload
4424
4427
  @staticmethod
@@ -4459,6 +4462,45 @@ class P123Client(P123OpenClient):
4459
4462
  request_kwargs["async_"] = async_
4460
4463
  return request(**request_kwargs)
4461
4464
 
4465
+ @overload
4466
+ @staticmethod
4467
+ def app_server_time(
4468
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
4469
+ request: None | Callable = None,
4470
+ *,
4471
+ async_: Literal[False] = False,
4472
+ **request_kwargs,
4473
+ ) -> dict:
4474
+ ...
4475
+ @overload
4476
+ @staticmethod
4477
+ def app_server_time(
4478
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
4479
+ request: None | Callable = None,
4480
+ *,
4481
+ async_: Literal[True],
4482
+ **request_kwargs,
4483
+ ) -> Coroutine[Any, Any, dict]:
4484
+ ...
4485
+ @staticmethod
4486
+ def app_server_time(
4487
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
4488
+ request: None | Callable = None,
4489
+ *,
4490
+ async_: Literal[False, True] = False,
4491
+ **request_kwargs,
4492
+ ) -> dict | Coroutine[Any, Any, dict]:
4493
+ """获取 123 网盘的服务器时间戳
4494
+
4495
+ GET https://www.123pan.com/api/get/server/time
4496
+ """
4497
+ request_kwargs["url"] = complete_url("/api/get/server/time", base_url)
4498
+ request_kwargs.setdefault("parse", default_parse)
4499
+ if request is None:
4500
+ request = get_default_request()
4501
+ request_kwargs["async_"] = async_
4502
+ return request(**request_kwargs)
4503
+
4462
4504
  @overload
4463
4505
  def download_info(
4464
4506
  self,
@@ -4551,7 +4593,7 @@ class P123Client(P123OpenClient):
4551
4593
  async_=async_,
4552
4594
  **request_kwargs,
4553
4595
  )
4554
- return run_gen_step(gen_step, async_=async_)
4596
+ return run_gen_step(gen_step, async_)
4555
4597
 
4556
4598
  @overload
4557
4599
  def download_info_batch(
@@ -4712,7 +4754,7 @@ class P123Client(P123OpenClient):
4712
4754
  )
4713
4755
  check_response(resp)
4714
4756
  return resp["data"]["downloadUrl"]
4715
- return run_gen_step(gen_step, async_=async_)
4757
+ return run_gen_step(gen_step, async_)
4716
4758
 
4717
4759
  @overload
4718
4760
  def fs_copy(
@@ -4788,7 +4830,7 @@ class P123Client(P123OpenClient):
4788
4830
  async_=async_,
4789
4831
  **request_kwargs,
4790
4832
  )
4791
- return run_gen_step(gen_step, async_=async_)
4833
+ return run_gen_step(gen_step, async_)
4792
4834
 
4793
4835
  @overload
4794
4836
  def fs_detail(
@@ -5055,7 +5097,7 @@ class P123Client(P123OpenClient):
5055
5097
  - next: int = 0 💡 下一批拉取开始的 id
5056
5098
  - orderBy: str = "file_id" 💡 排序依据
5057
5099
 
5058
- - "file_id": 文件 id
5100
+ - "file_id": 文件 id,也可以写作 "fileId"
5059
5101
  - "file_name": 文件名
5060
5102
  - "size": 文件大小
5061
5103
  - "create_at": 创建时间
@@ -5151,7 +5193,7 @@ class P123Client(P123OpenClient):
5151
5193
  - next: int = 0 💡 下一批拉取开始的 id
5152
5194
  - orderBy: str = "file_id" 💡 排序依据
5153
5195
 
5154
- - "file_id": 文件 id
5196
+ - "file_id": 文件 id,也可以写作 "fileId"
5155
5197
  - "file_name": 文件名
5156
5198
  - "size": 文件大小
5157
5199
  - "create_at": 创建时间
@@ -5160,7 +5202,7 @@ class P123Client(P123OpenClient):
5160
5202
  - ...
5161
5203
 
5162
5204
  - orderDirection: "asc" | "desc" = "asc" 💡 排序顺序
5163
- - Page: int = <default> 💡 第几页,从 1 开始,可以是 0
5205
+ - Page: int = 1 💡 第几页,从 1 开始
5164
5206
  - parentFileId: int | str = 0 💡 父目录 id
5165
5207
  - trashed: "false" | "true" = <default> 💡 是否查看回收站的文件
5166
5208
  - inDirectSpace: "false" | "true" = "false"
@@ -5171,8 +5213,13 @@ class P123Client(P123OpenClient):
5171
5213
  - "syncFileList": 同步空间
5172
5214
 
5173
5215
  - operateType: int | str = <default> 💡 操作类型,如果在同步空间,则需要指定为 "SyncSpacePage"
5216
+
5217
+ .. note::
5218
+ 这个值似乎不影响结果,所以可以忽略。我在浏览器中,看到罗列根目录为 1,搜索(指定 `SearchData`)为 2,同步空间的根目录为 3,罗列其它目录大多为 4,偶尔为 8,也可能是其它值
5219
+
5174
5220
  - SearchData: str = <default> 💡 搜索关键字(将无视 `parentFileId` 参数)
5175
- - OnlyLookAbnormalFile: int = <default>
5221
+ - OnlyLookAbnormalFile: int = 0 💡 大概可传入 0 或 1
5222
+ - RequestSource: int = <default> 💡 浏览器中,在同步空间中为 1
5176
5223
  """
5177
5224
  if isinstance(payload, (int, str)):
5178
5225
  payload = {"parentFileId": payload}
@@ -5185,6 +5232,8 @@ class P123Client(P123OpenClient):
5185
5232
  "parentFileId": 0,
5186
5233
  "inDirectSpace": "false",
5187
5234
  "event": event,
5235
+ "OnlyLookAbnormalFile": 0,
5236
+ "Page": 1,
5188
5237
  })
5189
5238
  if not payload.get("trashed"):
5190
5239
  match payload["event"]:
@@ -5322,6 +5371,50 @@ class P123Client(P123OpenClient):
5322
5371
  **request_kwargs,
5323
5372
  )
5324
5373
 
5374
+ @overload
5375
+ def fs_fresh(
5376
+ self,
5377
+ payload: dict = {},
5378
+ /,
5379
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
5380
+ *,
5381
+ async_: Literal[False] = False,
5382
+ **request_kwargs,
5383
+ ) -> dict:
5384
+ ...
5385
+ @overload
5386
+ def fs_fresh(
5387
+ self,
5388
+ payload: dict = {},
5389
+ /,
5390
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
5391
+ *,
5392
+ async_: Literal[True],
5393
+ **request_kwargs,
5394
+ ) -> Coroutine[Any, Any, dict]:
5395
+ ...
5396
+ def fs_fresh(
5397
+ self,
5398
+ payload: dict = {},
5399
+ /,
5400
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
5401
+ *,
5402
+ async_: Literal[False, True] = False,
5403
+ **request_kwargs,
5404
+ ) -> dict | Coroutine[Any, Any, dict]:
5405
+ """刷新列表和直链缓存
5406
+
5407
+ POST https://www.123pan.com/api/restful/goapi/v1/cdnLink/cache/refresh
5408
+ """
5409
+ return self.request(
5410
+ "restful/goapi/v1/cdnLink/cache/refresh",
5411
+ "POST",
5412
+ json=payload,
5413
+ base_url=base_url,
5414
+ async_=async_,
5415
+ **request_kwargs,
5416
+ )
5417
+
5325
5418
  @overload # type: ignore
5326
5419
  def fs_rename(
5327
5420
  self,
@@ -5378,6 +5471,56 @@ class P123Client(P123OpenClient):
5378
5471
  **request_kwargs,
5379
5472
  )
5380
5473
 
5474
+ @overload
5475
+ def fs_sync_log(
5476
+ self,
5477
+ payload: dict | int = 1,
5478
+ /,
5479
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
5480
+ *,
5481
+ async_: Literal[False] = False,
5482
+ **request_kwargs,
5483
+ ) -> dict:
5484
+ ...
5485
+ @overload
5486
+ def fs_sync_log(
5487
+ self,
5488
+ payload: dict | int = 1,
5489
+ /,
5490
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
5491
+ *,
5492
+ async_: Literal[True],
5493
+ **request_kwargs,
5494
+ ) -> Coroutine[Any, Any, dict]:
5495
+ ...
5496
+ def fs_sync_log(
5497
+ self,
5498
+ payload: dict | int = 1,
5499
+ /,
5500
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
5501
+ *,
5502
+ async_: Literal[False, True] = False,
5503
+ **request_kwargs,
5504
+ ) -> dict | Coroutine[Any, Any, dict]:
5505
+ """获取同步空间的操作记录
5506
+
5507
+ GET https://www.123pan.com/api/restful/goapi/v1/sync-disk/file/log
5508
+
5509
+ :payload:
5510
+ - page: int = 1 💡 第几页
5511
+ - pageSize: int = 100 💡 每页大小
5512
+ - searchData: str = <default> 💡 搜索关键字
5513
+ """
5514
+ if not isinstance(payload, dict):
5515
+ payload = {"page": payload, "pageSize": 100}
5516
+ return self.request(
5517
+ "restful/goapi/v1/sync-disk/file/log",
5518
+ params=payload,
5519
+ base_url=base_url,
5520
+ async_=async_,
5521
+ **request_kwargs,
5522
+ )
5523
+
5381
5524
  @overload # type: ignore
5382
5525
  def fs_trash(
5383
5526
  self,
@@ -5433,6 +5576,8 @@ class P123Client(P123OpenClient):
5433
5576
  - "recycleRestore": 移出回收站
5434
5577
 
5435
5578
  - operation: bool = <default>
5579
+ - operatePlace: int = <default>
5580
+ - RequestSource: int = <default>
5436
5581
  """
5437
5582
  if isinstance(payload, (int, str)):
5438
5583
  payload = {"fileTrashInfoList": [{"FileId": payload}]}
@@ -7102,7 +7247,7 @@ class P123Client(P123OpenClient):
7102
7247
  async_=async_,
7103
7248
  **request_kwargs,
7104
7249
  )
7105
- return run_gen_step(gen_step, async_=async_)
7250
+ return run_gen_step(gen_step, async_)
7106
7251
 
7107
7252
  @overload
7108
7253
  def upload_file_fast(
@@ -7263,7 +7408,56 @@ class P123Client(P123OpenClient):
7263
7408
  async_=async_,
7264
7409
  **request_kwargs,
7265
7410
  )
7266
- return run_gen_step(gen_step, async_=async_)
7411
+ return run_gen_step(gen_step, async_)
7412
+
7413
+ @overload
7414
+ def user_device_list(
7415
+ self,
7416
+ payload: dict | str = "deviceManagement",
7417
+ /,
7418
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7419
+ *,
7420
+ async_: Literal[False] = False,
7421
+ **request_kwargs,
7422
+ ) -> dict:
7423
+ ...
7424
+ @overload
7425
+ def user_device_list(
7426
+ self,
7427
+ payload: dict | str = "deviceManagement",
7428
+ /,
7429
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7430
+ *,
7431
+ async_: Literal[True],
7432
+ **request_kwargs,
7433
+ ) -> Coroutine[Any, Any, dict]:
7434
+ ...
7435
+ def user_device_list(
7436
+ self,
7437
+ payload: dict | str = "deviceManagement",
7438
+ /,
7439
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7440
+ *,
7441
+ async_: Literal[False, True] = False,
7442
+ **request_kwargs,
7443
+ ) -> dict | Coroutine[Any, Any, dict]:
7444
+ """用户设备列表
7445
+
7446
+ GET https://www.123pan.com/api/user/device_list
7447
+
7448
+ :payload:
7449
+ - event: str = "deviceManagement" 💡 事件类型,"deviceManagement" 为管理登录设备列表
7450
+ - operateType: int = <default>
7451
+ """
7452
+ if not isinstance(payload, dict):
7453
+ payload = {"event": payload}
7454
+ return self.request(
7455
+ "user/device_list",
7456
+ params=payload,
7457
+ base_url=base_url,
7458
+ async_=async_,
7459
+ **request_kwargs,
7460
+ )
7267
7461
 
7268
7462
  @overload
7269
7463
  def user_info(
@@ -7357,8 +7551,57 @@ class P123Client(P123OpenClient):
7357
7551
  request_kwargs["async_"] = async_
7358
7552
  return request(url=api, method="POST", json=payload, **request_kwargs)
7359
7553
 
7360
- # TODO: 添加扫码登录接口,以及通过扫码登录的方法
7554
+ @overload
7555
+ def user_use_history(
7556
+ self,
7557
+ payload: dict | str = "loginRecord",
7558
+ /,
7559
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7560
+ *,
7561
+ async_: Literal[False] = False,
7562
+ **request_kwargs,
7563
+ ) -> dict:
7564
+ ...
7565
+ @overload
7566
+ def user_use_history(
7567
+ self,
7568
+ payload: dict | str = "loginRecord",
7569
+ /,
7570
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7571
+ *,
7572
+ async_: Literal[True],
7573
+ **request_kwargs,
7574
+ ) -> Coroutine[Any, Any, dict]:
7575
+ ...
7576
+ def user_use_history(
7577
+ self,
7578
+ payload: dict | str = "loginRecord",
7579
+ /,
7580
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7581
+ *,
7582
+ async_: Literal[False, True] = False,
7583
+ **request_kwargs,
7584
+ ) -> dict | Coroutine[Any, Any, dict]:
7585
+ """用户使用记录
7586
+
7587
+ GET https://www.123pan.com/api/user/use_history
7588
+
7589
+ :payload:
7590
+ - event: str = "loginRecord" 💡 事件类型,"loginRecord" 为登录记录
7591
+ """
7592
+ if not isinstance(payload, dict):
7593
+ payload = {"event": payload}
7594
+ return self.request(
7595
+ "user/use_history",
7596
+ params=payload,
7597
+ base_url=base_url,
7598
+ async_=async_,
7599
+ **request_kwargs,
7600
+ )
7601
+
7602
+ # TODO: 添加扫码登录接口,以及通过扫码登录的方法,特别是用已登录的设备扫描一个新的 token 出来
7361
7603
  # TODO: 添加 同步空间 和 直链空间 的操作接口
7362
7604
  # TODO: 添加 图床 的操作接口
7363
7605
  # TODO: 添加 视频转码 的操作接口
7364
7606
  # TODO: 对于某些工具的接口封装,例如 重复文件清理
7607
+ # TODO: 开放接口有更新了,从此开始 https://123yunpan.yuque.com/org-wiki-123yunpan-muaork/cr6ced/xogi45g7okqk7svr
@@ -6,14 +6,14 @@ __all__ = ["make_uri", "upload_uri", "get_downurl", "iterdir", "share_iterdir"]
6
6
 
7
7
  from asyncio import sleep as async_sleep
8
8
  from collections import deque
9
- from collections.abc import AsyncIterator, Callable, Coroutine, Iterator
9
+ from collections.abc import AsyncIterator, Callable, Coroutine, Iterable, Iterator, Mapping
10
10
  from errno import EISDIR, ENOENT
11
11
  from functools import partial
12
12
  from itertools import count
13
13
  from time import sleep, time
14
14
  from typing import Literal
15
15
  from typing import overload, Any, Literal
16
- from urllib.parse import unquote
16
+ from urllib.parse import unquote, urlsplit
17
17
 
18
18
  from encode_uri import encode_uri_component_loose
19
19
  from iterutils import run_gen_step, run_gen_step_iter, Yield
@@ -73,7 +73,7 @@ def make_uri(
73
73
  size = info["Size"]
74
74
  s3_key_flag = info["S3KeyFlag"]
75
75
  return f"123://{name}|{size}|{md5}?{s3_key_flag}"
76
- return run_gen_step(gen_step, async_=async_)
76
+ return run_gen_step(gen_step, async_)
77
77
 
78
78
 
79
79
  @overload
@@ -213,9 +213,12 @@ def get_downurl(
213
213
  resp = yield client.download_info(payload, async_=async_, **request_kwargs)
214
214
  check_response(resp)
215
215
  return resp["data"]["DownloadUrl"]
216
- return run_gen_step(gen_step, async_=async_)
216
+ return run_gen_step(gen_step, async_)
217
217
 
218
218
 
219
+ # TODO: _iterdir 支持广度优先遍历
220
+ # TODO: 失败时,报错信息支持返回已经成功和未成功的列表,并且形式上也要利于断点重试
221
+ # TODO: 支持传入其它自定义的查询参数
219
222
  @overload
220
223
  def _iterdir(
221
224
  fs_files: Callable,
@@ -224,7 +227,9 @@ def _iterdir(
224
227
  min_depth: int = 1,
225
228
  max_depth: int = 1,
226
229
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
227
- interval: int | float = 0,
230
+ cooldown: int | float = 0,
231
+ base_url: None | str | Callable[[], str] = None,
232
+ extra_data: None | Mapping | Iterable[tuple[str, Any]] = None,
228
233
  *,
229
234
  async_: Literal[False] = False,
230
235
  **request_kwargs,
@@ -238,7 +243,9 @@ def _iterdir(
238
243
  min_depth: int = 1,
239
244
  max_depth: int = 1,
240
245
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
241
- interval: int | float = 0,
246
+ cooldown: int | float = 0,
247
+ base_url: None | str | Callable[[], str] = None,
248
+ extra_data: None | Mapping | Iterable[tuple[str, Any]] = None,
242
249
  *,
243
250
  async_: Literal[True],
244
251
  **request_kwargs,
@@ -251,7 +258,9 @@ def _iterdir(
251
258
  min_depth: int = 1,
252
259
  max_depth: int = 1,
253
260
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
254
- interval: int | float = 0,
261
+ cooldown: int | float = 0,
262
+ base_url: None | str | Callable[[], str] = None,
263
+ extra_data: None | Mapping | Iterable[tuple[str, Any]] = None,
255
264
  *,
256
265
  async_: Literal[False, True] = False,
257
266
  **request_kwargs,
@@ -270,7 +279,9 @@ def _iterdir(
270
279
  - 如果返回值是 False,则跳过此节点(但依然会继续处理位于此节点之下的节点)
271
280
  - 如果返回值是 True,则输出此节点
272
281
 
273
- :param interval: 两次调用之间,休息的时间
282
+ :param cooldown: 两次调用之间,冷却的时间(用两次调用开始时的时间差,而不是一次完成到下一次开始的时间差)
283
+ :param base_url: 基地址,如果为空,则用默认
284
+ :param extra_data: 附加数据
274
285
  :param async_: 是否异步
275
286
  :param request_kwargs: 其它请求参数
276
287
 
@@ -278,6 +289,8 @@ def _iterdir(
278
289
  """
279
290
  default_payload = payload
280
291
  page_size = int(payload.setdefault("limit", 100))
292
+ if base_url:
293
+ request_kwargs["base_url"] = base_url
281
294
  def gen_step():
282
295
  nonlocal parent_id
283
296
  dq: deque[tuple[int, int, str]] = deque()
@@ -290,13 +303,13 @@ def _iterdir(
290
303
  payload = {**default_payload, "parentFileId": parent_id}
291
304
  for i in count(1):
292
305
  payload["Page"] = i
293
- if last_ts and interval > 0 and (remains := last_ts + interval - time()) > 0:
306
+ if last_ts and cooldown > 0 and (remains := last_ts + cooldown - time()) > 0:
294
307
  if async_:
295
308
  yield async_sleep(remains)
296
309
  else:
297
310
  sleep(remains)
298
311
  resp = yield fs_files(payload, async_=async_, **request_kwargs)
299
- if interval > 0:
312
+ if cooldown > 0:
300
313
  last_ts = time()
301
314
  check_response(resp)
302
315
  info_list = resp["data"]["InfoList"]
@@ -320,6 +333,8 @@ def _iterdir(
320
333
  continue
321
334
  elif pred:
322
335
  if depth >= min_depth:
336
+ if extra_data:
337
+ info = dict(extra_data, **info)
323
338
  yield Yield(info)
324
339
  if pred is 1:
325
340
  continue
@@ -333,7 +348,7 @@ def _iterdir(
333
348
  break
334
349
  if next_id := resp["data"]["Next"]:
335
350
  payload["next"] = next_id
336
- return run_gen_step_iter(gen_step, async_=async_)
351
+ return run_gen_step_iter(gen_step, async_)
337
352
 
338
353
 
339
354
  @overload
@@ -343,7 +358,8 @@ def iterdir(
343
358
  min_depth: int = 1,
344
359
  max_depth: int = 1,
345
360
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
346
- interval: int | float = 0,
361
+ cooldown: int | float = 0,
362
+ base_url: None | str | Callable[[], str] = None,
347
363
  use_list_new: bool = False,
348
364
  *,
349
365
  async_: Literal[False] = False,
@@ -357,7 +373,8 @@ def iterdir(
357
373
  min_depth: int = 1,
358
374
  max_depth: int = 1,
359
375
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
360
- interval: int | float = 0,
376
+ cooldown: int | float = 0,
377
+ base_url: None | str | Callable[[], str] = None,
361
378
  use_list_new: bool = False,
362
379
  *,
363
380
  async_: Literal[True],
@@ -370,7 +387,8 @@ def iterdir(
370
387
  min_depth: int = 1,
371
388
  max_depth: int = 1,
372
389
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
373
- interval: int | float = 0,
390
+ cooldown: int | float = 0,
391
+ base_url: None | str | Callable[[], str] = None,
374
392
  use_list_new: bool = False,
375
393
  *,
376
394
  async_: Literal[False, True] = False,
@@ -389,7 +407,8 @@ def iterdir(
389
407
  - 如果返回值是 False,则跳过此节点(但依然会继续处理位于此节点之下的节点)
390
408
  - 如果返回值是 True,则输出此节点
391
409
 
392
- :param interval: 两次调用之间,休息的时间
410
+ :param cooldown: 两次调用之间,冷却的时间(用两次调用开始时的时间差,而不是一次完成到下一次开始的时间差)
411
+ :param base_url: 基地址,如果为空,则用默认
393
412
  :param use_list_new: 使用 `P123Client.fs_list_new` 而不是 `P123Client.fs_list`
394
413
  :param async_: 是否异步
395
414
  :param request_kwargs: 其它请求参数
@@ -402,7 +421,8 @@ def iterdir(
402
421
  min_depth=min_depth,
403
422
  max_depth=max_depth,
404
423
  predicate=predicate,
405
- interval=interval,
424
+ cooldown=cooldown,
425
+ base_url=base_url,
406
426
  async_=async_,
407
427
  **request_kwargs,
408
428
  )
@@ -416,7 +436,8 @@ def share_iterdir(
416
436
  min_depth: int = 1,
417
437
  max_depth: int = 1,
418
438
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
419
- interval: int | float = 0,
439
+ cooldown: int | float = 0,
440
+ base_url: None | str | Callable[[], str] = None,
420
441
  *,
421
442
  async_: Literal[False] = False,
422
443
  **request_kwargs,
@@ -430,7 +451,8 @@ def share_iterdir(
430
451
  min_depth: int = 1,
431
452
  max_depth: int = 1,
432
453
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
433
- interval: int | float = 0,
454
+ cooldown: int | float = 0,
455
+ base_url: None | str | Callable[[], str] = None,
434
456
  *,
435
457
  async_: Literal[True],
436
458
  **request_kwargs,
@@ -443,15 +465,24 @@ def share_iterdir(
443
465
  min_depth: int = 1,
444
466
  max_depth: int = 1,
445
467
  predicate: None | Callable[[dict], Literal[None, 0, 1, False, True]] = None,
446
- interval: int | float = 0,
468
+ cooldown: int | float = 0,
469
+ base_url: None | str | Callable[[], str] = None,
447
470
  *,
448
471
  async_: Literal[False, True] = False,
449
472
  **request_kwargs,
450
473
  ) -> Iterator[dict] | AsyncIterator[dict]:
451
474
  """遍历分享的文件列表
452
475
 
453
- :param share_key: 分享码,在分享链接中的位置形如 "https://www.123pan.com/s/{share_key}"
454
- :param share_pwd: 密码,如果没有就不传
476
+ :param share_key: 分享码或者分享链接(可以携带提取码)
477
+
478
+ .. note::
479
+ 在分享链接中的位置形如 f"https://www.123pan.com/s/{share_key}"
480
+
481
+ 如果携带提取码,要写成 f"https://www.123pan.com/s/{share_key}?提取码:{share_pwd}"
482
+
483
+ 上面的基地址不必是 "https://www.123pan.com"
484
+
485
+ :param share_pwd: 提取码(4个文字),可以为空
455
486
  :param parent_id: 父目录 id,默认是根目录
456
487
  :param min_depth: 最小深度,小于此深度的不会输出
457
488
  :param max_depth: 最大深度,大于此深度的不会输出,如果小于 0 则无限
@@ -462,20 +493,33 @@ def share_iterdir(
462
493
  - 如果返回值是 False,则跳过此节点(但依然会继续处理位于此节点之下的节点)
463
494
  - 如果返回值是 True,则输出此节点
464
495
 
465
- :param interval: 两次调用之间,休息的时间
496
+ :param cooldown: 两次调用之间,冷却的时间(用两次调用开始时的时间差,而不是一次完成到下一次开始的时间差)
497
+ :param base_url: 基地址,如果为空,则用默认(如果 `share_key` 是分享链接,则用它的 origin)
466
498
  :param async_: 是否异步
467
499
  :param request_kwargs: 其它请求参数
468
500
 
469
501
  :return: 迭代器,产生文件或目录的信息
470
502
  """
503
+ if share_key.startswith(("http://", "https://")):
504
+ urlp = urlsplit(share_key)
505
+ if not base_url:
506
+ base_url = f"{urlp.scheme}://{urlp.netloc}"
507
+ share_key = urlp.path.rsplit("/", 1)[-1]
508
+ if not share_pwd:
509
+ share_pwd = urlp.query.rpartition(":")[-1]
510
+ if len(share_pwd) != 4:
511
+ share_pwd = ""
512
+ payload = {"ShareKey": share_key, "SharePwd": share_pwd}
471
513
  return _iterdir(
472
514
  P123Client.share_fs_list,
473
- {"ShareKey": share_key, "SharePwd": share_pwd},
515
+ payload,
474
516
  parent_id=parent_id,
475
517
  min_depth=min_depth,
476
518
  max_depth=max_depth,
477
519
  predicate=predicate,
478
- interval=interval,
520
+ cooldown=cooldown,
521
+ base_url=base_url,
522
+ extra_data=payload,
479
523
  async_=async_,
480
524
  **request_kwargs,
481
525
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p123client
3
- Version: 0.0.6.6
3
+ Version: 0.0.6.9
4
4
  Summary: Python 123 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p123client
6
6
  License: MIT
@@ -31,7 +31,7 @@ Requires-Dist: python-filewrap (>=0.2.6.1)
31
31
  Requires-Dist: python-hashtools (>=0.0.3.3)
32
32
  Requires-Dist: python-http_request (>=0.0.7)
33
33
  Requires-Dist: python-httpfile (>=0.0.5)
34
- Requires-Dist: python-iterutils (>=0.2)
34
+ Requires-Dist: python-iterutils (>=0.2.4.1)
35
35
  Requires-Dist: python-property (>=0.0.3)
36
36
  Requires-Dist: yarl
37
37
  Project-URL: Repository, https://github.com/ChenyangGao/p123client
@@ -1,12 +1,12 @@
1
1
  LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
2
  p123client/__init__.py,sha256=gfUum-q3f_XuXOk2HpArDAIxAlscZm8Fau1kiNkNFpg,214
3
- p123client/client.py,sha256=NrHeHzRb2FWHjLUw-nmrkXclYBfsozVenk5UkiW4sMo,251394
3
+ p123client/client.py,sha256=sjv9kzsiVl8hFMsaaAMGjCpsbewo3LaXqbYUpzhh5bI,258804
4
4
  p123client/const.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
5
5
  p123client/exception.py,sha256=020xGo8WQmGCJz1UzNg9oFzpEvToQcgTye0s6lkFASQ,1540
6
6
  p123client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- p123client/tool/__init__.py,sha256=aG-wkqZcOvI1p_XMInZ1QIwZJjQbdBktuZEGcp2vxvs,16475
7
+ p123client/tool/__init__.py,sha256=rZIgiXMNN21acq6OdT3ywQdPQRSmxDrifzHmhj-5E8E,18860
8
8
  p123client/type.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
9
- p123client-0.0.6.6.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
10
- p123client-0.0.6.6.dist-info/METADATA,sha256=i-yh3DNW8fDB7zhuKh2l3I7bXZycOQeey-zB_o_SkRs,8855
11
- p123client-0.0.6.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
- p123client-0.0.6.6.dist-info/RECORD,,
9
+ p123client-0.0.6.9.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
10
+ p123client-0.0.6.9.dist-info/METADATA,sha256=BGbHQeCskMwE3Lxh985P00v3W4BDi49-b-5-YRKJEHc,8859
11
+ p123client-0.0.6.9.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
+ p123client-0.0.6.9.dist-info/RECORD,,