Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to v0.8.0 #156

Merged
merged 18 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@

### 💡 Feature

- Add support for customizing filename:
- Edit `KTOOLBOX_JOB__FILENAME_FORMAT` in `prod.env` or environment variables to set this option (#116)
- Stop using binary prefix (IEEE 1541-2002) in download speed unit (use `KB`, `MB`, ... instead of `KiB`, `MiB`, ...)
- Stop downloading when failing to retrieve the creator's name, instead of using the creator ID as the directory name to continue downloading
- In addition to the `prod.env` file, KToolBox also reads configurations from the **`.env`** file
- When KToolBox starts, it will output the configuration details for user inspection

### 🪲 Fix

- Fix the issue where the log output interrupts the download progress bar
- Fix the `job.filename_format` configuration, where `{}` is simply replaced with the filename and extension without considering its position
- 📖More information: [Configuration-Reference-JobConfiguration](https://ktoolbox.readthedocs.io/latest/configuration/reference/#ktoolbox.configuration.JobConfiguration)
```dotenv
# Rename attachments in numerical order, e.g. `1.png`, `2.png`, ...
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True

# `{}`: Basic filename
# Can be used with the configuration option above.
# Rename attachments to `[2024-1-1]_1.png`, `[2024-1-1]_2.png`, ...
KTOOLBOX_JOB__FILENAME_FORMAT="[{published}]_{}"
# Rename attachments to `1_[2024-1-1].png`, `2_[2024-1-1].png`, ...
KTOOLBOX_JOB__FILENAME_FORMAT="{}_[{published}]"
```
- Change default post text content filename `index.html` to `content.txt`

[//]: # (### 🪲 Fix)

- - -

### 💡 新特性

- 支持自定义下载的文件名格式:
- 在 `prod.env` 或环境变量中编辑 `KTOOLBOX_JOB__FILENAME_FORMAT` 以设置该选项 (#116)
- 停止在下载速度单位中使用二进制前缀(IEEE 1541-2002)(使用 `KB`, `MB`, ... 而不是 `KiB`, `MiB`, ...)
- 获取作者名称失败时停止下载,而不是采用作者ID作为目录名继续下载
- 除了 `prod.env` 文件以外,KToolBox 也会从 **`.env`** 文件读取配置
- KToolBox 启动时将会输出配置详情,以便用户检查

### 🪲 修复

- 修复下载进度条被输出的日志打断的问题
- 修复 job.filename_format 文件名格式配置中的 {} 被简单地替换成文件名和后缀,而没有考虑其所在位置的问题
- 📖更多信息: [配置-参考-JobConfiguration](https://ktoolbox.readthedocs.io/latest/configuration/reference/#ktoolbox.configuration.JobConfiguration)
```dotenv
# 按照数字顺序重命名附件, 例如 `1.png`, `2.png`, ...
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True

# `{}`:基本文件名
# 可以和上面的配置选项搭配使用
# 附件将被重命名为 `[2024-1-1]_1.png`, `[2024-1-1]_2.png`, ...
KTOOLBOX_JOB__FILENAME_FORMAT="[{published}]_{}"
# 附件将被重命名为 `1_[2024-1-1].png`, `2_[2024-1-1].png`, ...
KTOOLBOX_JOB__FILENAME_FORMAT="{}_[{published}]"
```
- 更改默认的作品文本内容文件名 `index.html` 为 `content.txt`

[//]: # (### 🪲 修复)

**Full Changelog**: https://github.com/Ljzd-PRO/KToolBox/compare/v0.6.0...v0.7.0
**Full Changelog**: https://github.com/Ljzd-PRO/KToolBox/compare/v0.7.0...v0.8.0
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ See [documentation](https://ktoolbox.readthedocs.io/) for more details.

### Installation

You can use executables from [releases](https://github.com/Ljzd-PRO/KToolBox/releases) page

Manually install:

- Recommend
```bash
pip3 install pipx
Expand Down
4 changes: 4 additions & 0 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

### 安装

你可以从 [releases](https://github.com/Ljzd-PRO/KToolBox/releases) 页面下载可执行文件使用

手动安装:

- 推荐
```bash
pip3 install pipx
Expand Down
10 changes: 7 additions & 3 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@

### Installation

=== "Normal"
You can use executables from [releases](https://github.com/Ljzd-PRO/KToolBox/releases) page

=== "Manually Install - Normal"
Recommend to use pipx
```bash
pip3 install ktoolbox
pip3 install pipx
pipx install ktoolbox
```

=== "For iOS a-Shell"
=== "Manually Install - For iOS a-Shell"
```bash
pip3 install ktoolbox-pure-py
```
Expand Down
14 changes: 9 additions & 5 deletions docs/zh/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@

### 安装

=== "一般情况"
```bash
pip3 install ktoolbox
```
你可以从 [releases](https://github.com/Ljzd-PRO/KToolBox/releases) 页面下载可执行文件使用

=== "手动安装 - 一般情况"
推荐使用 pipx
```bash
pip3 install pipx
pipx install ktoolbox
```

=== "对于 iOS a-Shell"
=== "手动安装 - 对于 iOS a-Shell"
```bash
pip3 install ktoolbox-pure-py
```
Expand Down
2 changes: 1 addition & 1 deletion ktoolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__title__ = "KToolBox"
# noinspection SpellCheckingInspection
__description__ = "A useful CLI tool for downloading posts in Kemono.party / .su"
__version__ = "0.7.0"
__version__ = "0.8.0"
4 changes: 2 additions & 2 deletions ktoolbox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from ktoolbox.cli import KToolBoxCli
from ktoolbox.configuration import config
from ktoolbox.utils import logger_init, uvloop_init, generate_msg
from ktoolbox.utils import logger_init, uvloop_init


def main():
try:
logger_init(cli_use=True)
logger.debug(generate_msg(config=config))
logger.info(repr(config))
uvloop_init()
fire.Fire(KToolBoxCli)
except KeyboardInterrupt:
Expand Down
7 changes: 5 additions & 2 deletions ktoolbox/action/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from pathlib import Path
from typing import Optional, List, Generator, Any, Tuple

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

def generate_filename(post: Post, basic_name: str) -> str:
"""Generate download filename"""
basic_name_suffix = Path(basic_name).suffix
basic_name_filename = basic_name.split(basic_name_suffix)[0] if basic_name_suffix else basic_name
try:
return sanitize_filename(
config.job.filename_format.format(
basic_name,
basic_name_filename,
id=post.id,
user=post.user,
service=post.service,
title=post.title,
added=post.added.strftime(TIME_FORMAT) if post.added else "",
published=post.published.strftime(TIME_FORMAT) if post.published else "",
edited=post.edited.strftime(TIME_FORMAT) if post.edited else ""
)
) + basic_name_suffix
)
except KeyError as e:
logger.error(f"`JobConfiguration.filename_format` contains invalid key: {e}")
Expand Down
6 changes: 4 additions & 2 deletions ktoolbox/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,14 @@ async def sync_creator(
)
)
else:
logger.warning(
logger.error(
generate_msg(
f"Failed to fetch the name of creator <{creator_id}>, use creator ID as directory name",
f"Failed to fetch the name of creator <{creator_id}>",
detail=creator_ret.message
)
)
return creator_ret.message

creator_path = path / sanitize_filename(creator_name)

creator_path.mkdir(exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion ktoolbox/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,4 @@ class Configuration(BaseSettings):
)


config = Configuration(_env_file='prod.env')
config = Configuration(_env_file=['.env', 'prod.env'])
5 changes: 2 additions & 3 deletions ktoolbox/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ async def run(
desc=self._save_filename,
total=total_size,
disable=not progress,
unit="iB",
unit_scale=True,
unit_divisor=1024
unit="B",
unit_scale=True
)
async for chunk in chunk_iterator:
if self._stop:
Expand Down
4 changes: 3 additions & 1 deletion ktoolbox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import aiofiles
from loguru import logger
from pydantic import BaseModel, ConfigDict
from tqdm import tqdm

from ktoolbox._enum import RetCodeEnum, DataStorageNameEnum
from ktoolbox.configuration import config
Expand Down Expand Up @@ -60,7 +61,8 @@ def logger_init(cli_use: bool = False, disable_stdout: bool = False):
elif cli_use:
logger.remove()
logger.add(
sys.stderr,
tqdm.write,
colorize=True,
level=logging.INFO,
filter=lambda record: record["level"].name != "SUCCESS"
)
Expand Down
Loading
Loading