Skip to content

Commit bfeb5e9

Browse files
authored
Merge pull request #156 from Ljzd-PRO/devel
Bump to v0.8.0
2 parents 292419f + 774ff2b commit bfeb5e9

14 files changed

+182
-144
lines changed

CHANGELOG.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,46 @@
22

33
### 💡 Feature
44

5-
- Add support for customizing filename:
6-
- Edit `KTOOLBOX_JOB__FILENAME_FORMAT` in `prod.env` or environment variables to set this option (#116)
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
9+
10+
### 🪲 Fix
11+
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
714
- 📖More information: [Configuration-Reference-JobConfiguration](https://ktoolbox.readthedocs.io/latest/configuration/reference/#ktoolbox.configuration.JobConfiguration)
815
```dotenv
916
# Rename attachments in numerical order, e.g. `1.png`, `2.png`, ...
1017
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
1118
1219
# `{}`: Basic filename
13-
# Can be used with the configuration option above.
14-
# Rename attachments to `[2024-1-1]_1.png`, `[2024-1-1]_2.png`, ...
15-
KTOOLBOX_JOB__FILENAME_FORMAT="[{published}]_{}"
20+
# Rename attachments to `1_[2024-1-1].png`, `2_[2024-1-1].png`, ...
21+
KTOOLBOX_JOB__FILENAME_FORMAT="{}_[{published}]"
1622
```
17-
- Change default post text content filename `index.html` to `content.txt`
18-
19-
[//]: # (### 🪲 Fix)
2023
2124
- - -
2225
2326
### 💡 新特性
2427
25-
- 支持自定义下载的文件名格式:
26-
- 在 `prod.env` 或环境变量中编辑 `KTOOLBOX_JOB__FILENAME_FORMAT` 以设置该选项 (#116)
28+
- 停止在下载速度单位中使用二进制前缀(IEEE 1541-2002)(使用 `KB`, `MB`, ... 而不是 `KiB`, `MiB`, ...)
29+
- 获取作者名称失败时停止下载,而不是采用作者ID作为目录名继续下载
30+
- 除了 `prod.env` 文件以外,KToolBox 也会从 **`.env`** 文件读取配置
31+
- KToolBox 启动时将会输出配置详情,以便用户检查
32+
33+
### 🪲 修复
34+
35+
- 修复下载进度条被输出的日志打断的问题
36+
- 修复 job.filename_format 文件名格式配置中的 {} 被简单地替换成文件名和后缀,而没有考虑其所在位置的问题
2737
- 📖更多信息: [配置-参考-JobConfiguration](https://ktoolbox.readthedocs.io/latest/configuration/reference/#ktoolbox.configuration.JobConfiguration)
2838
```dotenv
2939
# 按照数字顺序重命名附件, 例如 `1.png`, `2.png`, ...
3040
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
3141
3242
# `{}`:基本文件名
33-
# 可以和上面的配置选项搭配使用
34-
# 附件将被重命名为 `[2024-1-1]_1.png`, `[2024-1-1]_2.png`, ...
35-
KTOOLBOX_JOB__FILENAME_FORMAT="[{published}]_{}"
43+
# 附件将被重命名为 `1_[2024-1-1].png`, `2_[2024-1-1].png`, ...
44+
KTOOLBOX_JOB__FILENAME_FORMAT="{}_[{published}]"
3645
```
37-
- 更改默认的作品文本内容文件名 `index.html` 为 `content.txt`
38-
39-
[//]: # (### 🪲 修复)
4046
41-
**Full Changelog**: https://github.com/Ljzd-PRO/KToolBox/compare/v0.6.0...v0.7.0
47+
**Full Changelog**: https://github.com/Ljzd-PRO/KToolBox/compare/v0.7.0...v0.8.0

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ See [documentation](https://ktoolbox.readthedocs.io/) for more details.
6565

6666
### Installation
6767

68+
You can use executables from [releases](https://github.com/Ljzd-PRO/KToolBox/releases) page
69+
70+
Manually install:
71+
6872
- Recommend
6973
```bash
7074
pip3 install pipx

README_zh-CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666

6767
### 安装
6868

69+
你可以从 [releases](https://github.com/Ljzd-PRO/KToolBox/releases) 页面下载可执行文件使用
70+
71+
手动安装:
72+
6973
- 推荐
7074
```bash
7175
pip3 install pipx

docs/en/index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@
5353

5454
### Installation
5555

56-
=== "Normal"
56+
You can use executables from [releases](https://github.com/Ljzd-PRO/KToolBox/releases) page
57+
58+
=== "Manually Install - Normal"
59+
Recommend to use pipx
5760
```bash
58-
pip3 install ktoolbox
61+
pip3 install pipx
62+
pipx install ktoolbox
5963
```
6064

61-
=== "For iOS a-Shell"
65+
=== "Manually Install - For iOS a-Shell"
6266
```bash
6367
pip3 install ktoolbox-pure-py
6468
```

docs/zh/index.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@
5454

5555
### 安装
5656

57-
=== "一般情况"
58-
```bash
59-
pip3 install ktoolbox
60-
```
57+
你可以从 [releases](https://github.com/Ljzd-PRO/KToolBox/releases) 页面下载可执行文件使用
58+
59+
=== "手动安装 - 一般情况"
60+
推荐使用 pipx
61+
```bash
62+
pip3 install pipx
63+
pipx install ktoolbox
64+
```
6165

62-
=== "对于 iOS a-Shell"
66+
=== "手动安装 - 对于 iOS a-Shell"
6367
```bash
6468
pip3 install ktoolbox-pure-py
6569
```

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.7.0"
4+
__version__ = "0.8.0"

ktoolbox/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
from ktoolbox.cli import KToolBoxCli
55
from ktoolbox.configuration import config
6-
from ktoolbox.utils import logger_init, uvloop_init, generate_msg
6+
from ktoolbox.utils import logger_init, uvloop_init
77

88

99
def main():
1010
try:
1111
logger_init(cli_use=True)
12-
logger.debug(generate_msg(config=config))
12+
logger.info(repr(config))
1313
uvloop_init()
1414
fire.Fire(KToolBoxCli)
1515
except KeyboardInterrupt:

ktoolbox/action/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
from pathlib import Path
23
from typing import Optional, List, Generator, Any, Tuple
34

45
from loguru import logger
@@ -37,18 +38,20 @@ def generate_post_path_name(post: Post) -> str:
3738

3839
def generate_filename(post: Post, basic_name: str) -> str:
3940
"""Generate download filename"""
41+
basic_name_suffix = Path(basic_name).suffix
42+
basic_name_filename = basic_name.split(basic_name_suffix)[0] if basic_name_suffix else basic_name
4043
try:
4144
return sanitize_filename(
4245
config.job.filename_format.format(
43-
basic_name,
46+
basic_name_filename,
4447
id=post.id,
4548
user=post.user,
4649
service=post.service,
4750
title=post.title,
4851
added=post.added.strftime(TIME_FORMAT) if post.added else "",
4952
published=post.published.strftime(TIME_FORMAT) if post.published else "",
5053
edited=post.edited.strftime(TIME_FORMAT) if post.edited else ""
51-
)
54+
) + basic_name_suffix
5255
)
5356
except KeyError as e:
5457
logger.error(f"`JobConfiguration.filename_format` contains invalid key: {e}")

ktoolbox/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,14 @@ async def sync_creator(
276276
)
277277
)
278278
else:
279-
logger.warning(
279+
logger.error(
280280
generate_msg(
281-
f"Failed to fetch the name of creator <{creator_id}>, use creator ID as directory name",
281+
f"Failed to fetch the name of creator <{creator_id}>",
282282
detail=creator_ret.message
283283
)
284284
)
285+
return creator_ret.message
286+
285287
creator_path = path / sanitize_filename(creator_name)
286288

287289
creator_path.mkdir(exist_ok=True)

ktoolbox/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ class Configuration(BaseSettings):
219219
)
220220

221221

222-
config = Configuration(_env_file='prod.env')
222+
config = Configuration(_env_file=['.env', 'prod.env'])

ktoolbox/downloader/downloader.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,8 @@ async def run(
214214
desc=self._save_filename,
215215
total=total_size,
216216
disable=not progress,
217-
unit="iB",
218-
unit_scale=True,
219-
unit_divisor=1024
217+
unit="B",
218+
unit_scale=True
220219
)
221220
async for chunk in chunk_iterator:
222221
if self._stop:

ktoolbox/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import aiofiles
88
from loguru import logger
99
from pydantic import BaseModel, ConfigDict
10+
from tqdm import tqdm
1011

1112
from ktoolbox._enum import RetCodeEnum, DataStorageNameEnum
1213
from ktoolbox.configuration import config
@@ -60,7 +61,8 @@ def logger_init(cli_use: bool = False, disable_stdout: bool = False):
6061
elif cli_use:
6162
logger.remove()
6263
logger.add(
63-
sys.stderr,
64+
tqdm.write,
65+
colorize=True,
6466
level=logging.INFO,
6567
filter=lambda record: record["level"].name != "SUCCESS"
6668
)

0 commit comments

Comments
 (0)