p123client 0.0.7__tar.gz → 0.0.7.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p123client
3
- Version: 0.0.7
3
+ Version: 0.0.7.1.1
4
4
  Summary: Python 123 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p123client
6
6
  License: MIT
@@ -22,7 +22,7 @@ from os import fsdecode, fstat, isatty, PathLike
22
22
  from os.path import basename
23
23
  from pathlib import Path, PurePath
24
24
  from re import compile as re_compile, MULTILINE
25
- from string import digits, ascii_uppercase
25
+ from string import digits, hexdigits, ascii_uppercase
26
26
  from sys import _getframe
27
27
  from tempfile import TemporaryFile
28
28
  from typing import cast, overload, Any, Final, Literal, Self
@@ -1644,7 +1644,7 @@ class P123OpenClient:
1644
1644
 
1645
1645
  :payload:
1646
1646
  - businessType: int = <default> 💡 业务类型:2:转码空间
1647
- - category: int = <default> 💡 分类代码:0:未知 1:音频 2:视频 3:图片 4:音频 5:其它
1647
+ - category: int = <default> 💡 分类代码:0:未知 1:音频 2:视频 3:图片 4:音频 5:其它 6:保险箱 7:收藏夹
1648
1648
  - lastFileId: int = <default> 💡 上一页的最后一条记录的 FileID,翻页查询时需要填写
1649
1649
  - limit: int = 100 💡 分页大小,最多 100
1650
1650
  - parentFileId: int | str = 0 💡 父目录 id,根目录是 0
