mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-27 16:26:29 +03:00
handle chapters with part numbers
This commit is contained in:
parent
bc1ddd4379
commit
e6faee9779
2 changed files with 19 additions and 1 deletions
|
@ -19,6 +19,8 @@ public class ChapterRecognition {
|
||||||
|
|
||||||
private static final Pattern pUnwanted =
|
private static final Pattern pUnwanted =
|
||||||
Pattern.compile("(\\b|\\d)(v|ver|vol|version|volume)\\.?\\s*\\d+\\b");
|
Pattern.compile("(\\b|\\d)(v|ver|vol|version|volume)\\.?\\s*\\d+\\b");
|
||||||
|
private static final Pattern pPart =
|
||||||
|
Pattern.compile("(\\b|\\d)part\\s*\\d+.+");
|
||||||
|
|
||||||
public static void parseChapterNumber(Chapter chapter, Manga manga) {
|
public static void parseChapterNumber(Chapter chapter, Manga manga) {
|
||||||
if (chapter.chapter_number != -1)
|
if (chapter.chapter_number != -1)
|
||||||
|
@ -96,8 +98,8 @@ public class ChapterRecognition {
|
||||||
|
|
||||||
// try splitting the name in parts an pick the first valid one
|
// try splitting the name in parts an pick the first valid one
|
||||||
String[] nameParts = chapter.name.split("-");
|
String[] nameParts = chapter.name.split("-");
|
||||||
if (nameParts.length > 1) {
|
|
||||||
Chapter dummyChapter = Chapter.create();
|
Chapter dummyChapter = Chapter.create();
|
||||||
|
if (nameParts.length > 1) {
|
||||||
for (String part : nameParts) {
|
for (String part : nameParts) {
|
||||||
dummyChapter.name = part;
|
dummyChapter.name = part;
|
||||||
parseChapterNumber(dummyChapter, manga);
|
parseChapterNumber(dummyChapter, manga);
|
||||||
|
@ -107,6 +109,15 @@ public class ChapterRecognition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip anything after "part xxx" and try that
|
||||||
|
name = pPart.matcher(name).replaceAll("$1");
|
||||||
|
dummyChapter.name = name;
|
||||||
|
parseChapterNumber(dummyChapter, manga);
|
||||||
|
if (dummyChapter.chapter_number >= 0) {
|
||||||
|
chapter.chapter_number = dummyChapter.chapter_number;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -165,4 +165,11 @@ public class ChapterRecognitionTest {
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number).isEqualTo(123f);
|
assertThat(c.chapter_number).isEqualTo(123f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChapterWithChapterPrefixAfterPart() {
|
||||||
|
Chapter c = createChapter("Tokyo ESP 027: Part 002: Chapter 001");
|
||||||
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
|
assertThat(c.chapter_number).isEqualTo(027f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue