p123client 0.0.6.3__py3-none-any.whl → 0.0.6.5__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
@@ -40,6 +40,9 @@ from .exception import P123OSError, P123BrokenUpload
40
40
 
41
41
 
42
42
  # 默认使用的域名
43
+ # "https://www.123pan.com"
44
+ # "https://www.123pan.com/a"
45
+ # "https://www.123pan.com/b"
43
46
  DEFAULT_BASE_URL = "https://www.123pan.com/b"
44
47
  DEFAULT_LOGIN_BASE_URL = "https://login.123pan.com"
45
48
  DEFAULT_OPEN_BASE_URL = "https://open-api.123pan.com"
@@ -4531,8 +4534,7 @@ class P123Client(P123OpenClient):
4531
4534
  )
4532
4535
  resp["payload"] = payload
4533
4536
  check_response(resp)
4534
- info_list = resp["data"]["infoList"]
4535
- if not info_list:
4537
+ if not (info_list := resp["data"]["infoList"]):
4536
4538
  raise FileNotFoundError(ENOENT, resp)
4537
4539
  payload = cast(dict, info_list[0])
4538
4540
  if payload["Type"]:
@@ -4611,6 +4613,107 @@ class P123Client(P123OpenClient):
4611
4613
  **request_kwargs,
4612
4614
  )
4613
4615
 
4616
+ @overload
4617
+ def download_url(
4618
+ self,
4619
+ payload: dict | int | str,
4620
+ /,
4621
+ *,
4622
+ async_: Literal[False] = False,
4623
+ **request_kwargs,
4624
+ ) -> str:
4625
+ ...
4626
+ @overload
4627
+ def download_url(
4628
+ self,
4629
+ payload: dict | int | str,
4630
+ /,
4631
+ *,
4632
+ async_: Literal[True],
4633
+ **request_kwargs,
4634
+ ) -> Coroutine[Any, Any, str]:
4635
+ ...
4636
+ def download_url(
4637
+ self,
4638
+ payload: dict | int | str,
4639
+ /,
4640
+ *,
4641
+ async_: Literal[False, True] = False,
4642
+ **request_kwargs,
4643
+ ) -> str | Coroutine[Any, Any, str]:
4644
+ """获取下载链接
4645
+
4646
+ .. note::
4647
+ `payload` 支持多种格式的输入,按下面的规则按顺序进行判断:
4648
+
4649
+ 1. 如果是 `int` 或 `str`,则视为文件 id,必须在你的网盘中存在此文件
4650
+ 2. 如果是 `dict`(不区分大小写),有 "S3KeyFlag", "Etag" 和 "Size" 的值,则直接获取链接,文件不必在你网盘中
4651
+ 3. 如果是 `dict`(不区分大小写),有 "Etag" 和 "Size" 的值,则会先秒传(临时文件路径为 /.tempfile)再获取链接,文件不必在你网盘中
4652
+ 4. 如果是 `dict`(不区分大小写),有 "FileID",则会先获取信息,再获取链接,必须在你的网盘中存在此文件
4653
+ 5. 否则会报错 ValueError
4654
+
4655
+ :params payload: 文件 id 或者文件信息,文件信息必须包含的信息如下:
4656
+
4657
+ - FileID: int | str 💡 下载链接
4658
+ - S3KeyFlag: str 💡 存储桶名
4659
+ - Etag: str 💡 文件的 MD5 散列值
4660
+ - Size: int 💡 文件大小
4661
+ - FileName: str 💡 默认用 Etag(即 MD5)作为文件名,可以省略
4662
+
4663
+ :params async_: 是否异步
4664
+ :params request_kwargs: 其它请求参数
4665
+
4666
+ :return: 下载链接
4667
+ """
4668
+ def gen_step():
4669
+ nonlocal payload
4670
+ if isinstance(payload, dict):
4671
+ payload = dict_to_lower(payload)
4672
+ if not ("size" in payload and "etag" in payload):
4673
+ if fileid := payload.get("fileid"):
4674
+ resp = yield self.fs_info(fileid, async_=async_, **request_kwargs)
4675
+ check_response(resp)
4676
+ if not (info_list := resp["data"]["infoList"]):
4677
+ raise P123OSError(ENOENT, resp)
4678
+ info = info_list[0]
4679
+ if info["Type"]:
4680
+ raise IsADirectoryError(EISDIR, resp)
4681
+ payload = dict_to_lower_merge(payload, info)
4682
+ else:
4683
+ raise ValueError("`Size` and `Etag` must be provided")
4684
+ if "s3keyflag" not in payload:
4685
+ resp = yield self.upload_request(
4686
+ {
4687
+ "filename": ".tempfile",
4688
+ "duplicate": 2,
4689
+ "etag": payload["etag"],
4690
+ "size": payload["size"],
4691
+ "type": 0,
4692
+ },
4693
+ async_=async_,
4694
+ **request_kwargs,
4695
+ )
4696
+ check_response(resp)
4697
+ if not resp["data"]["Reuse"]:
4698
+ raise P123OSError(ENOENT, resp)
4699
+ payload["s3keyflag"] = resp["data"]["Info"]["S3KeyFlag"]
4700
+ resp = yield self.download_info(
4701
+ payload,
4702
+ async_=async_,
4703
+ **request_kwargs,
4704
+ )
4705
+ check_response(resp)
4706
+ return resp["data"]["DownloadUrl"]
4707
+ else:
4708
+ resp = yield self.download_info_open(
4709
+ payload,
4710
+ async_=async_,
4711
+ **request_kwargs,
4712
+ )
4713
+ check_response(resp)
4714
+ return resp["data"]["downloadUrl"]
4715
+ return run_gen_step(gen_step, async_=async_)
4716
+
4614
4717
  @overload
