跳转至

参考

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:pip install ktoolbox[winloop] Unix 下安装 uvloop:pip install ktoolbox[uvloop]

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

文件名解析和帖子 内容external_links 保存的字符集

'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 的反向代理格式。通过插入空的 {} 自定义文件名格式以表示原始 URL。 例如:https://example.com/{} 会变成 https://example.com/https://n1.kemono.su/data/66/83/xxxxx.jpghttps://example.com/?url={} 会变成 https://example.com/?url=https://n1.kemono.su/data/66/83/xxxxx.jpg

'{}'
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

帖子 file 文件名的格式(file 不是 attachment,每个帖子只有一个 file,通常为封面图片)。 通过插入空的 {} 自定义文件名格式。可使用 属性。 例如:{title}_{} 可能生成 TheTitle_Stelle_lv5_logo.gifTheTitle_ScxHjZIdxt5cnjaAwf3ql2p7.jpg 等文件名。 同时,你也可以使用 Python 格式规格迷你语言的格式化功能,例如:{title:.6}_{} 可以将标题长度缩短为 6 个字符, 像 HiEveryoneThisIsALongTitle_ScxHjZIdxt5cnjaAwf3ql2p7.jpg 会变成 HiEver_ScxHjZIdxt5cnjaAwf3ql2p7.jpg

'{id}_{}'
revisions Path

修订目录的子路径

Path('revisions')

JobConfiguration

下载任务配置

  • post_dirname_formatfilename_format 可用属性

    属性 类型
    id 字符串
    user 字符串
    service 字符串
    title 字符串
    added 日期
    published 日期
    edited 日期
  • year_dirname_formatmonth_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

自定义帖子目录名格式,可使用 属性。 例如:[{published}]{id} 可以生成类似 [2024-1-1]123123 的目录名, {user}_{published}_{title} 可以生成类似 234234_2024-1-1_TheTitle 的目录名。 同时,你也可以使用 Python 格式规格迷你语言的格式化功能,例如:{title:.6} 可以将标题长度缩短为 6 个字符,像 HiEveryoneThisIsALongTitle 会变成 HiEver

'{title}'
post_structure PostStructureConfiguration

帖子路径结构

PostStructureConfiguration()
mix_posts bool

在创作者目录下将不同帖子的所有文件保存到同一路径,不创建帖子目录,且不会记录 CreatorIndices

False
sequential_filename bool

附件按数字顺序重命名,如 1.png2.png

False
sequential_filename_excludes Set[str]

启用 sequential_filename 时排除按顺序命名的文件扩展名,这些文件将保留原始名称。例如 [".psd", ".zip", ".mp4"]

Field(default_factory=set)
filename_format str

通过插入空的 {} 自定义文件名格式,表示基本文件名。可使用 属性。 例如:{title}_{} 可能生成 TheTitle_b4b41de2-8736-480d-b5c3-ebf0d917561bTheTitle_af349b25-ac08-46d7-98fb-6ce99a237b90 等。 也可与 sequential_filename 结合使用,如 [{published}]_{} 可能生成 [2024-1-1]_1.png[2024-1-1]_2.png 等。 同时,你也可以使用 Python 格式规格迷你语言的格式化功能,例如:{title:.6} 可以将标题长度缩短为 6 个字符,像 HiEveryoneThisIsALongTitle 会变成 HiEver

'{}'
allow_list Set[str]

下载匹配这些模式(Unix shell 风格)的文件,如 ["*.png"]

Field(default_factory=set)
block_list Set[str]

不下载匹配这些模式(Unix shell 风格)的文件,如 ["*.psd","*.zip"]

Field(default_factory=set)
extract_content bool

提取帖子内容并保存到单独文件(文件名由 config.job.post_structure.content 定义)

False
extract_external_links bool

从帖子内容中提取外部文件分享链接并保存到单独文件(文件名由 config.job.post_structure.external_links 定义)

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。例如:{year} > 2024Year_{year} > Year_2024

'{year}'
month_dirname_format str

自定义月份目录名格式。可用属性:yearmonth。例如:{year}-{month} > 2024-01{year}_{month} > 2024_01

'{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

LoggerConfiguration

日志配置

Attributes:

Name Type Description Default
path Optional[Path]

日志保存路径,None 表示不输出日志文件

None
level Union[str, int]

日志过滤级别

logging.getLevelName(logging.DEBUG)
rotation Union[str, int, time, timedelta]

日志轮换周期

'1 week'