Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sources/zh.baozimanhua/Cargo.lock

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

1 change: 1 addition & 0 deletions sources/zh.baozimanhua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aidoku = { git = "https://github.com/Aidoku/aidoku-rs", features = ["json"] }
regex = { version = "1.11.1", default-features = false, features = ["unicode"] }
serde = { version = "1.0.219", default-features = false }
serde_json = { version = "1.0.140", default-features = false }
spin = "0.10.0"

[dev-dependencies]
aidoku = { git = "https://github.com/Aidoku/aidoku-rs.git", features = ["test"] }
Expand Down
2 changes: 1 addition & 1 deletion sources/zh.baozimanhua/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"info": {
"id": "zh.baozimanhua",
"name": "包子漫畫",
"version": 6,
"version": 7,
"urls": [
"https://www.webmota.com",
"https://cn.webmota.com",
Expand Down
49 changes: 22 additions & 27 deletions sources/zh.baozimanhua/src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,31 @@ use aidoku::{
prelude::*,
};
use regex::Regex;
use spin::Lazy;

// Compile the regexes once instead of per chapter to keep the details call
// fast on interpreted runtimes (see Aidoku-Community/sources#829).
static CHAPTER_RES: Lazy<[Regex; 3]> = Lazy::new(|| {
#[expect(clippy::unwrap_used)]
[
// This handles cases like "第183话 180" where 180 is the actual chapter
Regex::new(r"(?:第\s*\d+(?:\.\d+)?\s*(?:话|話|章|回|卷|册|冊)\s*)(\d+(?:\.\d+)?)").unwrap(),
// Second try: match "第X话" pattern where X is the chapter number
Regex::new(r"(?:第\s*)(\d+(?:\.\d+)?)\s*(?:话|話|章|回|卷|册|冊)").unwrap(),
// Third try: match pure number at the beginning
Regex::new(r"^(\d+(?:\.\d+)?)").unwrap(),
]
});

fn extract_chapter_number(title: &str) -> Option<f32> {
// This handles cases like "第183话 180" where 180 is the actual chapter
let re1 =
Regex::new(r"(?:第\s*\d+(?:\.\d+)?\s*(?:话|話|章|回|卷|册|冊)\s*)(\d+(?:\.\d+)?)").ok()?;
if let Some(captures) = re1.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
}

// Second try: match "第X话" pattern where X is the chapter number
let re2 = Regex::new(r"(?:第\s*)(\d+(?:\.\d+)?)\s*(?:话|話|章|回|卷|册|冊)").ok()?;
if let Some(captures) = re2.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
}

// Third try: match pure number at the beginning
let re3 = Regex::new(r"^(\d+(?:\.\d+)?)").ok()?;
if let Some(captures) = re3.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
for re in CHAPTER_RES.iter() {
if let Some(captures) = re.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
}
}

None
}

Expand Down
12 changes: 11 additions & 1 deletion sources/zh.bilimanga/Cargo.lock

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

1 change: 1 addition & 0 deletions sources/zh.bilimanga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2024"
aes = "0.8.4"
aidoku = { git = "https://github.com/Aidoku/aidoku-rs.git", version = "0.3.0", features = ["json"] }
regex = { version = "1.11.1", default-features = false, features = ["unicode"] }
spin = "0.10.0"

