From eee137a084d89e71fe65c33387acc60b36fc671b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Feb 2016 21:03:52 +0100 Subject: [PATCH] prefer numbers at the start of the chapter title if otherwise unparsed --- .../kanade/tachiyomi/util/ChapterRecognition.java | 13 +++++++++++++ .../eu/kanade/tachiyomi/ChapterRecognitionTest.java | 9 +++++++++ 2 files changed, 22 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 1dbe9ebc6..1373deae1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java @@ -122,6 +122,19 @@ public class ChapterRecognition { return; } } + + + // check for a number either at the start or right after the manga title + matcher = startingNumber.matcher(name); + if (matcher.find()) { + chapter.chapter_number = Float.parseFloat(matcher.group(1)); + return; + } + matcher = startingNumber.matcher(nameWithoutManga); + if (matcher.find()) { + chapter.chapter_number = Float.parseFloat(matcher.group(1)); + return; + } } /** diff --git a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java index 6aace84f9..6235e298d 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java +++ b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java @@ -186,4 +186,13 @@ public class ChapterRecognitionTest { ChapterRecognition.parseChapterNumber(c, randomManga); assertThat(c.chapter_number).isEqualTo(404f); } + + @Test + public void testPlainNumberInTitle() { + Chapter c = createChapter("Kuroko no Basket 002 Monday at 840 on the Rooftop"); + Manga manga = new Manga(); + manga.title = "Kuroko no Basket"; + ChapterRecognition.parseChapterNumber(c, manga); + assertThat(c.chapter_number).isEqualTo(2f); + } }