Skip to content

Commit

Permalink
Add Koharu metadata support
Browse files Browse the repository at this point in the history
  • Loading branch information
LetrixZ committed Jul 11, 2024
1 parent 77fb740 commit 205e17c
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 27 deletions.
2 changes: 1 addition & 1 deletion server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
[package]
name = "server"
version = "1.1.2"
version = "1.1.3"
edition = "2021"

[dependencies]
anyhow = "1.0.86"
async_zip = { version = "0.0.17", features = ["full"] }
axum = { version = "0.7.5", features = ["macros"] }
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4.5.4", features = ["derive"] }
data-encoding = "2.6.0"
file-format = "0.25.0"
funty = "2.0.0"
globwalk = "0.9.1"
image = { version = "0.25.1", features = ["rayon"] }
indicatif = "0.17.8"
itertools = "0.13.0"
lava_torrent = "0.11.1"
natord = "1.0.9"
once_cell = "1.19.0"
rayon = "1.10.0"
regex = "1.10.4"
ring = "0.17.8"
serde = { version = "1.0.203", features = ["derive"] }
serde-inline-default = "0.2.0"
serde_json = "1.0.117"
serde_yaml = "0.9.34"
sha2 = "0.10.8"
slug = "0.1.5"
sqlx = { version = "0.7", features = ["postgres", "runtime-tokio", "chrono"] }
thiserror = "1.0.61"
time = "0.3.36"
tokio = { version = "1.38.0", features = ["full"] }
zip = "2.1.2"
tokio-util = { version = "0.7.11", features = ["io-util"] }
axum = { version = "0.7.5", features = ["macros"] }
toml = "0.8.14"
tower-http = { version = "0.5.2", features = ["trace", "cors"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
clap = { version = "4.5.4", features = ["derive"] }
ring = "0.17.8"
data-encoding = "2.6.0"
toml = "0.8.14"
serde-inline-default = "0.2.0"
regex = "1.10.4"
ureq = { version = "2.9.7", features = ["json"] }
url = "2.5.0"
file-format = "0.25.0"
funty = "2.0.0"
rayon = "1.10.0"
image = { version = "0.25.1", features = ["rayon"] }
thiserror = "1.0.61"
indicatif = "0.17.8"
time = "0.3.36"
webp = "0.3.0"
natord = "1.0.9"
lava_torrent = "0.11.1"
ureq = { version = "2.9.7", features = ["json"] }
zip = "2.1.2"
127 changes: 127 additions & 0 deletions server/src/metadata/koharu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use crate::{db, utils};
use serde::Deserialize;
use slug::slugify;

#[derive(Deserialize)]
pub struct Metadata {
pub title: String,
pub description: Option<String>,
pub source: Option<String>,
pub artist: Option<Vec<String>>,
pub circle: Option<Vec<String>>,
pub parody: Option<Vec<String>>,
pub magazine: Option<Vec<String>>,
pub event: Option<Vec<String>>,
pub general: Option<Vec<String>>,
pub female: Option<Vec<String>>,
pub male: Option<Vec<String>>,
pub mixed: Option<Vec<String>>,
pub other: Option<Vec<String>>,
pub language: Option<Vec<String>>,
pub url: Option<String>,
}

pub fn add_metadata(info: Metadata, archive: &mut db::UpsertArchiveData) -> anyhow::Result<()> {
archive.title = Some(info.title);
archive.slug = archive.title.as_ref().map(slugify);
archive.description = info.description;
archive.thumbnail = Some(1);

archive.artists = info.artist.map(|tags| {
tags
.iter()
.map(|tag| utils::capitalize_words(tag))
.collect()
});
archive.circles = info.circle.map(|tags| {
tags
.iter()
.map(|tag| utils::capitalize_words(tag))
.collect()
});
archive.magazines = info.magazine.map(|tags| {
tags
.iter()
.map(|tag| utils::capitalize_words(tag))
.collect()
});
archive.events = info.event.map(|tags| {
tags
.iter()
.map(|tag| utils::capitalize_words(tag))
.collect()
});
archive.parodies = info.parody.map(|tags| {
tags
.iter()
.map(|tag| utils::capitalize_words(tag))
.collect()
});

archive.language = info.language.and_then(|languages| {
languages
.first()
.map(|language| utils::capitalize_words(language))
});

let mut tags = vec![];

if let Some(general) = info.general {
general.into_iter().for_each(|tag| {
tags.push((utils::capitalize_words(&tag), "".to_string()));
});
}

if let Some(female) = info.female {
female.into_iter().for_each(|tag| {
tags.push((utils::capitalize_words(&tag), "female".to_string()));
});
}

if let Some(male) = info.male {
male.into_iter().for_each(|tag| {
tags.push((utils::capitalize_words(&tag), "male".to_string()));
});
}

if let Some(mixed) = info.mixed {
mixed.into_iter().for_each(|tag| {
tags.push((utils::capitalize_words(&tag), "mixed".to_string()));
});
}

if let Some(other) = info.other {
other.into_iter().for_each(|tag| {
tags.push((utils::capitalize_words(&tag), "other".to_string()));
});
}

if !tags.is_empty() {
archive.tags = Some(tags);
}

let mut sources = vec![];

if let Some(url) = info.url {
sources.push(db::ArchiveSource {
name: utils::parse_source_name(&url),
url: Some(url),
});
}

if let Some(url) = info.source {
sources.push(db::ArchiveSource {
name: utils::parse_source_name(&url),
url: Some(format!(
"https://koharu.to{}",
url.split(":").last().unwrap()
)),
});
}

if !sources.is_empty() {
archive.sources = Some(sources);
}

Ok(())
}
10 changes: 10 additions & 0 deletions server/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod eze;
mod gallerydl;
pub mod hentag;
mod hentainexus;
mod koharu;
mod koromo;

use crate::{
Expand Down Expand Up @@ -68,6 +69,7 @@ enum MetadataFormatYaml {
Anchira(String),
HentaiNexus(String),
CCDC06(String),
Koharu(String),
}

enum MetadataFormatJson {
Expand Down Expand Up @@ -95,6 +97,10 @@ fn handle_metadata_format(
let metadata = serde_yaml::from_str(&yaml)?;
ccdc06::add_metadata(metadata, archive)?
}
MetadataFormatYaml::Koharu(yaml) => {
let metadata = serde_yaml::from_str(&yaml)?;
koharu::add_metadata(metadata, archive)?
}
},
MetadataFormat::Json(json) => match json {
MetadataFormatJson::HenTag(json) => {
Expand All @@ -120,6 +126,10 @@ fn handle_metadata_format(
}

fn get_yaml_type(yaml: String) -> anyhow::Result<MetadataFormatYaml> {
if yaml.contains("title") || yaml.contains("general") {
return Ok(MetadataFormatYaml::Koharu(yaml));
}

if yaml.contains("DownloadSource") || yaml.contains("ThumbnailIndex") || yaml.contains("Files") {
return Ok(MetadataFormatYaml::CCDC06(yaml));
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub fn parse_source_name(str: &str) -> String {
"ExHentai".into()
} else if str.contains("hentag") {
"HenTag".into()
} else if str.contains("koharu") || str.contains("schale") {
"Koharu".into()
} else {
url::Url::parse(&str)
.ok()
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-kit",
"version": "1.1.2",
"version": "1.1.3",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
Binary file added web/src/assets/koharu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions web/src/lib/components/gallery-source.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script lang="ts">
import type { Source } from '$lib/models';
import Irodori from '$assets/irodori.webp';
import Fakku from '$assets/fakku.svg';
import Anchira from '$assets/anchira.webp';
import HentaiNexus from '$assets/hentainexus.webp';
import ExHentai from '$assets/exhentai.ico';
import Pixiv from '$assets/pixiv.webp';
import Fakku from '$assets/fakku.svg';
import HenTag from '$assets/hentag.webp';
import HentaiNexus from '$assets/hentainexus.webp';
import Irodori from '$assets/irodori.webp';
import Koharu from '$assets/koharu.png';
import Patreon from '$assets/patreon.webp';
import Pixiv from '$assets/pixiv.webp';
import ProjectHentai from '$assets/project-hentai.webp';
import HenTag from '$assets/hentag.webp';
import type { Source } from '$lib/models';
import IcBaselineQuestionMark from '~icons/ic/baseline-question-mark';
export let source: Source;
Expand All @@ -35,6 +36,8 @@
return ProjectHentai;
case 'hentag':
return HenTag;
case 'koharu':
return Koharu;
default:
return;
}
Expand Down

0 comments on commit 205e17c

Please sign in to comment.