bangumi_api/module/subject/
model.rs

1use serde::{Deserialize, Serialize};
2use serde_repr::{Deserialize_repr, Serialize_repr};
3
4use crate::module::{
5    character::model::CharacterType,
6    collection::model::CollectionStats,
7    model::{Image, InfoBox, SimpleImage},
8    person::model::{Person, PersonCareer, PersonType},
9};
10
11/// 条目类型枚举,用于区分不同类型的内容条目
12///
13/// 基于u8存储,对应不同类别的内容分类
14#[derive(Clone, Debug, PartialEq, Serialize_repr, Deserialize_repr)]
15#[repr(u8)]
16pub enum SubjectType {
17    /// 书籍
18    Book = 1,
19    /// 动画
20    Anime = 2,
21    /// 音乐
22    Music = 3,
23    /// 游戏
24    Game = 4,
25    /// 三次元
26    Real = 6,
27}
28
29/// 内容条目的核心数据结构,包含条目的详细信息
30///
31/// 存储各类内容(动画、书籍等)的完整属性信息
32#[derive(Clone, Debug, Serialize, Deserialize)]
33pub struct Subject {
34    /// 条目的唯一标识符
35    pub id: u32,
36    /// 条目的类型(如动画、书籍等)
37    pub r#type: SubjectType,
38    /// 条目的原始名称(通常为外文原名)
39    pub name: String,
40    /// 条目的中文名称
41    pub name_cn: String,
42    /// 条目的详细简介
43    pub summary: String,
44    /// 是否为系列作品
45    pub series: bool,
46    /// 是否包含不适宜内容(Not Safe For Work)
47    pub nsfw: bool,
48    /// 是否被锁定(禁止编辑)
49    pub locked: bool,
50    /// 条目相关日期(如发布日期、首播日期等,可选)
51    pub date: Option<String>,
52    /// 条目对应的平台(如游戏平台、播放平台等)
53    pub platform: String,
54    /// 条目的图片资源信息
55    pub images: Image,
56    /// 条目的信息框内容(结构化属性)
57    pub infobox: InfoBox,
58    /// 卷数(主要用于书籍类条目)
59    pub volumes: u32,
60    /// 集数(主要用于动画、剧集类条目)
61    pub eps: u32,
62    // pub total_episodes: u32, // 文档中存在 实际不存在
63    /// 条目的评分信息
64    pub rating: Rating,
65    /// 条目的收藏统计数据
66    pub collection: CollectionStats,
67    /// 元标签列表(系统级标签)
68    pub meta_tags: Vec<String>,
69    /// 用户标签列表(包含标签统计信息)
70    pub tags: Vec<SubjectTag>,
71}
72
73/// 条目标签结构体,包含标签信息及统计数据
74///
75/// 记录用户标记的标签及其相关计数
76#[derive(Clone, Debug, Serialize, Deserialize)]
77pub struct SubjectTag {
78    /// 标签名称
79    pub name: String,
80    /// 该标签的使用次数
81    pub count: u32,
82    /// 该标签的总贡献人数
83    pub total_cont: u32,
84}
85
86/// 每日日历条目结构体,用于展示每日更新的内容
87///
88/// 按星期分类,包含对应日期的内容条目列表
89#[derive(Clone, Debug, Serialize, Deserialize)]
90pub struct DailyCalendarItem {
91    /// 星期信息(多语言表示)
92    pub weekday: Weekday,
93    /// 当日的内容条目列表(精简信息)
94    pub items: Vec<SubjectSmall>,
95}
96
97/// 星期信息结构体,包含多语言表示及标识
98///
99/// 提供星期的多语言名称和唯一标识
100#[derive(Clone, Debug, Serialize, Deserialize)]
101pub struct Weekday {
102    /// 英文星期名称
103    pub en: String,
104    /// 中文星期名称
105    pub cn: String,
106    /// 日文星期名称
107    pub ja: String,
108    /// 星期标识ID(1-7)
109    pub id: u8,
110}
111
112/// 精简的条目信息结构体,用于列表展示
113///
114/// 包含条目核心信息,适用于列表、日历等场景
115#[derive(Clone, Debug, Serialize, Deserialize)]
116pub struct SubjectSmall {
117    /// 条目的唯一标识符
118    pub id: u32,
119    /// 条目的访问链接
120    pub url: String,
121    /// 条目的类型
122    pub r#type: SubjectType,
123    /// 条目的原始名称
124    pub name: String,
125    /// 条目的中文名称
126    pub name_cn: String,
127    /// 条目的简介
128    pub summary: String,
129    /// 播出/发布日期
130    pub air_date: String,
131    /// 播出星期(对应Weekday的id)
132    pub air_weekday: u8,
133    /// 条目的评分信息(可选)
134    pub rating: Option<SubjectSmallRating>,
135    /// 条目的排名(可选)
136    pub rank: Option<u32>,
137    /// 条目的图片资源信息
138    pub images: Image,
139    // 文档中存在 实际不存在
140    // pub eps: u32,
141    // pub eps_count: u32,
142    /// 条目的收藏统计数据(可选)
143    pub collection: Option<CollectionStats>,
144}
145
146/// 精简的条目评分信息结构体
147///
148/// 用于列表场景中的评分展示
149#[derive(Clone, Debug, Serialize, Deserialize)]
150pub struct SubjectSmallRating {
151    /// 总评分人数
152    pub total: u32,
153    /// 各评分等级的投票数量
154    pub count: RatingCount,
155    /// 平均分数
156    pub score: f64,
157}
158
159/// 评分分布统计结构体
160///
161/// 记录1-10分每个分数段的投票数量
162#[derive(Clone, Debug, Serialize, Deserialize)]
163pub struct RatingCount {
164    #[serde(rename = "1")]
165    pub param_1: u32, // 1分的投票数量
166    #[serde(rename = "2")]
167    pub param_2: u32, // 2分的投票数量
168    #[serde(rename = "3")]
169    pub param_3: u32, // 3分的投票数量
170    #[serde(rename = "4")]
171    pub param_4: u32, // 4分的投票数量
172    #[serde(rename = "5")]
173    pub param_5: u32, // 5分的投票数量
174    #[serde(rename = "6")]
175    pub param_6: u32, // 6分的投票数量
176    #[serde(rename = "7")]
177    pub param_7: u32, // 7分的投票数量
178    #[serde(rename = "8")]
179    pub param_8: u32, // 8分的投票数量
180    #[serde(rename = "9")]
181    pub param_9: u32, // 9分的投票数量
182    #[serde(rename = "10")]
183    pub param_10: u32, // 10分的投票数量
184}
185
186/// 条目搜索参数结构体
187///
188/// 用于构建条目搜索请求,包含关键词、排序和过滤条件
189#[derive(Clone, Debug, Serialize, Deserialize)]
190pub struct SubjectSearch {
191    /// 搜索关键词
192    pub keyword: String,
193    /// 排序方式(可选)
194    pub sort: Option<SubjectSearchSort>,
195    /// 过滤条件(可选)
196    pub filter: Option<SubjectSearchFilter>,
197}
198
199/// 条目搜索排序方式枚举
200///
201/// 定义搜索结果的排序规则
202#[derive(Clone, Debug, Serialize, Deserialize)]
203#[serde(rename_all = "lowercase")]
204pub enum SubjectSearchSort {
205    Match, // 按匹配度排序
206    Heat,  // 按热度排序
207    Rank,  // 按排名排序
208    Score, // 按评分排序
209}
210
211/// 条目搜索过滤条件结构体
212///
213/// 用于精确筛选搜索结果
214#[derive(Clone, Debug, Serialize, Deserialize)]
215pub struct SubjectSearchFilter {
216    /// 条目类型过滤(多选)
217    pub r#type: Vec<SubjectType>,
218    /// 元标签过滤(多选)
219    pub meta_tags: Vec<String>,
220    /// 标签过滤(多选)
221    pub tag: Vec<String>,
222    /// 播出日期过滤(多选)
223    pub air_date: Vec<String>,
224    /// 评分过滤(多选)
225    pub rating: Vec<String>,
226    /// 排名过滤(多选)
227    pub rank: Vec<String>,
228    /// 是否包含不适宜内容
229    pub nsfw: bool,
230}
231
232/// 完整的条目评分信息结构体
233///
234/// 包含评分统计的详细数据
235#[derive(Clone, Debug, Serialize, Deserialize)]
236pub struct Rating {
237    /// 条目排名
238    pub rank: u32,
239    /// 总评分人数
240    pub total: u32,
241    /// 各评分等级的投票数量
242    pub count: RatingCount,
243    /// 平均分数
244    pub score: f64,
245}
246
247/// 条目子分类枚举(无标签联合类型)
248///
249/// 根据条目主类型区分不同的子分类体系
250#[derive(Debug, Clone, Serialize, Deserialize)]
251#[serde(untagged)]
252pub enum SubjectCategory {
253    Book(SubjectBookCategory),   // 书籍类条目的子分类
254    Anime(SubjectAnimeCategory), // 动画类条目的子分类
255    Game(SubjectGameCategory),   // 游戏类条目的子分类
256    Real(SubjectRealCategory),   // 真人影视类条目的子分类
257}
258
259/// 书籍类条目的子分类枚举
260///
261/// 基于u16存储,细分书籍类型
262#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
263#[repr(u16)]
264pub enum SubjectBookCategory {
265    Other = 0,      // 其他书籍类型
266    Comic = 1001,   // 漫画
267    Novel = 1002,   // 小说
268    Artbook = 1003, // 画册/艺术书
269}
270
271/// 动画类条目的子分类枚举
272///
273/// 基于u16存储,细分动画类型
274#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
275#[repr(u16)]
276pub enum SubjectAnimeCategory {
277    Other = 0, // 其他动画类型
278    Tv = 1,    // 电视动画
279    Ova = 2,   // OVA(原创动画录像带)
280    Movie = 3, // 动画电影
281    Web = 5,   // 网络动画
282}
283
284/// 游戏类条目的子分类枚举
285///
286/// 基于u16存储,细分游戏类型
287#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
288#[repr(u16)]
289pub enum SubjectGameCategory {
290    Other = 0,        // 其他游戏类型
291    Game = 4001,      // 普通游戏
292    Software = 4002,  // 软件
293    Expansion = 4003, // 扩展包
294    BoardGame = 4005, // 桌游
295}
296
297/// 真人影视类条目的子分类枚举
298///
299/// 基于u16存储,细分真人影视类型
300#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
301#[repr(u16)]
302pub enum SubjectRealCategory {
303    Other = 0,             // 其他真人类型
304    JapaneseDrama = 1,     // 日剧
305    EuroAmericanDrama = 2, // 欧美剧
306    ChineseDrama = 3,      // 中剧
307    TvDrama = 6001,        // 电视剧
308    Movie = 6002,          // 电影
309    Performance = 6003,    // 表演/演出
310    VarietyShow = 6004,    // 综艺节目
311}
312
313/// 条目浏览排序方式枚举
314///
315/// 定义条目列表的排序规则
316#[derive(Debug, Clone, Serialize, Deserialize)]
317#[serde(rename_all = "lowercase")]
318pub enum SubjectBrowseSort {
319    Date, // 按日期排序
320    Rank, // 按排名排序
321}
322
323/// 与条目相关的人物信息结构体
324///
325/// 记录参与条目的人物及其关联信息
326#[derive(Debug, Clone, Serialize, Deserialize)]
327pub struct SubjectPerson {
328    /// 人物唯一标识符
329    pub id: u32,
330    /// 人物名称
331    pub name: String,
332    /// 人物类型
333    pub r#type: PersonType,
334    /// 人物职业列表
335    pub career: Vec<PersonCareer>,
336    /// 人物图片资源信息
337    pub images: SimpleImage,
338    /// 人物与条目的关系(如导演、声优等)
339    pub relation: String,
340    /// 参与的集数信息
341    pub eps: String,
342}
343
344/// 与条目相关的角色信息结构体
345///
346/// 记录条目中的角色及其配音演员信息
347#[derive(Debug, Clone, Serialize, Deserialize)]
348pub struct SubjectCharacter {
349    /// 角色唯一标识符
350    pub id: u32,
351    /// 角色名称
352    pub name: String,
353    /// 角色类型
354    pub r#type: CharacterType,
355    /// 角色图片资源信息
356    pub images: SimpleImage,
357    /// 角色与条目的关系
358    pub relation: String,
359    /// 配音演员列表
360    pub actors: Vec<Person>,
361}
362
363/// 与条目相关的其他条目信息结构体
364///
365/// 记录关联条目(如系列作品、衍生作品等)
366#[derive(Debug, Clone, Serialize, Deserialize)]
367pub struct SubjectSubject {
368    /// 关联条目的唯一标识符
369    pub id: u32,
370    /// 关联条目的类型
371    pub r#type: SubjectType,
372    /// 关联条目的原始名称
373    pub name: String,
374    /// 关联条目的中文名称
375    pub name_cn: String,
376    /// 关联条目的图片资源信息
377    pub images: Image,
378    /// 与当前条目的关系描述
379    pub relation: String,
380}