rusty_booru/danbooru/
mod.rs

1pub mod client;
2
3use derive_more::From;
4use serde::{Deserialize, Serialize};
5use strum::Display;
6
7use crate::generic::{BooruPost, Rating};
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
10pub struct DanbooruPost {
11    pub id: u32,
12    pub created_at: String,
13    pub updated_at: String,
14    pub uploader_id: u32,
15    pub approver_id: Option<u32>,
16    pub tag_string: String,
17    pub tag_string_general: String,
18    pub tag_string_artist: String,
19    pub tag_string_copyright: String,
20    pub tag_string_character: String,
21    pub tag_string_meta: String,
22    pub rating: Option<DanbooruRating>,
23    pub parent_id: Option<u32>,
24    pub pixiv_id: Option<u32>,
25    pub source: String,
26    pub md5: Option<String>,
27    pub file_url: Option<String>,
28    pub large_file_url: Option<String>,
29    pub preview_file_url: Option<String>,
30    pub file_ext: String,
31    pub file_size: u32,
32    pub image_width: u32,
33    pub image_height: u32,
34    pub score: i32,
35    pub up_score: i32,
36    pub down_score: i32,
37    pub fav_count: u32,
38    pub tag_count_general: u32,
39    pub tag_count_artist: u32,
40    pub tag_count_copyright: u32,
41    pub tag_count_character: u32,
42    pub tag_count_meta: u32,
43    pub last_comment_bumped_at: Option<String>,
44    pub last_noted_at: Option<String>,
45    pub has_large: bool,
46    pub has_children: bool,
47    pub has_visible_children: bool,
48    pub has_active_children: bool,
49    pub is_banned: bool,
50    pub is_deleted: bool,
51    pub is_flagged: bool,
52    pub is_pending: bool,
53    pub bit_flags: u32,
54}
55
56/// Post's rating. Check the [Danbooru's ratings wiki](https://danbooru.donmai.us/wiki_pages/howto:rate)
57#[derive(Serialize, Deserialize, Debug, Clone, Display, From)]
58#[serde(rename_all = "lowercase")]
59#[strum(serialize_all = "lowercase")]
60pub enum DanbooruRating {
61    #[serde(rename = "e")]
62    Explicit,
63    #[serde(rename = "q")]
64    Questionable,
65    #[serde(rename = "s")]
66    Sensitive,
67    #[serde(rename = "g")]
68    General,
69}
70
71impl From<Rating> for DanbooruRating {
72    fn from(value: Rating) -> Self {
73        match value {
74            Rating::Explicit => Self::Explicit,
75            Rating::Questionable => Self::Questionable,
76            Rating::Safe => Self::General,
77            Rating::Sensitive => Self::Sensitive,
78            Rating::General => Self::General,
79        }
80    }
81}
82
83impl From<DanbooruRating> for Rating {
84    fn from(value: DanbooruRating) -> Self {
85        match value {
86            DanbooruRating::Explicit => Rating::Explicit,
87            DanbooruRating::Questionable => Rating::Questionable,
88            DanbooruRating::Sensitive => Rating::Sensitive,
89            DanbooruRating::General => Rating::General,
90        }
91    }
92}
93
94impl From<DanbooruPost> for BooruPost {
95    fn from(value: DanbooruPost) -> Self {
96        Self {
97            id: value.id,
98            created_at: value.created_at.into(),
99            score: value.score.into(),
100            width: value.image_width,
101            height: value.image_height,
102            md5: value.md5,
103            file_url: value.file_url,
104            tags: value.tag_string,
105            image: None,
106            source: value.source.into(),
107            rating: value.rating.unwrap_or(DanbooruRating::Sensitive).into(),
108        }
109    }
110}