p123client 0.0.6.2__tar.gz → 0.0.6.4__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,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p123client
3
- Version: 0.0.6.2
3
+ Version: 0.0.6.4
4
4
  Summary: Python 123 webdisk client.
5
- Home-page: https://github.com/ChenyangGao/python-123-client
5
+ Home-page: https://github.com/ChenyangGao/p123client
6
6
  License: MIT
7
7
  Keywords: 123,webdisk,client
8
8
  Author: ChenyangGao
@@ -34,7 +34,7 @@ Requires-Dist: python-httpfile (>=0.0.5)
34
34
  Requires-Dist: python-iterutils (>=0.2)
35
35
  Requires-Dist: python-property (>=0.0.3)
36
36
  Requires-Dist: yarl
37
- Project-URL: Repository, https://github.com/ChenyangGao/python-123-client
37
+ Project-URL: Repository, https://github.com/ChenyangGao/p123client
38
38
  Description-Content-Type: text/markdown
39
39
 
40
40
  # Python 123 网盘客户端
@@ -107,6 +107,20 @@ def dict_to_lower_merge[K, V](
107
107
  return m
108
108
 
109
109
 
110
+ def update_headers_in_kwargs(
111
+ request_kwargs: dict,
112
+ /,
113
+ *args,
114
+ **kwargs,
115
+ ):
116
+ if headers := request_kwargs.get("headers"):
117
+ headers = dict(headers)
118
+ else:
119
+ headers = {}
120
+ headers.update(*args, **kwargs)
121
+ request_kwargs["headers"] = headers
122
+
123
+
110
124
  def escape_filename(
111
125
  s: str,
112
126
  /,
@@ -961,6 +975,7 @@ class P123OpenClient:
961
975
  - fileId: int 💡 文件 id
962
976
  """
963
977
  api = complete_url("/api/v1/file/download_info", base_url)
978
+ update_headers_in_kwargs(request_kwargs, platform="android")
964
979
  if not isinstance(payload, dict):
965
980
  payload = {"fileId": payload}
966
981
  return self.request(api, params=payload, async_=async_, **request_kwargs)
@@ -4506,12 +4521,7 @@ class P123Client(P123OpenClient):
4506
4521
  """
4507
4522
  def gen_step():
4508
4523
  nonlocal payload
4509
- if headers := request_kwargs.get("headers"):
4510
- headers = dict(headers)
4511
- else:
4512
- headers = {}
4513
- headers["platform"] = "android"
4514
- request_kwargs["headers"] = headers
4524
+ update_headers_in_kwargs(request_kwargs, platform="android")
4515
4525
  if not isinstance(payload, dict):
4516
4526
  resp = yield self.fs_info(
4517
4527
  payload,
@@ -4601,6 +4611,67 @@ class P123Client(P123OpenClient):
4601
4611
  **request_kwargs,
4602
4612
  )
4603
4613
 
4614
+ @overload
4615
+ def download_url(
4616
+ self,
4617
+ payload: dict | int | str,
4618
+ /,
4619
+ *,
4620
+ async_: Literal[False] = False,
4621
+ **request_kwargs,
4622
+ ) -> str:
4623
+ ...
4624
+ @overload
4625
+ def download_url(
4626
+ self,
4627
+ payload: dict | int | str,
4628
+ /,
4629
+ *,
4630
+ async_: Literal[True],
4631
+ **request_kwargs,
4632
+ ) -> Coroutine[Any, Any, str]:
4633
+ ...
4634
+ def download_url(
4635
+ self,
4636
+ payload: dict | int | str,
4637
+ /,
4638
+ *,
4639
+ async_: Literal[False, True] = False,
4640
+ **request_kwargs,
4641
+ ) -> str | Coroutine[Any, Any, str]:
4642
+ """获取下载链接
4643
+
4644
+ :params payload: 文件 id 或者文件信息,文件信息必须包含的信息如下:
4645
+
4646
+ - S3KeyFlag: str 💡 存储桶名
4647
+ - Etag: str 💡 文件的 MD5 散列值
4648
+ - Size: int 💡 文件大小
4649
+ - FileName: str = <default> 💡 默认用 Etag(即 MD5)作为文件名
4650
+
4651
+ :params async_: 是否异步
4652
+ :params request_kwargs: 其它请求参数
4653
+
4654
+ :return: 下载链接
4655
+ """
4656
+ def gen_step():
4657
+ if isinstance(payload, dict):
4658
+ resp = yield self.download_info(
4659
+ payload,
4660
+ async_=async_,
4661
+ **request_kwargs,
4662
+ )
4663
+ check_response(resp)
4664
+ return resp["data"]["DownloadUrl"]
4665
+ else:
4666
+ resp = yield self.download_info_open(
4667
+ payload,
4668
+ async_=async_,
4669
+ **request_kwargs,
4670
+ )
4671
+ check_response(resp)
4672
+ return resp["data"]["downloadUrl"]
4673
+ return run_gen_step(gen_step, async_=async_)
4674
+
4604
4675
  @overload
4605
4676
  def fs_copy(
4606
4677
  self,
@@ -5904,12 +5975,7 @@ class P123Client(P123OpenClient):
5904
5975
  payload = self
5905
5976
  self = None
5906
5977
  assert payload is not None
5907
- if headers := request_kwargs.get("headers"):
5908
- headers = dict(headers)
5909
- else:
5910
- headers = {}
5911
- headers["platform"] = "android"
5912
- request_kwargs["headers"] = headers
5978
+ update_headers_in_kwargs(request_kwargs, platform="android")
5913
5979
  api = complete_url("share/download/info", base_url)
5914
5980
  if self is None:
5915
5981
  request_kwargs.setdefault("parse", default_parse)
@@ -1,12 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "p123client"
3
- version = "0.0.6.2"
3
+ version = "0.0.6.4"
4
4
  description = "Python 123 webdisk client."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "readme.md"
8
- homepage = "https://github.com/ChenyangGao/python-123-client"
9
- repository = "https://github.com/ChenyangGao/python-123-client"
8
+ homepage = "https://github.com/ChenyangGao/p123client"
9
+ repository = "https://github.com/ChenyangGao/p123client"
10
10
  keywords = ["123", "webdisk", "client"]
11
11
  classifiers = [
12
12
  "License :: OSI Approved :: MIT License",
File without changes
File without changes