[dev-dependencies]
aidoku = { git = "https://github.com/Aidoku/aidoku-rs.git", features = ["test"] }
Expand Down
2 changes: 1 addition & 1 deletion sources/zh.bilimanga/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"info": {
"id": "zh.bilimanga",
"name": "嗶哩漫畫",
"version": 4,
"version": 5,
"url": "https://www.bilimanga.net",
"contentRating": 1,
"languages": ["zh"],
Expand Down
20 changes: 14 additions & 6 deletions sources/zh.bilimanga/src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ use aidoku::{
prelude::*,
};
use regex::Regex;
use spin::Lazy;

// Compile the regexes once instead of per chapter to keep the details call
// fast on interpreted runtimes (see Aidoku-Community/sources#829).
static CHAPTER_RES: Lazy<[Regex; 2]> = Lazy::new(|| {
#[expect(clippy::unwrap_used)]
[
Regex::new(r"(?:第\s*)(\d+(?:\.\d+)?)|(\d+(?:\.\d+)?)\s*(?:话|話|章|回|卷|册|冊)").unwrap(),
// Fallback: find any standalone number in the string
Regex::new(r"(?:\s|\.)+(\d+(?:\.\d+)?)\s*$").unwrap(),
]
});

fn extract_chapter_number(title: &str) -> Option<f32> {
// Normalize fullwidth digits and dot to ASCII, and lowercase for matching
Expand All @@ -35,18 +47,14 @@ fn extract_chapter_number(title: &str) -> Option<f32> {

let s = normalize(title);

if let Ok(re) =
Regex::new(r"(?:第\s*)(\d+(?:\.\d+)?)|(\d+(?:\.\d+)?)\s*(?:话|話|章|回|卷|册|冊)")
&& let Some(captures) = re.captures(&s)
if let Some(captures) = CHAPTER_RES[0].captures(&s)
&& let Some(m) = captures.get(1).or_else(|| captures.get(2))
&& let Ok(num) = m.as_str().parse::<f32>()
{
return Some(num);
}

// Fallback: find any standalone number in the string
if let Ok(re2) = Regex::new(r"(?:\s|\.)+(\d+(?:\.\d+)?)\s*$")
&& let Some(captures) = re2.captures(&s)
if let Some(captures) = CHAPTER_RES[1].captures(&s)
&& let Some(m) = captures.get(1)
&& let Ok(num) = m.as_str().parse::<f32>()
{
Expand Down
12 changes: 11 additions & 1 deletion sources/zh.dm5/Cargo.lock

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

1 change: 1 addition & 0 deletions sources/zh.dm5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
aidoku = { git = "https://github.com/Aidoku/aidoku-rs.git", version = "0.3.0", features = ["json"] }
regex = { version = "1.11.1", default-features = false, features = ["unicode"] }
spin = "0.10.0"

[dev-dependencies]
aidoku = { git = "https://github.com/Aidoku/aidoku-rs.git", features = ["test"] }
Expand Down
2 changes: 1 addition & 1 deletion sources/zh.dm5/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"info": {
"id": "zh.dm5",
"name": "动漫屋",
"version": 3,
"version": 4,
"urls": [
"https://www.dm5.com",
"https://www.dm5.cn"
Expand Down
15 changes: 10 additions & 5 deletions sources/zh.dm5/src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ use aidoku::{
prelude::*,
};
use regex::Regex;
use spin::Lazy;

/// Extracts the leading number from a chapter/volume title and reports whether
/// the unit attached to that number marks it as a volume (卷/册/冊) rather than a
/// chapter (话/話/章/回). The unit is anchored to the matched number so that a 卷
/// appearing inside a word does not misclassify a chapter.
// Compile the regex once instead of per chapter to keep the details call
// fast on interpreted runtimes (see Aidoku-Community/sources#829).
static CHAPTER_RE: Lazy<Regex> = Lazy::new(|| {
#[expect(clippy::unwrap_used)]
Regex::new(r"第\s*(\d+(?:\.\d+)?)\s*([话話章回卷册冊])?|(\d+(?:\.\d+)?)\s*([话話章回卷册冊])")
.unwrap()
});

fn extract_chapter_number(title: &str) -> Option<(f32, bool)> {
let re = Regex::new(
r"第\s*(\d+(?:\.\d+)?)\s*([话話章回卷册冊])?|(\d+(?:\.\d+)?)\s*([话話章回卷册冊])",
)
.ok()?;
let caps = re.captures(title)?;
let caps = CHAPTER_RE.captures(title)?;
let (num, unit) = if let Some(n) = caps.get(1) {
(n, caps.get(2))
} else {
Expand Down
12 changes: 11 additions & 1 deletion sources/zh.godamanga/Cargo.lock

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

1 change: 1 addition & 0 deletions sources/zh.godamanga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ chrono = { version = "0.4.39", default-features = false, features = ["serde"] }
regex = { version = "1.11.1", default-features = false, features = ["unicode"] }
serde = { version = "1.0.219", default-features = false }
serde_json = { version = "1.0.140", default-features = false }
spin = "0.10.0"

[dev-dependencies]
aidoku = { git = "https://github.com/Aidoku/aidoku-rs.git", features = ["test"] }
Expand Down
2 changes: 1 addition & 1 deletion sources/zh.godamanga/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"info": {
"id": "zh.godamanga",
"name": "G站漫畫",
"version": 2,
"version": 4,
"urls": [
"https://godamh.com",
"https://baozimh.org",
Expand Down
51 changes: 23 additions & 28 deletions sources/zh.godamanga/src/json/chapter_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,32 @@ use aidoku::{
};
use chrono::DateTime;
use regex::Regex;
use spin::Lazy;

fn extract_chapter_number(title: &str) -> Option<f32> {
// This handles cases like "第183话 180" where 180 is the actual chapter
let re1 =
Regex::new(r"(?:第\s*\d+(?:\.\d+)?\s*(?:话|話|章|回|卷|册|冊)\s*)(\d+(?:\.\d+)?)").ok()?;
if let Some(captures) = re1.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
}

// Second try: match "第X话" pattern where X is the chapter number
let re2 = Regex::new(r"(?:第\s*)(\d+(?:\.\d+)?)\s*(?:话|話|章|回|卷|册|冊)").ok()?;
if let Some(captures) = re2.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
}
// Compile the regexes once instead of per chapter to keep the details call
// fast on interpreted runtimes
static CHAPTER_RES: Lazy<[Regex; 3]> = Lazy::new(|| {
#[expect(clippy::unwrap_used)]
[
// This handles cases like "第183话 180" where 180 is the actual chapter
Regex::new(r"(?:第\s*\d+(?:\.\d+)?\s*(?:话|話|章|回|卷|册|冊)\s*)(\d+(?:\.\d+)?)").unwrap(),
// Second try: match "第X话" pattern where X is the chapter number
Regex::new(r"(?:第\s*)(\d+(?:\.\d+)?)\s*(?:话|話|章|回|卷|册|冊)").unwrap(),
// Third try: match pure number at the beginning
Regex::new(r"^(\d+(?:\.\d+)?)").unwrap(),
]
});

// Third try: match pure number at the beginning
let re3 = Regex::new(r"^(\d+(?:\.\d+)?)").ok()?;
if let Some(captures) = re3.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
Some(num)
} else {
None
fn extract_chapter_number(title: &str) -> Option<f32> {
for re in CHAPTER_RES.iter() {
if let Some(captures) = re.captures(title)
&& let Some(num_match) = captures.get(1)
&& let Ok(num) = num_match.as_str().parse::<f32>()
{
return Some(num);
}
}
None
}

pub struct ChapterList;
Expand Down
Loading
Loading