From e6faee97792c1608716a2c6ea699a42fead2dfb5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 9 Feb 2016 21:23:57 +0100 Subject: [PATCH] handle chapters with part numbers --- .../kanade/tachiyomi/util/ChapterRecognition.java | 13 ++++++++++++- .../eu/kanade/tachiyomi/ChapterRecognitionTest.java | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java index 717841777..045b4609e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java @@ -19,6 +19,8 @@ public class ChapterRecognition { private static final Pattern pUnwanted = 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) { if (chapter.chapter_number != -1) @@ -96,8 +98,8 @@ public class ChapterRecognition { // try splitting the name in parts an pick the first valid one String[] nameParts = chapter.name.split("-"); + Chapter dummyChapter = Chapter.create(); if (nameParts.length > 1) { - Chapter dummyChapter = Chapter.create(); for (String part : nameParts) { dummyChapter.name = part; 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; + } } /** diff --git a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java index 40ac33f04..28ad19ed8 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java +++ b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java @@ -165,4 +165,11 @@ public class ChapterRecognitionTest { ChapterRecognition.parseChapterNumber(c, randomManga); 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); + } }