p123client 0.0.6.8__py3-none-any.whl → 0.0.6.9.1__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
@@ -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": 文件大小
@@ -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
@@ -5094,7 +5097,7 @@ class P123Client(P123OpenClient):
5094
5097
  - next: int = 0 💡 下一批拉取开始的 id
5095
5098
  - orderBy: str = "file_id" 💡 排序依据
5096
5099
 
5097
- - "file_id": 文件 id
5100
+ - "file_id": 文件 id,也可以写作 "fileId"
5098
5101
  - "file_name": 文件名
5099
5102
  - "size": 文件大小
5100
5103
  - "create_at": 创建时间
@@ -5190,7 +5193,7 @@ class P123Client(P123OpenClient):
5190
5193
  - next: int = 0 💡 下一批拉取开始的 id
5191
5194
  - orderBy: str = "file_id" 💡 排序依据
5192
5195
 
5193
- - "fileId": 文件 id
5196
+ - "file_id": 文件 id,也可以写作 "fileId"
5194
5197
  - "file_name": 文件名
5195
5198
  - "size": 文件大小
5196
5199
  - "create_at": 创建时间
@@ -7596,8 +7599,9 @@ class P123Client(P123OpenClient):
7596
7599
  **request_kwargs,
7597
7600
  )
7598
7601
 
7599
- # TODO: 添加扫码登录接口,以及通过扫码登录的方法
7602
+ # TODO: 添加扫码登录接口,以及通过扫码登录的方法,特别是用已登录的设备扫描一个新的 token 出来
7600
7603
  # TODO: 添加 同步空间 和 直链空间 的操作接口
7601
7604
  # TODO: 添加 图床 的操作接口
7602
7605
  # TODO: 添加 视频转码 的操作接口
7603
7606
  # TODO: 对于某些工具的接口封装,例如 重复文件清理
7607
+ # TODO: 开放接口有更新了(全部添加后,版本号可以来到 0.0.7),从此开始 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
@@ -216,6 +216,9 @@ def get_downurl(
216
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
@@ -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: 基地址,如果为空,则用默认
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.8
3
+ Version: 0.0.6.9.1
4
4
  Summary: Python 123 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p123client
6
6
  License: MIT
@@ -0,0 +1,12 @@
1
+ LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
+ p123client/__init__.py,sha256=gfUum-q3f_XuXOk2HpArDAIxAlscZm8Fau1kiNkNFpg,214
3
+ p123client/client.py,sha256=FYb3ZmYN9reFJn9g5eO0s28ckEd4zi1UxdN2HF9-CeE,258851
4
+ p123client/const.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
5
+ p123client/exception.py,sha256=020xGo8WQmGCJz1UzNg9oFzpEvToQcgTye0s6lkFASQ,1540
6
+ p123client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ p123client/tool/__init__.py,sha256=Okg3C6NNIKp1FxNzO7K40wFujYhxKWnUjD2v5jKJuas,18802
8
+ p123client/type.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
9
+ p123client-0.0.6.9.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
10
+ p123client-0.0.6.9.1.dist-info/METADATA,sha256=nJl2uZaJwSdAoKeu8L1DjHepXx35aDfI9u-x09Az3Tc,8861
11
+ p123client-0.0.6.9.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
+ p123client-0.0.6.9.1.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
- p123client/__init__.py,sha256=gfUum-q3f_XuXOk2HpArDAIxAlscZm8Fau1kiNkNFpg,214
3
- p123client/client.py,sha256=vK7kdjvd7I3iVUroiC89E1rt-HG-A1YhwECAaGr8aqk,258512
4
- p123client/const.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
5
- p123client/exception.py,sha256=020xGo8WQmGCJz1UzNg9oFzpEvToQcgTye0s6lkFASQ,1540
6
- p123client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- p123client/tool/__init__.py,sha256=MFMue0hh3czAtfTf3yInzBgcNIWVVjO-8tHrPka4TGA,16454
8
- p123client/type.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
9
- p123client-0.0.6.8.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
10
- p123client-0.0.6.8.dist-info/METADATA,sha256=kQ9PI-wnjaB8NQe1vL8J0dzlZsLqinejvRpxB615KH0,8859
11
- p123client-0.0.6.8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
- p123client-0.0.6.8.dist-info/RECORD,,