Skip to content

Commit 0183910

Browse files
authored
Merge pull request #163 from Ljzd-PRO/devel
Bump to v0.9.0
2 parents bfeb5e9 + caec1e9 commit 0183910

File tree

14 files changed

+181
-176
lines changed

14 files changed

+181
-176
lines changed

CHANGELOG.md

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,28 @@
22

33
### 💡 Feature
44

5-
- Stop using binary prefix (IEEE 1541-2002) in download speed unit (use `KB`, `MB`, ... instead of `KiB`, `MiB`, ...)
6-
- Stop downloading when failing to retrieve the creator's name, instead of using the creator ID as the directory name to continue downloading
7-
- In addition to the `prod.env` file, KToolBox also reads configurations from the **`.env`** file
8-
- When KToolBox starts, it will output the configuration details for user inspection
5+
- Show the download job status each 30s (waiting, running, completed%)
6+
- Shortened the log length
7+
- E.g. `2024-10-05 20:12:37 | WARNING | ktoolbox.job.runner - Download file already exists, skipping ...`
98

109
### 🪲 Fix
1110

12-
- Fix the issue where the log output interrupts the download progress bar
13-
- Fix the `job.filename_format` configuration, where `{}` is simply replaced with the filename and extension without considering its position
14-
- 📖More information: [Configuration-Reference-JobConfiguration](https://ktoolbox.readthedocs.io/latest/configuration/reference/#ktoolbox.configuration.JobConfiguration)
15-
```dotenv
16-
# Rename attachments in numerical order, e.g. `1.png`, `2.png`, ...
17-
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
18-
19-
# `{}`: Basic filename
20-
# Rename attachments to `1_[2024-1-1].png`, `2_[2024-1-1].png`, ...
21-
KTOOLBOX_JOB__FILENAME_FORMAT="{}_[{published}]"
22-
```
11+
- Fix error when attempting to download files which posses too long names (invalid names) (#150)
12+
- For example the wrong filename like this: `https://www.patreon.com/media-u/Z0FBQUFBQm........=#12345678_` \
13+
KToolBox can get the correct filename: `6edd5bdae......0e7f913.png`
2314

2415
- - -
2516

2617
### 💡 新特性
2718

28-
- 停止在下载速度单位中使用二进制前缀(IEEE 1541-2002)(使用 `KB`, `MB`, ... 而不是 `KiB`, `MiB`, ...)
29-
- 获取作者名称失败时停止下载,而不是采用作者ID作为目录名继续下载
30-
- 除了 `prod.env` 文件以外,KToolBox 也会从 **`.env`** 文件读取配置
31-
- KToolBox 启动时将会输出配置详情,以便用户检查
19+
- 每隔 30 秒显示下载任务状态(等待中、运行中、已完成%)
20+
- 缩短了日志长度
21+
- 例如 `2024-10-05 20:12:37 | WARNING | ktoolbox.job.runner - Download file already exists, skipping ...`
3222

3323
### 🪲 修复
3424

35-
- 修复下载进度条被输出的日志打断的问题
36-
- 修复 job.filename_format 文件名格式配置中的 {} 被简单地替换成文件名和后缀,而没有考虑其所在位置的问题
37-
- 📖更多信息: [配置-参考-JobConfiguration](https://ktoolbox.readthedocs.io/latest/configuration/reference/#ktoolbox.configuration.JobConfiguration)
38-
```dotenv
39-
# 按照数字顺序重命名附件, 例如 `1.png`, `2.png`, ...
40-
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
41-
42-
# `{}`:基本文件名
43-
# 附件将被重命名为 `1_[2024-1-1].png`, `2_[2024-1-1].png`, ...
44-
KTOOLBOX_JOB__FILENAME_FORMAT="{}_[{published}]"
45-
```
25+
- 修复下载过长文件名(非法文件名)的文件时报错的问题 (#150)
26+
- 例如这样的错误文件名:`https://www.patreon.com/media-u/Z0FBQUFBQm........=#12345678_` \
27+
KToolBox 可以获取到正确的文件名:`6edd5bdae......0e7f913.png`
4628

47-
**Full Changelog**: https://github.com/Ljzd-PRO/KToolBox/compare/v0.7.0...v0.8.0
29+
**Full Changelog**: https://github.com/Ljzd-PRO/KToolBox/compare/v0.8.0...v0.9.0

docs/en/configuration/guide.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Guide
22

3-
- KToolBox read **`prod.env` file** in the work folder or **environment variables** to store configuration
3+
- KToolBox read **`.env` or `prod.env` file** in the work folder or **environment variables** to store configuration
44
- Check [Reference](reference.md) for all configuration options
55
- Use `__` to specify the sub option, like `KTOOLBOX_API__SCHEME` means `api.scheme`
66
- All configuration options are optional
77

8-
## `prod.env` file example
8+
## `.env` / `prod.env` file example
99

1010
```dotenv
1111
# Download 10 files at the same time.
@@ -27,11 +27,4 @@ KTOOLBOX_JOB__FILENAME_FORMAT=[{published}]_{}
2727
2828
# Prefix the post directory name with its release/publish date, e.g. `[2024-1-1]HelloWorld`
2929
KTOOLBOX_JOB__POST_DIRNAME_FORMAT=[{published}]{title}
30-
31-
# Allocate 102400 Bytes as buffer for each download job
32-
KTOOLBOX_DOWNLOADER__BUFFER_SIZE=102400
33-
34-
# Disable SSL certificate verification for Kemono API server and download server
35-
# It's useful when certificate on Kemono server expired. (SSL: CERTIFICATE_VERIFY_FAILED)
36-
KTOOLBOX_SSL_VERIFY=False
3730
```

docs/en/coomer.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
KToolBox support downloading from Coomer.su / Coomer.party
44

5-
Files of Coomer.su can be downloaded from Kemono.su / Kemono.party server, so you can download Coomer posts **without modifying configuration**.
6-
7-
If it did not work, you can modify the configuration by `prod.env` dotenv file or system environment variables and then try again:
5+
You need to modify the configuration by `.env` or `prod.env` dotenv file or system environment variables:
86
```dotenv
97
# For Coomer API
108
KTOOLBOX_API__NETLOC=coomer.su

docs/en/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,12 @@ ktoolbox sync-creator https://kemono.su/fanbox/user/9016 --offset=10 --length=5
106106
# Download posts from the creator/artist from 2024-1-1 to 2024-3-1
107107
ktoolbox sync-creator https://kemono.su/fanbox/user/9016 --start-time=2024-1-1 --end-time=2024-3-1
108108
```
109+
110+
### Configuration
111+
112+
- Download 10 files at the same time
113+
- Rename attachments in numerical order
114+
- Prefix the post directory name with its release/publish date
115+
- ...
116+
117+
Goto [Configuration-Guide](https://ktoolbox.readthedocs.io/latest/configuration/guide/) page for more details.

docs/zh/configuration/guide.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# 向导
22

3-
- KToolBox 读取工作目录下的 **`prod.env` 文件****环境变量** 来设定配置
3+
- KToolBox 读取工作目录下的 **`.env``prod.env` 文件****环境变量** 来设定配置
44
- 前往 [参考](./reference.md) 查看所有配置选项
55
-`__` 来指定子选项, 例如 `KTOOLBOX_API__SCHEME` 相当于 `api.scheme`
66
- 所有配置选项都是可选的
77

8-
## `prod.env` 文件示例
8+
## `.env` / `prod.env` 文件示例
99

1010
```dotenv
1111
# 可同时下载10个文件
@@ -27,11 +27,4 @@ KTOOLBOX_JOB__FILENAME_FORMAT=[{published}]_{}
2727
2828
# 将发布日期作为作品目录名的开头,例如 `[2024-1-1]HelloWorld`
2929
KTOOLBOX_JOB__POST_DIRNAME_FORMAT=[{published}]{title}
30-
31-
# 为每个下载任务分配 102400 字节内存作为缓冲区
32-
KTOOLBOX_DOWNLOADER__BUFFER_SIZE=102400
33-
34-
# 为Kemono API服务器和下载服务器禁用SSL证书检查
35-
# 在Kemono服务器的证书过期时很有用 (SSL: CERTIFICATE_VERIFY_FAILED)
36-
KTOOLBOX_SSL_VERIFY=False
3730
```

docs/zh/coomer.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
KToolBox 支持从 Coomer.su / Coomer.party 下载
44

5-
Coomer.su 的文件可以从 Kemono.su / Kemono.party 服务器下载,所以 **无需编辑配置** 即可下载 Coomer 里的作品
6-
7-
如果无效,你可以通过 dotenv文件 `prod.env` 或系统环境变量来修改配置,然后再次尝试:
5+
你需要通过 dotenv文件 `.env``prod.env` 或系统环境变量来修改配置:
86
```dotenv
97
# Coomer API
108
KTOOLBOX_API__NETLOC=coomer.su

docs/zh/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ ktoolbox sync-creator https://kemono.su/fanbox/user/9016 --offset=10 --length=5
105105
# 下载作者/画师从 2024-1-1 到 2024-3-1 的作品
106106
ktoolbox sync-creator https://kemono.su/fanbox/user/9016 --start-time=2024-1-1 --end-time=2024-3-1
107107
```
108+
109+
### 配置
110+
111+
- 同时下载10个文件
112+
- 按照数字顺序重命名附件, 例如 `1.png`, `2.png`, ...
113+
- 将发布日期作为作品目录名的开头,例如 `[2024-1-1]HelloWorld`
114+
- ...
115+
116+
前往 [配置-向导](https://ktoolbox.readthedocs.io/latest/zh/configuration/guide/) 页面查看更多详情。

ktoolbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__title__ = "KToolBox"
22
# noinspection SpellCheckingInspection
33
__description__ = "A useful CLI tool for downloading posts in Kemono.party / .su"
4-
__version__ = "0.8.0"
4+
__version__ = "0.9.0"

ktoolbox/action/job.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,24 @@ async def create_job_from_post(
8181

8282
# Filter and create jobs for ``Post.file``
8383
if post.file and post.file.path:
84-
post_file_name = post.file.name or Path(post.file.path).name
84+
post_file_name = Path(post.file.name) if is_valid_filename(post.file.name) else Path(
85+
urlparse(post.file.path).path
86+
)
8587
if (not config.job.allow_list or any(
8688
map(
87-
lambda x: fnmatch(post_file_name, x),
89+
lambda x: fnmatch(post_file_name.name, x),
8890
config.job.allow_list
8991
)
9092
)) and not any(
9193
map(
92-
lambda x: fnmatch(post_file_name, x),
94+
lambda x: fnmatch(post_file_name.name, x),
9395
config.job.block_list
9496
)
9597
):
9698
jobs.append(
9799
Job(
98100
path=post_path,
99-
alt_filename=f"{post.id}_{post_file_name}",
101+
alt_filename=f"{post.id}_{post_file_name.name}",
100102
server_path=post.file.path,
101103
type=PostFileTypeEnum.File
102104
)

ktoolbox/job/runner.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ async def processor(self) -> int:
141141
await self._job_queue.join()
142142
return failed_num
143143

144+
async def _watch_status(self):
145+
"""
146+
Watch running, completed, failed jobs
147+
"""
148+
while not self._job_queue.empty():
149+
await asyncio.sleep(30)
150+
logger.info(f"Waiting: {self.waiting_size} / "
151+
f"Running: {self.processing_size} / "
152+
f"Completed: {self.done_size} "
153+
f"({(self.done_size / (self.waiting_size + self.processing_size + self.done_size)) * 100:.2f}%)")
154+
144155
async def start(self):
145156
"""
146157
Start processing jobs concurrently
@@ -154,7 +165,10 @@ async def start(self):
154165
task = asyncio.create_task(self.processor())
155166
self._concurrent_tasks.add(task)
156167
task.add_done_callback(self._concurrent_tasks.discard)
157-
task_done_set, _ = await asyncio.wait(self._concurrent_tasks)
168+
_, (task_done_set, _) = await asyncio.gather(
169+
self._watch_status(),
170+
asyncio.wait(self._concurrent_tasks)
171+
)
158172
for task in task_done_set:
159173
try:
160174
failed_num += task.result()

ktoolbox/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def logger_init(cli_use: bool = False, disable_stdout: bool = False):
6363
logger.add(
6464
tqdm.write,
6565
colorize=True,
66+
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
67+
"<level>{level: <8}</level> | "
68+
"<cyan>{name}</cyan> - <level>{message}</level>",
6669
level=logging.INFO,
6770
filter=lambda record: record["level"].name != "SUCCESS"
6871
)

0 commit comments

Comments
 (0)