-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2fd4e4
commit 34c6b3f
Showing
12 changed files
with
165 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct Tag { | ||
tag: String, | ||
tag_type: TagType, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub enum TagType { | ||
Author, | ||
Copyright, | ||
Character, | ||
/// Exclusive to e621/926 | ||
Species, | ||
General, | ||
/// Exclusive to e621/926 | ||
Lore, | ||
Meta, | ||
} | ||
|
||
impl Tag { | ||
pub fn new(text: &str, tag_type: TagType) -> Self { | ||
Self { | ||
tag: text.to_string(), | ||
tag_type, | ||
} | ||
} | ||
|
||
pub fn tag(&self) -> String { | ||
self.tag.clone() | ||
} | ||
|
||
pub fn tag_type(&self) -> TagType { | ||
self.tag_type | ||
} | ||
|
||
pub fn is_prompt_tag(&self) -> bool { | ||
match self.tag_type { | ||
TagType::Author | TagType::Copyright | TagType::Lore | TagType::Meta => false, | ||
TagType::Character | TagType::Species | TagType::General => true, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,50 @@ | ||
use ibdl_common::serde::{self, Deserialize, Serialize}; | ||
use ibdl_common::{ | ||
post::tags::{Tag, TagType}, | ||
serde::{self, Deserialize, Serialize}, | ||
}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(crate = "self::serde")] | ||
pub struct DanbooruPost { | ||
pub id: Option<u64>, | ||
pub md5: Option<String>, | ||
pub file_url: Option<String>, | ||
pub tag_string: Option<String>, | ||
pub tag_string_general: Option<String>, | ||
pub tag_string_character: Option<String>, | ||
pub tag_string_copyright: Option<String>, | ||
pub tag_string_artist: Option<String>, | ||
pub tag_string_meta: Option<String>, | ||
pub file_ext: Option<String>, | ||
pub rating: Option<String>, | ||
} | ||
|
||
impl DanbooruPost { | ||
pub fn map_tags(&self) -> Vec<Tag> { | ||
let mut tags = Vec::with_capacity(64); | ||
if let Some(tagstr) = &self.tag_string_artist { | ||
tags.extend(tagstr.split(' ').map(|tag| Tag::new(tag, TagType::Author))) | ||
} | ||
if let Some(tagstr) = &self.tag_string_copyright { | ||
tags.extend( | ||
tagstr | ||
.split(' ') | ||
.map(|tag| Tag::new(tag, TagType::Copyright)), | ||
) | ||
} | ||
if let Some(tagstr) = &self.tag_string_character { | ||
tags.extend( | ||
tagstr | ||
.split(' ') | ||
.map(|tag| Tag::new(tag, TagType::Character)), | ||
) | ||
} | ||
if let Some(tagstr) = &self.tag_string_general { | ||
tags.extend(tagstr.split(' ').map(|tag| Tag::new(tag, TagType::General))) | ||
} | ||
if let Some(tagstr) = &self.tag_string_meta { | ||
tags.extend(tagstr.split(' ').map(|tag| Tag::new(tag, TagType::Meta))) | ||
} | ||
|
||
tags | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters