vndb/protocol/message/response/results.rs
1//! VNDB entities types.
2use serde::{Serialize, Deserialize};
3use serde::de::Error;
4
5#[derive(Deserialize, Serialize, Debug)]
6///Links for VN.
7///
8///All fields may be omitted by VNDB.
9pub struct VnLinks {
10 ///Wikipedia identifier for the VN
11 pub wikidata: Option<String>,
12 ///The name part of the url on renai.us.
13 pub renai: Option<String>
14}
15
16#[derive(Deserialize, Serialize, Debug)]
17///Anime related to the VN.
18///
19///All fields, except `id`, may be omitted by VNDB.
20pub struct VnAnime {
21 ///[AniDB](http://anidb.net/) ID
22 pub id: u64,
23 ///[AnimeNewsNetwork](http://animenewsnetwork.com/) ID
24 pub ann_id: Option<u64>,
25 ///[AnimeNfo](http://animenfo.com/) ID
26 pub nfo_id: Option<u64>,
27 ///Anime's title in romaji.
28 pub title_romaji: Option<String>,
29 ///Anime's title in kanji.
30 pub title_kanji: Option<String>,
31 ///Year in which anime was aired.
32 pub year: Option<u16>,
33 #[serde(rename = "type")]
34 ///Anime's type.
35 pub kind: Option<String>
36}
37
38///Related VN.
39#[derive(Deserialize, Serialize, Debug)]
40pub struct VnRelation {
41 ///VN's ID.
42 pub id: u64,
43 ///Description of relation.
44 pub relation: String,
45 ///Title in romaji.
46 pub title: String,
47 ///Title in kanji.
48 pub original: Option<String>,
49 ///Whether it is official.
50 pub official: bool
51}
52
53#[derive(Deserialize, Serialize, Debug)]
54///VN's tag.
55pub struct VnTag {
56 ///ID.
57 pub id: u64,
58 ///Score from 0 to 3.
59 ///
60 ///Note that VNDB's scores are float numbers.
61 pub score: f32,
62 #[serde(rename = "spoiler level")]
63 ///Spoiler severity.
64 ///
65 ///Possible values:
66 ///* 0 - None;
67 ///* 1 - Minor;
68 ///* 2 - Major;
69 pub spoiler: u8
70}
71
72#[derive(Deserialize, Serialize, Debug)]
73///VN's image.
74pub struct VnScreen {
75 ///URL.
76 pub image: String,
77 ///Release's ID.
78 pub rid: u64,
79 ///Release's flags
80 pub flagging: Option<VnImageFlags>,
81 ///Image's height.
82 pub height: u16,
83 ///Image's width.
84 pub width: u16,
85}
86
87#[derive(Deserialize, Serialize, Debug)]
88///VN's staff.
89pub struct VnStaff {
90 #[serde(rename = "sid")]
91 ///Staff's ID.
92 pub id: u64,
93 #[serde(rename = "aid")]
94 ///Staff's Alias ID.
95 pub alias: u64,
96 ///Name.
97 pub name: String,
98 ///Name in native language.
99 pub original: Option<String>,
100 ///Role.
101 pub role: String,
102 ///Note.
103 pub note: Option<String>
104}
105
106#[derive(Deserialize, Serialize, Debug)]
107///Flags of the main VN image
108pub struct VnImageFlags {
109 ///number of flagging votes.
110 #[serde(rename = "votecount")]
111 pub vote_count: usize,
112 ///Sexual score between 0 (safe) and 2 (explicit).
113 pub sexual_avg: Option<f32>,
114 ///Violence score between 0 (tame) and 2 (brutal).
115 pub violence_avg: Option<f32>,
116}
117
118#[derive(Deserialize, Serialize, Debug)]
119///VN data representation. Returned by `get vn`
120pub struct Vn {
121 ///Unique identifier of VN.
122 pub id: u64,
123
124 //Basic
125 ///Main title.
126 ///
127 ///Provided when `basic` flag is specified.
128 pub title: Option<String>,
129 ///Title in original language.
130 ///
131 ///Optionally provided when `basic` flag is specified.
132 pub original: Option<String>,
133 ///Date of the first release.
134 ///
135 ///Optionally provided when `basic` flag is specified.
136 pub released: Option<String>,
137 #[serde(skip_serializing_if = "Vec::is_empty", default)]
138 ///Languages in which VN is available.
139 ///
140 ///Provided when `basic` flag is specified.
141 ///Can be empty array.
142 pub languages: Vec<String>,
143 #[serde(skip_serializing_if = "Vec::is_empty", default)]
144 ///Languages of the first release.
145 ///
146 ///Optionally provided when `basic` flag is specified.
147 ///Can be empty array.
148 pub orig_lang: Vec<String>,
149 #[serde(skip_serializing_if = "Vec::is_empty", default)]
150 ///Platforms on which VN is available.
151 ///
152 ///Optionally provided when `basic` flag is specified.
153 ///Can be empty array.
154 pub platforms: Vec<String>,
155
156 //Details
157 ///Aliases, separated by newline.
158 ///
159 ///Provided when `details` flag is specified.
160 ///Can be `None`.
161 pub aliases: Option<String>,
162 ///Length of the VN. Between 1-5.
163 ///
164 ///Provided when `details` flag is specified.
165 ///Can be `None`.
166 pub length: Option<u8>,
167 ///Description of the VN.
168 ///
169 ///Provided when `details` flag is specified.
170 ///Can be `None`.
171 pub description: Option<String>,
172 ///Links related to the VN.
173 ///
174 ///Provided when `details` flag is specified.
175 pub links: Option<VnLinks>,
176 ///HTTP link to VN image.
177 ///
178 ///Provided when `details` flag is specified.
179 ///Can be `None`.
180 pub image: Option<String>,
181 ///Flags of the `image`
182 pub image_flagging: Option<VnImageFlags>,
183
184 #[serde(skip_serializing_if = "Vec::is_empty", default)]
185 //Anime
186 ///List of anime related to the VN.
187 ///
188 ///Provided when `anime` flag is specified.
189 pub anime: Vec<VnAnime>,
190
191 #[serde(skip_serializing_if = "Vec::is_empty", default)]
192 //Relations
193 ///List of related VNs.
194 ///
195 ///Provided when `relations` flag is specified.
196 pub relations: Vec<VnRelation>,
197
198 #[serde(skip_serializing_if = "Vec::is_empty", default)]
199 //Tags
200 ///List of VN's tags
201 ///
202 ///Provided when `tags` flag is specified.
203 pub tags: Vec<VnTag>,
204
205 #[serde(default)]
206 //Stats
207 ///Popularity from 0 to 100.
208 ///
209 ///Provided when `stats` flag is specified.
210 pub popularity: f32,
211 ///VN's rating from 1 to 10.
212 ///
213 ///Provided when `stats` flag is specified.
214 pub rating: Option<f32>,
215 ///Number of votes
216 ///
217 ///Provided when `stats` flag is specified.
218 pub votecount: Option<u64>,
219
220 #[serde(skip_serializing_if = "Vec::is_empty", default)]
221 //Screens
222 ///List of screenshots
223 ///
224 ///Provided when `screens` flag is specified.
225 pub screens: Vec<VnScreen>,
226
227 #[serde(skip_serializing_if = "Vec::is_empty", default)]
228 //Staff
229 ///List of Staff members.
230 ///
231 ///Provided when `staff` flag is specified.
232 pub staff: Vec<VnStaff>,
233}
234
235#[derive(Deserialize, Serialize, Debug)]
236///Type of media for the release.
237pub struct ReleaseMedia {
238 ///Name.
239 pub medium: String,
240 ///Quantity.
241 #[serde(rename = "qty")]
242 pub quantity: Option<u32>
243}
244
245#[derive(Deserialize, Serialize, Debug)]
246///Related to release VN.
247pub struct ReleaseVN {
248 ///VN's id.
249 pub id: u64,
250 ///VN's title.
251 pub title: String,
252 ///Vn's title in original language.
253 pub original: Option<String>
254}
255
256#[derive(Deserialize, Serialize, Debug)]
257///Related to release producers.
258pub struct ReleaseProducer {
259 ///Producer's id.
260 pub id: u64,
261 ///Whether developer or not.
262 pub developer: bool,
263 ///Whether publisher or not.
264 pub publisher: bool,
265 ///Producer's name in romaji.
266 pub name: String,
267 ///Producer's name in original language.
268 pub original: Option<String>,
269 #[serde(rename = "type")]
270 ///Producer's type
271 pub kind: String,
272}
273
274#[derive(Deserialize, Serialize, Debug)]
275///Release data representation. Returned by `get release`
276pub struct Release {
277 ///Unique identifier of Release.
278 pub id: u64,
279
280 //Basic
281 ///Main title.
282 ///
283 ///Provided when `basic` flag is specified.
284 pub title: Option<String>,
285 ///Title in original language.
286 ///
287 ///Optionally provided when `basic` flag is specified.
288 pub original: Option<String>,
289 ///Date of the first release.
290 ///
291 ///Optionally provided when `basic` flag is specified.
292 pub released: Option<String>,
293 #[serde(rename = "type")]
294 ///Type of release: "complete", "partial" or "trial".
295 ///
296 ///Optionally provided when `basic` flag is specified.
297 pub kind: Option<String>,
298 ///Whether it is a patch or not.
299 ///
300 ///Optionally provided when `basic` flag is specified.
301 pub patch: Option<bool>,
302 ///Whether it is a freeware or not.
303 ///
304 ///Optionally provided when `basic` flag is specified.
305 pub freeware: Option<bool>,
306 ///Whether it is a doujin or not.
307 ///
308 ///Optionally provided when `basic` flag is specified.
309 pub doujin: Option<bool>,
310 #[serde(skip_serializing_if = "Vec::is_empty", default)]
311 ///Languages in which release is available.
312 ///
313 ///Provided when `basic` flag is specified.
314 ///Can be empty array.
315 pub languages: Vec<String>,
316
317 //Details
318 ///URL to website.
319 ///
320 ///Optionally provided when `details` flag is specified.
321 pub website: Option<String>,
322 ///Some notes.
323 ///
324 ///Optionally provided when `details` flag is specified.
325 pub notes: Option<String>,
326 #[serde(rename = "minage")]
327 ///Age rating. 0 is all-age.
328 ///
329 ///Optionally provided when `details` flag is specified.
330 pub age: Option<u8>,
331 #[serde(rename = "gtin")]
332 ///JAN/UPC/EAN code.
333 ///
334 ///Optionally provided when `details` flag is specified.
335 pub code: Option<String>,
336 ///Catalogue number.
337 ///
338 ///Optionally provided when `details` flag is specified.
339 pub catalog: Option<String>,
340 #[serde(skip_serializing_if = "Vec::is_empty", default)]
341 ///Platforms on which release is available.
342 ///
343 ///Optionally provided when `details` flag is specified.
344 ///Can be empty array.
345 pub platforms: Vec<String>,
346 #[serde(skip_serializing_if = "Vec::is_empty", default)]
347 ///Release's media.
348 ///
349 ///Optionally provided when `details` flag is specified.
350 pub media: Vec<ReleaseMedia>,
351 ///Resolution.
352 ///
353 ///Optionally provided when `details` flag is specified.
354 pub resolution: Option<String>,
355 ///Voice type available.
356 ///
357 ///1 = Not voiced, 2 = Only ero scenes voiced, 3 = Partially voiced, 4 = Fully voiced
358 ///
359 ///Optionally provided when `details` flag is specified.
360 pub voiced: Option<u8>,
361 ///Animation status.
362 ///
363 ///Optionally provided when `details` flag is specified.
364 pub animation: Option<[u8; 2]>,
365 #[serde(skip_serializing_if = "Vec::is_empty", default)]
366 ///Related VNs.
367 ///
368 ///Optionally provided when `vn` flag is specified.
369 pub vn: Vec<ReleaseVN>,
370 #[serde(skip_serializing_if = "Vec::is_empty", default)]
371 ///Related producers.
372 ///
373 ///Optionally provided when `producer` flag is specified.
374 pub producers: Vec<ReleaseProducer>,
375}
376
377#[derive(Deserialize, Serialize, Debug)]
378///External links related for [Producer](struct.Prodcer.html)
379pub struct ProducerLinks {
380 ///Official homepage.
381 pub homepage: Option<String>,
382 ///Wikidata identifier.
383 pub wikidata: Option<String>
384}
385
386#[derive(Deserialize, Serialize, Debug)]
387///External links related for [Producer](struct.Prodcer.html)
388pub struct ProducerRelation {
389 ///Unique identifier of Producer.
390 pub id: u64,
391 ///Relation to [Producer](struct.Prodcer.html).
392 pub relation: String,
393 ///Name(romaji).
394 pub name: String,
395 ///Name in original language.
396 pub original: Option<String>
397}
398
399#[derive(Deserialize, Serialize, Debug)]
400///Producer data representation. Returned by `get producer`
401pub struct Producer {
402 ///Unique identifier of Producer.
403 pub id: u64,
404
405 //Basic
406 ///Name(romaji).
407 ///
408 ///Provided when `basic` flag is specified.
409 pub name: Option<String>,
410 ///Name in original language.
411 ///
412 ///Optionally provided when `basic` flag is specified.
413 pub original: Option<String>,
414 #[serde(rename = "type")]
415 ///Type.
416 ///
417 ///Provided when `basic` flag is specified.
418 pub kind: Option<String>,
419 ///Primary language.
420 ///
421 ///Provided when `basic` flag is specified.
422 pub language: Option<String>,
423
424 //Details
425 ///Related links.
426 ///
427 ///Provided when `details` flag is specified.
428 pub links: Option<ProducerLinks>,
429 ///Aliases, separated by newline.
430 ///
431 ///Optionally provided when `details` flag is specified.
432 pub aliases: Option<String>,
433 ///Description/notes on producer.
434 ///
435 ///Optionally provided when `details` flag is specified.
436 pub description: Option<String>,
437
438 #[serde(skip_serializing_if = "Vec::is_empty", default)]
439 //Relations
440 ///List of related producers.
441 ///
442 ///Provided when `relations` flag is specified.
443 pub relations: Vec<ProducerRelation>,
444}
445
446#[derive(Debug)]
447///[Character](struct.Character.html)'s gender
448pub enum CharacterGender {
449 ///Male gender.
450 Male,
451 ///Female gender.
452 Female,
453 ///Both genders?
454 Both
455}
456
457impl<'de> Deserialize<'de> for CharacterGender {
458 fn deserialize<D: serde::de::Deserializer<'de>>(gender: D) -> Result<Self, D::Error> {
459 let gender: &'de str = Deserialize::deserialize(gender)?;
460 match gender {
461 "m" => Ok(CharacterGender::Male),
462 "f" => Ok(CharacterGender::Female),
463 "b" => Ok(CharacterGender::Both),
464 _ => Err(D::Error::custom(format_args!("Unknown type '{}' of character gender.", gender)))
465 }
466 }
467}
468
469impl Serialize for CharacterGender {
470 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
471 match *self {
472 CharacterGender::Male => serializer.serialize_str("m"),
473 CharacterGender::Female => serializer.serialize_str("f"),
474 CharacterGender::Both => serializer.serialize_str("b")
475 }
476 }
477}
478
479#[derive(Deserialize, Serialize, Debug)]
480///Character's Voice Actress.
481pub struct CharacterSeiyuu {
482 ///Unique identifier of staff.
483 pub id: u64,
484 ///Alias identifier of staff.
485 pub aid: u64,
486 ///VN identifier.
487 pub vid: u64,
488 ///Note
489 pub note: String,
490}
491
492#[derive(Deserialize, Serialize, Debug)]
493///Character data representation. Returned by `get character`
494pub struct Character {
495 ///Unique identifier of Character.
496 pub id: u64,
497
498 //Basic
499 ///Name(romaji).
500 ///
501 ///Provided when `basic` flag is specified.
502 pub name: Option<String>,
503 ///Name in original language.
504 ///
505 ///Optionally provided when `basic` flag is specified.
506 pub original: Option<String>,
507 ///Character's gender.
508 ///
509 ///Optionally provided when `basic` flag is specified.
510 pub gender: Option<CharacterGender>,
511 ///Blood type.
512 ///
513 ///Optionally provided when `basic` flag is specified.
514 #[serde(rename = "bloodt")]
515 pub blood_type: Option<String>,
516 ///Birthday as tuple `(day, month)`
517 ///
518 ///Provided when `basic` flag is specified.
519 pub birthday: Option<(u8, u8)>,
520
521 //Details
522 ///Aliases, separated by newline.
523 ///
524 ///Provided when `details` flag is specified.
525 pub aliases: Option<String>,
526 ///Description/notes.
527 ///
528 ///Optionally provided when `details` flag is specified.
529 pub description: Option<String>,
530 ///URL to image.
531 ///
532 ///Optionally provided when `details` flag is specified.
533 pub image: Option<String>,
534
535 //Meas
536 ///Bust in cm.
537 ///
538 ///Optionally provided when `meas` flag is specified.
539 pub bust: Option<u16>,
540 ///Waist in cm.
541 ///
542 ///Optionally provided when `meas` flag is specified.
543 pub waist: Option<u16>,
544 ///Hip in cm.
545 ///
546 ///Optionally provided when `meas` flag is specified.
547 pub hip: Option<u16>,
548 ///Height in cm.
549 ///
550 ///Optionally provided when `meas` flag is specified.
551 pub height: Option<u16>,
552 ///Weight in kg.
553 ///
554 ///Optionally provided when `meas` flag is specified.
555 pub weight: Option<u16>,
556
557 #[serde(skip_serializing_if = "Vec::is_empty", default)]
558 //Traits
559 ///List, possibly empty, of traits specified as tuple `(id, spoiler level)`.
560 ///
561 ///Provided when `traits` flag is specified.
562 pub traits: Vec<(u64, u8)>,
563
564 #[serde(skip_serializing_if = "Vec::is_empty", default)]
565 ///List, possibly empty, of related VNs specified as tuple `(vn id, release id, spoiler level, role)`.
566 ///
567 ///Provided when `vns` flag is specified.
568 pub vns: Vec<(u64, u64, u8, String)>,
569
570 #[serde(skip_serializing_if = "Vec::is_empty", default)]
571 ///List, possibly empty, of related VNs specified as tuple `(vn id, release id, spoiler level, role)`.
572 ///
573 ///Provided when `voiced` flag is specified.
574 pub voiced: Vec<CharacterSeiyuu>,
575}
576
577#[derive(Deserialize, Serialize, Debug)]
578///User data representation. Returned by `get user`
579pub struct User {
580 ///Unique identifier of User.
581 ///
582 ///Provided when `basic` flag is specified.
583 pub id: Option<u64>,
584 ///User's name.
585 ///
586 ///Provided when `basic` flag is specified.
587 #[serde(rename = "username")]
588 pub name: Option<String>,
589}
590
591#[derive(Deserialize, Serialize, Debug)]
592///Vote list data representation. Returned by `get user`
593pub struct VoteList {
594 ///Unique identifier of User.
595 ///
596 ///Provided when `basic` flag is specified.
597 pub uid: Option<u64>,
598 ///Unique identifier of VN.
599 ///
600 ///Provided when `basic` flag is specified.
601 pub vn: Option<u64>,
602 ///Vote value in range from 10 to 100.
603 ///
604 ///Provided when `basic` flag is specified.
605 pub vote: Option<u8>,
606 ///Unix timestamp of when this vote is added.
607 ///
608 ///Provided when `basic` flag is specified.
609 pub added: Option<u64>,
610}
611
612#[derive(Copy, Clone, Debug)]
613///Status in [VnList](struct.VnList.html).
614pub enum VnStatus {
615 ///Unknown.
616 Unknown = 0,
617 ///Currently playing.
618 Playing = 1,
619 ///Finished.
620 Finished = 2,
621 ///Stalled.
622 Stalled = 3,
623 ///Dropped.
624 Dropped = 4
625}
626
627impl<'de> Deserialize<'de> for VnStatus {
628 fn deserialize<D: serde::de::Deserializer<'de>>(status: D) -> Result<Self, D::Error> {
629 let status: u8 = Deserialize::deserialize(status)?;
630 match status {
631 0 => Ok(VnStatus::Unknown),
632 1 => Ok(VnStatus::Playing),
633 2 => Ok(VnStatus::Finished),
634 3 => Ok(VnStatus::Stalled),
635 4 => Ok(VnStatus::Dropped),
636 _ => Err(D::Error::custom(format_args!("Unknown type '{}' of VN's status.", status)))
637 }
638 }
639}
640
641impl Serialize for VnStatus {
642 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
643 serializer.serialize_u8(*self as u8)
644 }
645}
646
647#[derive(Deserialize, Serialize, Debug)]
648///Vote list data representation. Returned by `get user`
649pub struct VnList {
650 ///Unique identifier of User.
651 ///
652 ///Provided when `basic` flag is specified.
653 pub uid: Option<u64>,
654 ///Unique identifier of VN.
655 ///
656 ///Provided when `basic` flag is specified.
657 pub vn: Option<u64>,
658 ///Status of VN.
659 pub status: Option<VnStatus>,
660 #[serde(default)]
661 ///Unix timestamp of when this vote is added.
662 ///
663 ///Provided when `basic` flag is specified.
664 pub added: u64,
665 ///User's notes.
666 ///
667 ///Optionally provided when `basic` flag is specified.
668 pub notes: Option<String>
669}
670
671#[derive(Deserialize, Serialize, Debug)]
672///Vote list data representation. Returned by `get user`
673pub struct UList {
674 ///Unique identifier of User.
675 ///
676 ///Provided when `basic` flag is specified.
677 pub uid: Option<u64>,
678 ///Unique identifier of VN.
679 ///
680 ///Provided when `basic` flag is specified.
681 pub vn: Option<u64>,
682 #[serde(default)]
683 ///Unix timestamp of when this item has been added.
684 ///
685 ///Provided when `basic` flag is specified.
686 pub added: u64,
687 #[serde(rename = "lastmod", default)]
688 ///Unix timestamp of when this item has been last modified.
689 ///
690 ///Provided when `basic` flag is specified.
691 pub last_mod: u64,
692 #[serde(default)]
693 ///Unix timestamp when the vote has been cast.
694 ///
695 ///Provided when `basic` flag is specified.
696 pub voted: u64,
697 ///Vote value in range from 10 to 100.
698 ///
699 ///Provided when `basic` flag is specified.
700 pub vote: Option<u8>,
701 ///User's notes.
702 ///
703 ///Optionally provided when `basic` flag is specified.
704 pub notes: Option<String>
705}