fundrive-baidu 0.1.3__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.
- fundrive_baidu-0.1.3/PKG-INFO +23 -0
- fundrive_baidu-0.1.3/README.md +1 -0
- fundrive_baidu-0.1.3/pyproject.toml +13 -0
- fundrive_baidu-0.1.3/setup.cfg +4 -0
- fundrive_baidu-0.1.3/src/baidu/__init__.py +3 -0
- fundrive_baidu-0.1.3/src/baidu/app/__init__.py +0 -0
- fundrive_baidu-0.1.3/src/baidu/app/account.py +223 -0
- fundrive_baidu-0.1.3/src/baidu/app/app.py +1903 -0
- fundrive_baidu-0.1.3/src/baidu/commands/__init__.py +0 -0
- fundrive_baidu-0.1.3/src/baidu/commands/cat.py +31 -0
- fundrive_baidu-0.1.3/src/baidu/commands/cloud.py +118 -0
- fundrive_baidu-0.1.3/src/baidu/commands/crypto.py +25 -0
- fundrive_baidu-0.1.3/src/baidu/commands/disk_usage.py +60 -0
- fundrive_baidu-0.1.3/src/baidu/commands/display.py +443 -0
- fundrive_baidu-0.1.3/src/baidu/commands/download.py +437 -0
- fundrive_baidu-0.1.3/src/baidu/commands/env.py +16 -0
- fundrive_baidu-0.1.3/src/baidu/commands/errors.py +2 -0
- fundrive_baidu-0.1.3/src/baidu/commands/file_operators.py +41 -0
- fundrive_baidu-0.1.3/src/baidu/commands/list_files.py +222 -0
- fundrive_baidu-0.1.3/src/baidu/commands/log.py +17 -0
- fundrive_baidu-0.1.3/src/baidu/commands/play.py +289 -0
- fundrive_baidu-0.1.3/src/baidu/commands/rapid_upload.py +257 -0
- fundrive_baidu-0.1.3/src/baidu/commands/search.py +33 -0
- fundrive_baidu-0.1.3/src/baidu/commands/server.py +235 -0
- fundrive_baidu-0.1.3/src/baidu/commands/share.py +217 -0
- fundrive_baidu-0.1.3/src/baidu/commands/sifter.py +107 -0
- fundrive_baidu-0.1.3/src/baidu/commands/sync.py +131 -0
- fundrive_baidu-0.1.3/src/baidu/commands/upload.py +849 -0
- fundrive_baidu-0.1.3/src/baidu/commands/user.py +7 -0
- fundrive_baidu-0.1.3/src/baidu/common/cache.py +52 -0
- fundrive_baidu-0.1.3/src/baidu/common/concurrent.py +36 -0
- fundrive_baidu-0.1.3/src/baidu/common/constant.py +11 -0
- fundrive_baidu-0.1.3/src/baidu/common/crypto.py +298 -0
- fundrive_baidu-0.1.3/src/baidu/common/date.py +7 -0
- fundrive_baidu-0.1.3/src/baidu/common/downloader.py +113 -0
- fundrive_baidu-0.1.3/src/baidu/common/event.py +50 -0
- fundrive_baidu-0.1.3/src/baidu/common/file_type.py +208 -0
- fundrive_baidu-0.1.3/src/baidu/common/io.py +1159 -0
- fundrive_baidu-0.1.3/src/baidu/common/keyboard.py +103 -0
- fundrive_baidu-0.1.3/src/baidu/common/localstorage.py +247 -0
- fundrive_baidu-0.1.3/src/baidu/common/log.py +40 -0
- fundrive_baidu-0.1.3/src/baidu/common/net.py +22 -0
- fundrive_baidu-0.1.3/src/baidu/common/number.py +9 -0
- fundrive_baidu-0.1.3/src/baidu/common/path.py +51 -0
- fundrive_baidu-0.1.3/src/baidu/common/platform.py +7 -0
- fundrive_baidu-0.1.3/src/baidu/common/progress_bar.py +41 -0
- fundrive_baidu-0.1.3/src/baidu/common/random.py +10 -0
- fundrive_baidu-0.1.3/src/baidu/common/url.py +2 -0
- fundrive_baidu-0.1.3/src/baidu/pcs/__init__.py +35 -0
- fundrive_baidu-0.1.3/src/baidu/pcs/api.py +650 -0
- fundrive_baidu-0.1.3/src/baidu/pcs/errors.py +155 -0
- fundrive_baidu-0.1.3/src/baidu/pcs/inner.py +321 -0
- fundrive_baidu-0.1.3/src/baidu/pcs/pcs.py +1056 -0
- fundrive_baidu-0.1.3/src/baidu/pcs/phone.py +363 -0
- fundrive_baidu-0.1.3/src/baidu/utils.py +73 -0
- fundrive_baidu-0.1.3/src/fundrive_baidu.egg-info/PKG-INFO +23 -0
- fundrive_baidu-0.1.3/src/fundrive_baidu.egg-info/SOURCES.txt +58 -0
- fundrive_baidu-0.1.3/src/fundrive_baidu.egg-info/dependency_links.txt +1 -0
- fundrive_baidu-0.1.3/src/fundrive_baidu.egg-info/requires.txt +14 -0
- fundrive_baidu-0.1.3/src/fundrive_baidu.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: fundrive-baidu
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: fundrive
|
|
5
|
+
Author-email: niuliangtao <farfarfun@qq.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: aget>=0.2.0
|
|
9
|
+
Requires-Dist: chardet>=5.2.0
|
|
10
|
+
Requires-Dist: click>=8.1.7
|
|
11
|
+
Requires-Dist: cryptography>=44.0.0
|
|
12
|
+
Requires-Dist: cython>=3.0.11
|
|
13
|
+
Requires-Dist: fastapi>=0.115.6
|
|
14
|
+
Requires-Dist: jinja2>=3.1.4
|
|
15
|
+
Requires-Dist: passlib>=1.7.4
|
|
16
|
+
Requires-Dist: pillow>=10.4.0
|
|
17
|
+
Requires-Dist: requests>=2.32.3
|
|
18
|
+
Requires-Dist: requests-toolbelt>=1.0.0
|
|
19
|
+
Requires-Dist: rich>=13.9.4
|
|
20
|
+
Requires-Dist: typing-extensions>=4.12.2
|
|
21
|
+
Requires-Dist: uvicorn>=0.33.0
|
|
22
|
+
|
|
23
|
+
# fundrive-baidu
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# fundrive-baidu
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fundrive-baidu"
|
|
3
|
+
version = "0.1.3"
|
|
4
|
+
description = "fundrive"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.8"
|
|
7
|
+
dependencies = [ "aget>=0.2.0", "chardet>=5.2.0", "click>=8.1.7", "cryptography>=44.0.0", "cython>=3.0.11", "fastapi>=0.115.6", "jinja2>=3.1.4", "passlib>=1.7.4", "pillow>=10.4.0", "requests>=2.32.3", "requests-toolbelt>=1.0.0", "rich>=13.9.4", "typing-extensions>=4.12.2", "uvicorn>=0.33.0",]
|
|
8
|
+
[[project.authors]]
|
|
9
|
+
name = "niuliangtao"
|
|
10
|
+
email = "farfarfun@qq.com"
|
|
11
|
+
|
|
12
|
+
[tool.setuptools]
|
|
13
|
+
license-files = []
|
|
File without changes
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
from os import PathLike
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Dict, List, NamedTuple, Optional
|
|
5
|
+
|
|
6
|
+
from rich import print
|
|
7
|
+
|
|
8
|
+
from baidu.baidupcs import BaiduPCSApi, PcsUser
|
|
9
|
+
from baidu.commands.env import ACCOUNT_DATA_PATH
|
|
10
|
+
from baidu.common.path import join_path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Account(NamedTuple):
|
|
14
|
+
user: PcsUser
|
|
15
|
+
|
|
16
|
+
# current working directory
|
|
17
|
+
pwd: str = "/"
|
|
18
|
+
encrypt_password: Optional[str] = None
|
|
19
|
+
|
|
20
|
+
# In version 2, salt is generated by `os.urandom`.
|
|
21
|
+
# Here it useless.
|
|
22
|
+
salt: Optional[str] = None
|
|
23
|
+
|
|
24
|
+
# Account Name which can be set by hand
|
|
25
|
+
account_name: str = ""
|
|
26
|
+
|
|
27
|
+
def pcsapi(self) -> BaiduPCSApi:
|
|
28
|
+
auth = self.user.auth
|
|
29
|
+
assert auth, f"{self}.user.auth is None"
|
|
30
|
+
return BaiduPCSApi(
|
|
31
|
+
bduss=auth.bduss,
|
|
32
|
+
stoken=auth.stoken,
|
|
33
|
+
ptoken=auth.ptoken,
|
|
34
|
+
cookies=auth.cookies,
|
|
35
|
+
user_id=self.user.user_id,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def from_bduss(
|
|
40
|
+
bduss: str,
|
|
41
|
+
cookies: Dict[str, Optional[str]] = {},
|
|
42
|
+
account_name: str = "",
|
|
43
|
+
) -> "Account":
|
|
44
|
+
api = BaiduPCSApi(bduss=bduss, cookies=cookies)
|
|
45
|
+
user = api.user_info()
|
|
46
|
+
return Account(user=user, account_name=account_name or user.user_name or "")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class AccountManager:
|
|
50
|
+
"""Account Manager
|
|
51
|
+
|
|
52
|
+
Manage all accounts
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(self, data_path: Optional[PathLike] = None):
|
|
56
|
+
self._accounts: Dict[int, Account] = {} # user_id (int) -> Account
|
|
57
|
+
self._who: Optional[int] = None # user_id (int)
|
|
58
|
+
self._data_path = data_path
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def load_data(data_path: PathLike) -> "AccountManager":
|
|
62
|
+
try:
|
|
63
|
+
data_path = Path(data_path).expanduser()
|
|
64
|
+
am = pickle.load(data_path.open("rb"))
|
|
65
|
+
_compat_account_manager(am)
|
|
66
|
+
return am
|
|
67
|
+
except Exception:
|
|
68
|
+
return AccountManager(data_path=data_path)
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def accounts(self) -> List[Account]:
|
|
72
|
+
"""All accounts"""
|
|
73
|
+
|
|
74
|
+
return list(self._accounts.values())
|
|
75
|
+
|
|
76
|
+
def set_account_name(self, account_name: str, user_id: int = None):
|
|
77
|
+
"""Set account name"""
|
|
78
|
+
|
|
79
|
+
user_id = user_id or self._who
|
|
80
|
+
|
|
81
|
+
assert user_id, "No recent user"
|
|
82
|
+
|
|
83
|
+
account = self._accounts.get(user_id)
|
|
84
|
+
|
|
85
|
+
assert account
|
|
86
|
+
|
|
87
|
+
account = account._replace(account_name=account_name)
|
|
88
|
+
self._accounts[user_id] = account
|
|
89
|
+
|
|
90
|
+
def set_encrypt_password(
|
|
91
|
+
self, encrypt_password: Optional[str] = None, salt: Optional[str] = None
|
|
92
|
+
):
|
|
93
|
+
"""Set encryption key"""
|
|
94
|
+
|
|
95
|
+
assert self._who, "No recent user"
|
|
96
|
+
|
|
97
|
+
account = self._accounts.get(self._who)
|
|
98
|
+
|
|
99
|
+
assert account
|
|
100
|
+
|
|
101
|
+
account = account._replace(encrypt_password=encrypt_password, salt=salt)
|
|
102
|
+
self._accounts[self._who] = account
|
|
103
|
+
|
|
104
|
+
def cd(self, remotedir: str = "/"):
|
|
105
|
+
"""Change current working directory"""
|
|
106
|
+
|
|
107
|
+
assert self._who, "No recent user"
|
|
108
|
+
|
|
109
|
+
account = self._accounts.get(self._who)
|
|
110
|
+
|
|
111
|
+
assert account
|
|
112
|
+
|
|
113
|
+
pwd = join_path(Path(account.pwd), Path(remotedir))
|
|
114
|
+
account = account._replace(pwd=pwd)
|
|
115
|
+
self._accounts[self._who] = account
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def pwd(self) -> str:
|
|
119
|
+
"""Current working directory of recent user"""
|
|
120
|
+
|
|
121
|
+
assert self._who, "No recent user"
|
|
122
|
+
|
|
123
|
+
account = self._accounts.get(self._who)
|
|
124
|
+
|
|
125
|
+
assert account
|
|
126
|
+
|
|
127
|
+
return account.pwd
|
|
128
|
+
|
|
129
|
+
def who(self, user_id: Optional[int] = None) -> Optional[Account]:
|
|
130
|
+
"""Return recent `Account`"""
|
|
131
|
+
|
|
132
|
+
user_id = user_id or self._who
|
|
133
|
+
if user_id:
|
|
134
|
+
return self._accounts.get(user_id)
|
|
135
|
+
else:
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
def update(self, user_id: Optional[int] = None):
|
|
139
|
+
"""Update user_info"""
|
|
140
|
+
|
|
141
|
+
user_id = user_id or self._who
|
|
142
|
+
if user_id:
|
|
143
|
+
account = self._accounts.get(user_id)
|
|
144
|
+
if not account:
|
|
145
|
+
return None
|
|
146
|
+
|
|
147
|
+
api = account.pcsapi()
|
|
148
|
+
user = api.user_info()
|
|
149
|
+
|
|
150
|
+
self._accounts[user_id] = account._replace(user=user)
|
|
151
|
+
|
|
152
|
+
def su(self, user_id: int):
|
|
153
|
+
"""Change recent user with `PcsUser.user_id`
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
who (int): `PcsUser.user_id`
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
assert user_id in self._accounts, f"No user {user_id}"
|
|
160
|
+
|
|
161
|
+
self._who = user_id
|
|
162
|
+
|
|
163
|
+
def add_account(self, account: Account):
|
|
164
|
+
"""Add an account to the manager"""
|
|
165
|
+
|
|
166
|
+
self._accounts[account.user.user_id] = account
|
|
167
|
+
|
|
168
|
+
def delete_account(self, user_id: int):
|
|
169
|
+
"""Delete a user
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
who (int): `PcsUser.user_id`
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
if user_id in self._accounts:
|
|
176
|
+
del self._accounts[user_id]
|
|
177
|
+
if user_id == self._who:
|
|
178
|
+
self._who = None
|
|
179
|
+
|
|
180
|
+
def save(self, data_path: Optional[PathLike] = None):
|
|
181
|
+
"""Serialize to local path"""
|
|
182
|
+
|
|
183
|
+
data_path = data_path or self._data_path
|
|
184
|
+
assert data_path, "No data path"
|
|
185
|
+
|
|
186
|
+
data_path = Path(data_path).expanduser()
|
|
187
|
+
if not data_path.parent.exists():
|
|
188
|
+
data_path.parent.mkdir(parents=True)
|
|
189
|
+
|
|
190
|
+
pickle.dump(self, open(data_path, "wb"))
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _compat_account_manager(am: AccountManager):
|
|
194
|
+
"""Update stored account manager to compat current version"""
|
|
195
|
+
_compat_v0_5_9(am)
|
|
196
|
+
_set_account_names(am)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _compat_v0_5_9(am: AccountManager):
|
|
200
|
+
for user_id, account in am._accounts.items():
|
|
201
|
+
old_products = account.user.products
|
|
202
|
+
if isinstance(old_products, dict): # type: ignore
|
|
203
|
+
print( # type: ignore
|
|
204
|
+
"[i yellow]Update[/i yellow]: Transfer PcsUser format for ^v0.5.9: "
|
|
205
|
+
f"user_id: {user_id}"
|
|
206
|
+
)
|
|
207
|
+
am.update(user_id)
|
|
208
|
+
|
|
209
|
+
data_path = am._data_path
|
|
210
|
+
if not data_path or not Path(data_path).exists():
|
|
211
|
+
am._data_path = ACCOUNT_DATA_PATH
|
|
212
|
+
|
|
213
|
+
am.save()
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _set_account_names(am: AccountManager):
|
|
217
|
+
"""Set account's name with its user's name if that is empty"""
|
|
218
|
+
|
|
219
|
+
for user_id, account in am._accounts.items():
|
|
220
|
+
if not account.account_name:
|
|
221
|
+
am._accounts[user_id] = account._replace(
|
|
222
|
+
account_name=account.user.user_name or ""
|
|
223
|
+
)
|