From bc1ddd43798cc3ce7a9c08a38b2526a38b1a454c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 9 Feb 2016 21:19:34 +0100 Subject: [PATCH] fallback to parsing parts to handle arc numbers --- .../kanade/tachiyomi/util/ChapterRecognition.java | 13 +++++++++++++ .../eu/kanade/tachiyomi/ChapterRecognitionTest.java | 7 +++++++ 2 files changed, 20 insertions(+) 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 af4bfd7aaf..7178417775 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java @@ -94,6 +94,19 @@ public class ChapterRecognition { // TODO more checks (maybe levenshtein?) + // try splitting the name in parts an pick the first valid one + String[] nameParts = chapter.name.split("-"); + if (nameParts.length > 1) { + Chapter dummyChapter = Chapter.create(); + for (String part : nameParts) { + dummyChapter.name = part; + 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 0e33b5f179..40ac33f049 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java +++ b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java @@ -158,4 +158,11 @@ public class ChapterRecognitionTest { ChapterRecognition.parseChapterNumber(c, randomManga); assertThat(c.chapter_number).isEqualTo(19.2f); } + + @Test + public void testChapterWithArcNumber() { + Chapter c = createChapter("Manga title 123 - Vol 016 Arc title 002"); + ChapterRecognition.parseChapterNumber(c, randomManga); + assertThat(c.chapter_number).isEqualTo(123f); + } }