Resource (资源)¶
资源模型包括 Resource(项目级其他材料)、VideoResource(视频关联资源)、Manga(漫画)和 Novel(小说)。
Resource (项目级资源/其他材料)¶
项目级资源文件,如设定资料、参考资料、OCR 材料、翻译表源文件等。
获取项目资源¶
for resource in project.resources(file_type="resources"):
print(f"{resource.name} ({resource.file_type})")
属性¶
| 属性 | 类型 | 说明 |
|---|---|---|
id |
str |
唯一标识 |
name |
str |
资源名称 |
description |
str | None |
描述 |
file_path |
str |
文件路径 |
file_type |
str |
文件类型 |
file_size |
int |
文件大小(字节) |
mime_type |
str | None |
MIME 类型 |
folder_path |
str | None |
文件夹路径 |
file_url |
str |
下载 URL |
owner_id |
str |
所有者 ID |
project_id |
str |
项目 ID |
created_at |
datetime |
创建时间 |
updated_at |
datetime |
更新时间 |
extra |
dict |
后端返回的额外字段 |
创建与更新¶
完整接口见 CRUD 与更新接口 - 资源与其他材料。
resource = project.create_resource(
name="Character settings",
file_path="materials/characters.pdf",
file_type="resources",
folder_path="materials",
)
client.update_resource(resource.id, description="Updated notes")
client.delete_resource(resource.id)
方法¶
VideoResource (视频资源)¶
视频关联的资源文件,如剧本、脚本、香盘表等。
获取视频资源¶
属性¶
| 属性 | 类型 | 说明 |
|---|---|---|
id |
str |
唯一标识 |
resource_id |
str |
资源 ID |
role |
ResourceRole |
资源角色/类型 |
note |
str | None |
备注 |
file_url |
str |
文件下载 URL |
name |
str |
资源名称 |
mime_type |
str | None |
MIME 类型 |
extra |
dict |
后端返回的额外字段 |
ResourceRole 资源类型¶
| 值 | 说明 |
|---|---|
ResourceRole.SCRIPT |
剧本 |
ResourceRole.SCREENPLAY |
脚本 |
ResourceRole.PROP_LIST |
香盘表 |
ResourceRole.OTHER |
其他 |
方法¶
CommonResource (通用资源基类)¶
Manga 和 Novel 的基类,包含通用的资源属性。
属性¶
| 属性 | 类型 | 说明 |
|---|---|---|
id |
str |
唯一标识 |
title |
str |
标题 |
author |
str | None |
作者 |
category |
str | None |
分类 |
tags |
list[str] | None |
标签 |
description |
str | None |
描述 |
sort_order |
int |
排序序号 |
resource_id |
str |
资源 ID |
project_id |
str |
项目 ID |
owner_id |
str |
所有者 ID |
file_name |
str |
文件名 |
file_size |
int |
文件大小(字节) |
file_url |
str |
下载 URL |
mime_type |
str | None |
MIME 类型 |
extra |
dict |
后端返回的额外字段 |
created_at |
datetime |
创建时间 |
updated_at |
datetime |
更新时间 |
Manga (漫画)¶
继承自 CommonResource,代表漫画资源。
for manga in project.mangas():
print(f"{manga.title} by {manga.author}")
print(f" 文件: {manga.file_name} ({manga.file_size} bytes)")
manga.save(f"output/{manga.file_name}")
Novel (小说)¶
继承自 CommonResource,代表小说资源,并额外包含 is_searchable: bool。
for novel in project.novels():
print(f"{novel.title} by {novel.author}")
novel.save(f"output/{novel.file_name}")
Manga / Novel 写入接口¶
漫画、小说的创建、更新、删除,以及小说检索、段落上下文和处理状态接口见 CRUD 与更新接口 - 漫画与小说资料。
manga = client.create_manga(project.id, title="Volume 1", resource_id="resource_id")
client.update_manga(manga["id"], tags=["volume-1"])
novel = client.create_novel(
project.id,
title="Episode draft",
resource_id="resource_id",
is_searchable=True,
)
client.update_novel(novel["id"], description="Revised draft")
下载方法¶
所有资源模型都支持以下下载方法:
| 方法 | 返回类型 | 说明 |
|---|---|---|
save(path) |
None |
下载并保存到指定路径 |
save_bytes() |
bytes |
获取文件字节数据 |