p123client 0.0.6.4__tar.gz → 0.0.6.6__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.6.4
3
+ Version: 0.0.6.6
4
4
  Summary: Python 123 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p123client
6
6
  License: MIT
@@ -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"]:
@@ -4641,12 +4643,22 @@ class P123Client(P123OpenClient):
4641
4643
  ) -> str | Coroutine[Any, Any, str]:
4642
4644
  """获取下载链接
4643
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
+
4644
4655
  :params payload: 文件 id 或者文件信息,文件信息必须包含的信息如下:
4645
4656
 
4646
- - S3KeyFlag: str 💡 存储桶名
4647
- - Etag: str 💡 文件的 MD5 散列值
4648
- - Size: int 💡 文件大小
4649
- - FileName: str = <default> 💡 默认用 Etag(即 MD5)作为文件名
4657
+ - FileID: int | str 💡 下载链接
4658
+ - S3KeyFlag: str 💡 s3 存储名
4659
+ - Etag: str 💡 文件的 MD5 散列值
4660
+ - Size: int 💡 文件大小
4661
+ - FileName: str 💡 默认用 Etag(即 MD5)作为文件名,可以省略
4650
4662
 
4651
4663
  :params async_: 是否异步
4652
4664
  :params request_kwargs: 其它请求参数
@@ -4654,7 +4666,37 @@ class P123Client(P123OpenClient):
4654
4666
  :return: 下载链接
4655
4667
  """
4656
4668
  def gen_step():
4669
+ nonlocal payload
4657
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"]
4658
4700
  resp = yield self.download_info(
4659
4701
  payload,
4660
4702
  async_=async_,
@@ -7004,8 +7046,10 @@ class P123Client(P123OpenClient):
7004
7046
  if async_:
7005
7047
  async def request():
7006
7048
  chunks = bio_chunk_async_iter(file, chunksize=slice_size) # type: ignore
7007
- upload_data["partNumberStart"] = 1
7049
+ slice_no = 1
7008
7050
  async for chunk in chunks:
7051
+ upload_data["partNumberStart"] = slice_no
7052
+ upload_data["partNumberEnd"] = slice_no + 1
7009
7053
  resp = await self.upload_prepare(
7010
7054
  upload_data,
7011
7055
  base_url=base_url,
@@ -7014,17 +7058,18 @@ class P123Client(P123OpenClient):
7014
7058
  )
7015
7059
  check_response(resp)
7016
7060
  await self.request(
7017
- resp["data"]["presignedUrls"]["1"],
7061
+ resp["data"]["presignedUrls"][str(slice_no)],
7018
7062
  data=chunk,
7019
7063
  async_=True,
7020
7064
  **upload_request_kwargs,
7021
7065
  )
7022
- upload_data["partNumberStart"] += 1
7066
+ slice_no += 1
7023
7067
  yield request()
7024
7068
  else:
7025
7069
  chunks = bio_chunk_iter(file, chunksize=slice_size) # type: ignore
7026
7070
  for slice_no, chunk in enumerate(chunks, 1):
7027
7071
  upload_data["partNumberStart"] = slice_no
7072
+ upload_data["partNumberEnd"] = slice_no + 1
7028
7073
  resp = self.upload_prepare(
7029
7074
  upload_data,
7030
7075
  base_url=base_url,
@@ -7032,7 +7077,7 @@ class P123Client(P123OpenClient):
7032
7077
  )
7033
7078
  check_response(resp)
7034
7079
  self.request(
7035
- resp["data"]["presignedUrls"]["1"],
7080
+ resp["data"]["presignedUrls"][str(slice_no)],
7036
7081
  data=chunk,
7037
7082
  **upload_request_kwargs,
7038
7083
  )
@@ -7313,3 +7358,7 @@ class P123Client(P123OpenClient):
7313
7358
  return request(url=api, method="POST", json=payload, **request_kwargs)
7314
7359
 
7315
7360
  # TODO: 添加扫码登录接口,以及通过扫码登录的方法
7361
+ # TODO: 添加 同步空间 和 直链空间 的操作接口
7362
+ # TODO: 添加 图床 的操作接口
7363
+ # TODO: 添加 视频转码 的操作接口
7364
+ # TODO: 对于某些工具的接口封装,例如 重复文件清理
@@ -194,19 +194,16 @@ def get_downurl(
194
194
  size = int(size_s)
195
195
  if s3_key_flag:
196
196
  payload = {
197
- "S3KeyFlag": s3_key_flag,
198
197
  "FileName": name,
199
198
  "Etag": md5,
200
199
  "Size": size,
200
+ "S3KeyFlag": s3_key_flag,
201
201
  }
202
202
  else:
203
- resp = yield client.fs_mkdir("我的秒传", async_=async_, **request_kwargs)
204
- check_response(resp)
205
203
  resp = yield client.upload_file_fast(
204
+ file_name=".tempfile",
206
205
  file_md5=md5,
207
- file_name=f"{md5}-{size}",
208
206
  file_size=size,
209
- parent_id=resp["data"]["Info"]["FileId"],
210
207
  duplicate=2,
211
208
  async_=async_,
212
209
  **request_kwargs,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "p123client"
3
- version = "0.0.6.4"
3
+ version = "0.0.6.6"
4
4
  description = "Python 123 webdisk client."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
File without changes
File without changes