@@ -5810,7 +5810,7 @@ class P123Client(P123OpenClient):
5810
5810
  """执行一次自动扫码,但并不因此更新 ``self.token``
5811
5811
 
5812
5812
  .. caution::
5813
- 非会员目前只支持同时在线 3 台登录设备
5813
+ 非会员目前只支持同时在线 3 台登录设备,VIP 则支持同时在线 10 台
5814
5814
 
5815
5815
  :param platform: 用哪个设备平台扫码
5816
5816
  :param base_url: 接口的基地址
@@ -7032,6 +7032,8 @@ class P123Client(P123OpenClient):
7032
7032
  - 3: 图片
7033
7033
  - 4: 音频
7034
7034
  - 5: 其它
7035
+ - 6: 保险箱
7036
+ - 7: 收藏夹
7035
7037
 
7036
7038
  - dateGranularity: int = <default> 💡 按时间分组展示
7037
7039
 
@@ -7426,6 +7428,98 @@ class P123Client(P123OpenClient):
7426
7428
  **request_kwargs,
7427
7429
  )
7428
7430
 
7431
+ @overload
7432
+ def fs_safe_box_lock(
7433
+ self,
7434
+ /,
7435
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7436
+ *,
7437
+ async_: Literal[False] = False,
7438
+ **request_kwargs,
7439
+ ) -> dict:
7440
+ ...
7441
+ @overload
7442
+ def fs_safe_box_lock(
7443
+ self,
7444
+ /,
7445
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7446
+ *,
7447
+ async_: Literal[True],
7448
+ **request_kwargs,
7449
+ ) -> Coroutine[Any, Any, dict]:
7450
+ ...
7451
+ def fs_safe_box_lock(
7452
+ self,
7453
+ /,
7454
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7455
+ *,
7456
+ async_: Literal[False, True] = False,
7457
+ **request_kwargs,
7458
+ ) -> dict | Coroutine[Any, Any, dict]:
7459
+ """锁定保险箱
7460
+
7461
+ POST https://www.123pan.com/api/restful/goapi/v1/file/safe_box/auth/lock
7462
+ """
7463
+ return self.request(
7464
+ "restful/goapi/v1/file/safe_box/auth/lock",
7465
+ "POST",
7466
+ base_url=base_url,
7467
+ async_=async_,
7468
+ **request_kwargs,
7469
+ )
7470
+
7471
+ @overload
7472
+ def fs_safe_box_unlock(
7473
+ self,
7474
+ payload: dict | int | str,
7475
+ /,
7476
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7477
+ *,
7478
+ async_: Literal[False] = False,
7479
+ **request_kwargs,
7480
+ ) -> dict:
7481
+ ...
7482
+ @overload
7483
+ def fs_safe_box_unlock(
7484
+ self,
7485
+ payload: dict | int | str,
7486
+ /,
7487
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7488
+ *,
7489
+ async_: Literal[True],
7490
+ **request_kwargs,
7491
+ ) -> Coroutine[Any, Any, dict]:
7492
+ ...
7493
+ def fs_safe_box_unlock(
7494
+ self,
7495
+ payload: dict | int | str,
7496
+ /,
7497
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
7498
+ *,
7499
+ async_: Literal[False, True] = False,
7500
+ **request_kwargs,
7501
+ ) -> dict | Coroutine[Any, Any, dict]:
7502
+ """解锁保险箱
7503
+
7504
+ .. note::
7505
+ 保险箱的 id,可以用 ``client.user_info()`` 接口获得,字段为 "SafeBoxFileId"
7506
+
7507
+ POST https://www.123pan.com/api/restful/goapi/v1/file/safe_box/auth/unlockbox
7508
+
7509
+ :payload:
7510
+ - password: int | str 💡 6 位密码
7511
+ """
7512
+ if not isinstance(payload, dict):
7513
+ payload = {"password": payload}
7514
+ return self.request(
7515
+ "restful/goapi/v1/file/safe_box/auth/unlockbox",
7516
+ "POST",
7517
+ json=payload,
7518
+ base_url=base_url,
7519
+ async_=async_,
7520
+ **request_kwargs,
7521
+ )
7522
+
7429
7523
  @overload
7430
7524
  def fs_star(
7431
7525
  self,
@@ -8267,6 +8361,64 @@ class P123Client(P123OpenClient):
8267
8361
 
8268
8362
  ########## Offline Download API ##########
8269
8363
 
8364
+ @overload
8365
+ def offline_task_abort(
8366
+ self,
8367
+ payload: int | Iterable[int] | dict,
8368
+ /,
8369
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8370
+ *,
8371
+ async_: Literal[False] = False,
8372
+ **request_kwargs,
8373
+ ) -> dict:
8374
+ ...
8375
+ @overload
8376
+ def offline_task_abort(
8377
+ self,
8378
+ payload: int | Iterable[int] | dict,
8379
+ /,
8380
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8381
+ *,
8382
+ async_: Literal[True],
8383
+ **request_kwargs,
8384
+ ) -> Coroutine[Any, Any, dict]:
8385
+ ...
8386
+ def offline_task_abort(
8387
+ self,
8388
+ payload: int | Iterable[int] | dict,
8389
+ /,
8390
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8391
+ *,
8392
+ async_: Literal[False, True] = False,
8393
+ **request_kwargs,
8394
+ ) -> dict | Coroutine[Any, Any, dict]:
8395
+ """取消离线下载任务
8396
+
8397
+ POST https://www.123pan.com/api/offline_download/task/abort
8398
+
8399
+ :payload:
8400
+ - task_ids: list[int] 💡 任务 id 列表
8401
+ - is_abort: bool = True 💡 是否取消
8402
+ - all: bool = False 💡 是否全部
8403
+ """
8404
+ if isinstance(payload, int):
8405
+ payload = {"task_ids": [payload]}
8406
+ elif not isinstance(payload, dict):
8407
+ if not isinstance(payload, (list, tuple)):
8408
+ payload = tuple(payload)
8409
+ payload = {"task_ids": payload}
8410
+ payload = cast(dict, payload)
8411
+ payload.setdefault("is_abort", True)
8412
+ payload.setdefault("all", False)
8413
+ return self.request(
8414
+ "offline_download/task/abort",
8415
+ "POST",
8416
+ json=payload,
8417
+ base_url=base_url,
8418
+ async_=async_,
8419
+ **request_kwargs,
8420
+ )
8421
+
8270
8422
  @overload
8271
8423
  def offline_task_delete(
8272
8424
  self,
@@ -8407,7 +8559,7 @@ class P123Client(P123OpenClient):
8407
8559
  ) -> dict | Coroutine[Any, Any, dict]:
8408
8560
  """解析下载链接