4615
4718
  def fs_copy(
4616
4719
  self,
@@ -7252,3 +7355,7 @@ class P123Client(P123OpenClient):
7252
7355
  return request(url=api, method="POST", json=payload, **request_kwargs)
7253
7356
 
7254
7357
  # TODO: 添加扫码登录接口,以及通过扫码登录的方法
7358
+ # TODO: 添加 同步空间 和 直链空间 的操作接口
7359
+ # TODO: 添加 图床 的操作接口
7360
+ # TODO: 添加 视频转码 的操作接口
7361
+ # TODO: 对于某些工具的接口封装,例如 重复文件清理
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p123client
3
- Version: 0.0.6.3
3
+ Version: 0.0.6.5
4
4
  Summary: Python 123 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p123client
6
6
  License: MIT
@@ -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=E4X5qEKnkDb17KGiy7CrhzKBkQ8ukFTFM6qxUzGsnVg,246781
3
+ p123client/client.py,sha256=zs8OeunszkdU9umC_yyPfpJL_T-4gpaMUhiKHS9Y6qU,251204
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
7
  p123client/tool/__init__.py,sha256=2k_tcc67O9QG4wzESIdnAwqNHybCGlrsnxo_uBqBhEI,16673
8
8
  p123client/type.py,sha256=T17OzPQrnIG6w_Hzjc8TF_fFMKa-hQMSn1gff8pVcBc,56
9
- p123client-0.0.6.3.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
10
- p123client-0.0.6.3.dist-info/METADATA,sha256=MgwA-g5ZGjXIchhxrFkYLPIoPeVJU96399yiIkxlBPw,8855
11
- p123client-0.0.6.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
- p123client-0.0.6.3.dist-info/RECORD,,
9
+ p123client-0.0.6.5.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
10
+ p123client-0.0.6.5.dist-info/METADATA,sha256=_uyeIOFiERlsHJ4bJGuuMbZCKb6SQaceo-dheiMAVmc,8855
11
+ p123client-0.0.6.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
+ p123client-0.0.6.5.dist-info/RECORD,,