参考¶
Configuration
¶
KToolBox 配置
Attributes:
| Name | Type | Description | Default |
|---|---|---|---|
api |
APIConfiguration
|
Kemono API 配置 |
APIConfiguration()
|
downloader |
DownloaderConfiguration
|
文件下载器配置 |
DownloaderConfiguration()
|
job |
JobConfiguration
|
下载任务配置 |
JobConfiguration()
|
logger |
LoggerConfiguration
|
日志配置 |
LoggerConfiguration()
|
ssl_verify |
bool
|
对 Kemono API 服务器和下载服务器启用 SSL 证书验证 |
True
|
json_dump_indent |
int
|
JSON 文件保存时的缩进 |
4
|
use_uvloop |
bool
|
使用 uvloop/winloop 优化 asyncio 性能 Windows 下使用 winloop,类 Unix 系统下使用 uvloop,提高并发性能。 Windows 下安装 winloop: |
True
|
APIConfiguration
¶
Kemono API 配置
Attributes:
| Name | Type | Description | Default |
|---|---|---|---|
scheme |
Literal['http', 'https']
|
Kemono API 的 URL 协议 |
'https'
|
netloc |
str
|
Kemono API 的主机地址 |
'kemono.cr'
|
statics_netloc |
str
|
Kemono 服务器静态文件(如图片)的主机地址 |
'img.kemono.cr'
|
files_netloc |
str
|
Kemono 服务器帖子文件的主机地址 |
'kemono.cr'
|
path |
str
|
Kemono API 的根路径 |
'/api/v1'
|
timeout |
float
|
API 请求超时时间 |
5.0
|
retry_times |
int
|
API 请求失败时重试次数 |
3
|
retry_interval |
float
|
API 请求重试间隔秒数 |
2.0
|
session_key |
str
|
登录成功后可在 Cookie 中找到的会话密钥 |
''
|
DownloaderConfiguration
¶
文件下载器配置
Attributes:
| Name | Type | Description | Default |
|---|---|---|---|
scheme |
Literal['http', 'https']
|
下载器的 URL 协议 |
'https'
|
timeout |
float
|
下载器请求超时时间 |
30.0
|
encoding |
str
|
文件名解析和帖子 |
'utf-8'
|
buffer_size |
int
|
每个下载文件的文件 I/O 缓冲区字节数 |
20480
|
chunk_size |
int
|
下载器流的分块字节数 |
1024
|
temp_suffix |
str
|
下载文件的临时文件名后缀 |
'tmp'
|
retry_times |
int
|
下载失败时重试次数 |
10
|
retry_stop_never |
bool
|
永不停止下载器重试(启用时忽略 retry_times) |
False
|
retry_interval |
float
|
下载器重试间隔秒数 |
3.0
|
tps_limit |
float
|
每秒最大连接数 |
5.0
|
use_bucket |
bool
|
启用本地存储桶模式 |
False
|
bucket_path |
Path
|
本地存储桶路径 |
Path('./.ktoolbox/bucket_storage')
|
reverse_proxy |
str
|
下载 URL 的反向代理格式。通过插入空的 |
'{}'
|
keep_metadata |
bool
|
下载文件时保留文件元数据(例如最后修改时间等) |
True
|
PostStructureConfiguration
¶
帖子路径结构模型
-
默认结构:
.. ├─ content.txt ├─ external_links.txt ├─ {id}_{}.png (文件) ├─ post.json (元数据) ├─ attachments │ ├─ 1.png │ └─ 2.png └─ revisions ├─ <PostStructure> │ ├─ ... │ └─ ... └─ <PostStructure> ├─ ... └─ ... -
file可用属性属性 类型 id字符串 user字符串 service字符串 title字符串 added日期 published日期 edited日期
Attributes:
| Name | Type | Description | Default |
|---|---|---|---|
attachments |
Path
|
附件目录的子路径 |
Path('attachments')
|
content |
Path
|
帖子内容文件的子路径 |
Path('content.txt')
|
external_links |
Path
|
外部链接文件的子路径(用于保存内容中发现的云存储链接) |
Path('external_links.txt')
|
file |
str
|
帖子 |
'{id}_{}'
|
revisions |
Path
|
修订目录的子路径 |
Path('revisions')
|
JobConfiguration
¶
下载任务配置
-
post_dirname_format和filename_format可用属性属性 类型 id字符串 user字符串 service字符串 title字符串 added日期 published日期 edited日期 -
year_dirname_format和month_dirname_format可用属性属性 类型 year字符串 month字符串 -
Python 格式规格迷你语言参考文档
https://docs.python.org/zh-cn/3.13/library/string.html#format-specification-mini-language
Attributes:
| Name | Type | Description | Default |
|---|---|---|---|
count |
int
|
并发下载的协程数量 |
4
|
include_revisions |
bool
|
下载时包含修订帖子 |
False
|
post_dirname_format |
str
|
自定义帖子目录名格式,可使用 属性。 例如: |
'{title}'
|
post_structure |
PostStructureConfiguration
|
帖子路径结构 |
PostStructureConfiguration()
|
mix_posts |
bool
|
在创作者目录下将不同帖子的所有文件保存到同一路径,不创建帖子目录,且不会记录 |
False
|
sequential_filename |
bool
|
附件按数字顺序重命名,如 |
False
|
sequential_filename_excludes |
Set[str]
|
启用 |
Field(default_factory=set)
|
filename_format |
str
|
通过插入空的 |
'{}'
|
allow_list |
Set[str]
|
下载匹配这些模式(Unix shell 风格)的文件,如 |
Field(default_factory=set)
|
block_list |
Set[str]
|
不下载匹配这些模式(Unix shell 风格)的文件,如 |
Field(default_factory=set)
|
extract_content |
bool
|
提取帖子内容并保存到单独文件(文件名由 |
False
|
extract_external_links |
bool
|
从帖子内容中提取外部文件分享链接并保存到单独文件(文件名由 |
False
|
external_link_patterns |
List[str]
|
用于提取外部链接的正则表达式模式 |
['https?://drive\\.google\\.com/[^\\s]+', 'https?://docs\\.google\\.com/[^\\s]+', 'https?://mega\\.nz/[^\\s]+', 'https?://mega\\.co\\.nz/[^\\s]+', 'https?://(?:www\\.)?dropbox\\.com/[^\\s]+', 'https?://db\\.tt/[^\\s]+', 'https?://onedrive\\.live\\.com/[^\\s]+', 'https?://1drv\\.ms/[^\\s]+', 'https?://(?:www\\.)?mediafire\\.com/[^\\s]+', 'https?://(?:www\\.)?wetransfer\\.com/[^\\s]+', 'https?://we\\.tl/[^\\s]+', 'https?://(?:www\\.)?sendspace\\.com/[^\\s]+', 'https?://(?:www\\.)?4shared\\.com/[^\\s]+', 'https?://(?:www\\.)?zippyshare\\.com/[^\\s]+', 'https?://(?:www\\.)?uploadfiles\\.io/[^\\s]+', 'https?://(?:www\\.)?box\\.com/[^\\s]+', 'https?://(?:www\\.)?pcloud\\.com/[^\\s]+', 'https?://disk\\.yandex\\.[a-z]+/[^\\s]+', 'https?://[^\\s]*(?:file|upload|share|download|drive|storage)[^\\s]*\\.[a-z]{2,4}/[^\\s]+']
|
group_by_year |
bool
|
根据发布日期按年分组到不同目录 |
False
|
group_by_month |
bool
|
根据发布日期按月分组到不同目录(需要启用 group_by_year) |
False
|
year_dirname_format |
str
|
自定义年份目录名格式。可用属性: |
'{year}'
|
month_dirname_format |
str
|
自定义月份目录名格式。可用属性: |
'{year}-{month:02d}'
|
keywords |
Set[str]
|
按帖子标题关键词过滤(不区分大小写) |
Field(default_factory=set)
|
keywords_exclude |
Set[str]
|
按帖子标题关键词排除(不区分大小写) |
Field(default_factory=set)
|
download_file |
bool
|
是否下载帖子文件(通常为封面图片)。设置为 False 可跳过文件下载。 |
True
|
download_attachments |
bool
|
是否下载帖子附件。设置为 False 可跳过附件下载。 |
True
|
min_file_size |
Optional[int]
|
最小文件大小(字节)。小于此大小的文件将被跳过。设置为 None 禁用最小文件大小过滤。 |
None
|
max_file_size |
Optional[int]
|
最大文件大小(字节)。大于此大小的文件将被跳过。设置为 None 禁用最大文件大小过滤。 |
None
|