8409
8561
 
8410
- POST https://www.123pan.com/api/offline_download/task/resolve
8562
+ POST https://www.123pan.com/api/v2/offline_download/task/resolve
8411
8563
 
8412
8564
  :payload:
8413
8565
  - urls: str = <default> 💡 下载链接,多个用 "\\n" 隔开(用于新建链接下载任务)
@@ -8418,7 +8570,7 @@ class P123Client(P123OpenClient):
8418
8570
  elif not isinstance(payload, dict):
8419
8571
  payload = {"urls": "\n".join(payload)}
8420
8572
  return self.request(
8421
- "offline_download/task/resolve",
8573
+ "v2/offline_download/task/resolve",
8422
8574
  "POST",
8423
8575
  json=payload,
8424
8576
  base_url=base_url,
@@ -8426,12 +8578,12 @@ class P123Client(P123OpenClient):
8426
8578
  **request_kwargs,
8427
8579
  )
8428
8580
 
8429
- # TODO: 支持接受一个 Iterable[dict | int],int 视为 id (select_file 为 [0]),dict 视为 resolve 信息
8430
8581
  @overload
8431
8582
  def offline_task_submit(
8432
8583
  self,
8433
- payload: dict,
8584
+ payload: dict | Iterable[dict],
8434
8585
  /,
8586
+ upload_dir: None | int | str = None,
8435
8587
  base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8436
8588
  *,
8437
8589
  async_: Literal[False] = False,
@@ -8441,8 +8593,9 @@ class P123Client(P123OpenClient):
8441
8593
  @overload
8442
8594
  def offline_task_submit(
8443
8595
  self,
8444
- payload: dict,
8596
+ payload: dict | Iterable[dict],
8445
8597
  /,
8598
+ upload_dir: None | int | str = None,
8446
8599
  base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8447
8600
  *,
8448
8601
  async_: Literal[True],
@@ -8451,8 +8604,9 @@ class P123Client(P123OpenClient):
8451
8604
  ...
8452
8605
  def offline_task_submit(
8453
8606
  self,
8454
- payload: dict,
8607
+ payload: dict | Iterable[dict],
8455
8608
  /,
8609
+ upload_dir: None | int | str = None,
8456
8610
  base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8457
8611
  *,
8458
8612
  async_: Literal[False, True] = False,
@@ -8460,7 +8614,19 @@ class P123Client(P123OpenClient):
8460
8614
  ) -> dict | Coroutine[Any, Any, dict]:
8461
8615
  """提交离线下载任务
8462
8616
 
8463
- POST https://www.123pan.com/api/offline_download/task/submit
8617
+ POST https://www.123pan.com/api/v2/offline_download/task/submit
8618
+
8619
+ .. note::
8620
+ 提交信息来自 ``client.offline_task_resolve()`` 接口的响应,假设响应为 ``resp``,那么
8621
+
8622
+ .. code:: python
8623
+
8624
+ payload = {
8625
+ "resource_list": [{
8626
+ "resource_id": resource["id"],
8627
+ "select_file_id": [info["id"] for info in resource["files"]],
8628
+ } for resource in resp["data"]["list"]]
8629
+ }
8464
8630
 
8465
8631
  :payload:
8466
8632
  - resource_list: list[Task] 💡 资源列表
@@ -8468,14 +8634,24 @@ class P123Client(P123OpenClient):
8468
8634
  .. code:: python
8469
8635
 
8470
8636
  File = {
8471
- "resource_id": int,
8472
- "select_file": list[int] # 如果是链接下载,则传 [0],如果BT下载,则传需要下载的文件在列表中的索引的列表
8637
+ "resource_id": int, # 资源 id
8638
+ "select_file_id": list[int], # 此资源内的文件 id
8473
8639
  }
8474
8640
 
8475
8641
  - upload_dir: int 💡 保存到目录的 id
8476
8642
  """
8643
+ if not isinstance(payload, dict):
8644
+ payload = {
8645
+ "resource_list": [{
8646
+ "resource_id": resource["id"],
8647
+ "select_file_id": [info["id"] for info in resource["files"]],
8648
+ } for resource in payload]
8649
+ }
8650
+ payload = cast(dict, payload)
8651
+ if upload_dir is not None:
8652
+ payload["upload_dir"] = upload_dir
8477
8653
  return self.request(
8478
- "offline_download/task/submit",
8654
+ "v2/offline_download/task/submit",
8479
8655
  "POST",
8480
8656
  json=payload,
8481
8657
  base_url=base_url,
@@ -8531,6 +8707,76 @@ class P123Client(P123OpenClient):
8531
8707
  **request_kwargs,
8532
8708
  )
8533
8709
 
8710
+ @overload
8711
+ def offline_add(
8712
+ self,
8713
+ /,
8714
+ url: str | Iterable[str],
8715
+ upload_dir: None | int | str = None,
8716
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8717
+ *,
8718
+ async_: Literal[False] = False,
8719
+ **request_kwargs,
8720
+ ) -> dict:
8721
+ ...
8722
+ @overload
8723
+ def offline_add(
8724
+ self,
8725
+ /,
8726
+ url: str | Iterable[str],
8727
+ upload_dir: None | int | str = None,
8728
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8729
+ *,
8730
+ async_: Literal[True],
8731
+ **request_kwargs,
8732
+ ) -> Coroutine[Any, Any, dict]:
8733
+ ...
8734
+ def offline_add(
8735
+ self,
8736
+ /,
8737
+ url: str | Iterable[str],
8738
+ upload_dir: None | int | str = None,
8739
+ base_url: str | Callable[[], str] = DEFAULT_BASE_URL,
8740
+ *,
8741
+ async_: Literal[False, True] = False,
8742
+ **request_kwargs,
8743
+ ) -> dict | Coroutine[Any, Any, dict]:
8744
+ """添加离线下载任务
8745
+
8746
+ POST https://www.123pan.com/api/offline_download/upload/seed
8747
+
8748
+ :param url: info_hash(只允许单个)、下载链接(多个用 "\n" 分隔)或者多个下载链接的迭代器
8749
+ :param upload_dir: 保存到目录的 id
8750
+ :param base_url: API 链接的基地址
8751
+ :param async_: 是否异步
8752
+ :param request_kwargs: 其它请求参数
8753
+
8754
+ :return: 接口响应信息
8755
+ """
8756
+ def gen_step():
8757
+ if isinstance(url, str):
8758
+ if len(url) == 40 and not url.strip(hexdigits):
8759
+ payload: dict = {"info_hash": url}
8760
+ else:
8761
+ payload = {"urls": url}
8762
+ else:
8763
+ payload = {"urls": "\n".join(url)}
8764
+ resp = yield self.offline_task_resolve(
8765
+ payload,
8766
+ base_url=base_url,
8767
+ async_=async_,
8768
+ **request_kwargs,
8769
+ )
8770
+ check_response(resp)
8771
+ return self.offline_task_submit(
8772
+ resp["data"]["list"],
8773
+ upload_dir,
8774
+ base_url=base_url,
8775
+ async_=async_,
8776
+ **request_kwargs,
8777
+ )
8778
+ return run_gen_step(gen_step, async_)
8779
+
8534
8780
  ########## Share API ##########
8535
8781
 
8536
8782
  @overload
@@ -10267,3 +10513,4 @@ with temp_globals():
10267
10513
  except KeyError:
10268
10514
  CLIENT_API_METHODS_MAP[api] = [name]
10269
10515
 
10516
+ # TODO: 实现 check_for_relogin 参数,当报错 401,则重新登录(如果用的是 client_id,账号密码 或 refresh_token),调用 client.login()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "p123client"
3
- version = "0.0.7"
3
+ version = "0.0.7.1.1"
4
4
  description = "Python 123 webdisk client."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
File without changes
File without changes