p123client 0.0.6.3__tar.gz → 0.0.6.5__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.
- {p123client-0.0.6.3 → p123client-0.0.6.5}/PKG-INFO +1 -1
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/client.py +109 -2
- {p123client-0.0.6.3 → p123client-0.0.6.5}/pyproject.toml +1 -1
- {p123client-0.0.6.3 → p123client-0.0.6.5}/LICENSE +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/__init__.py +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/const.py +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/exception.py +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/py.typed +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/tool/__init__.py +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/p123client/type.py +0 -0
- {p123client-0.0.6.3 → p123client-0.0.6.5}/readme.md +0 -0
@@ -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
|
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: 对于某些工具的接口封装,例如 重复文件清理
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|