From bf908c5e37915ceb395a692494b6fcab3670610b Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Wed, 27 Dec 2023 07:07:10 -0600 Subject: [PATCH] fix for decimal episodes --- .../ani/dantotsu/media/anime/AnimeNameAdapter.kt | 12 ++++++++++++ .../java/ani/dantotsu/parsers/AniyomiAdapter.kt | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt index 17d20bc677..140ba56793 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt @@ -16,5 +16,17 @@ class AnimeNameAdapter { null } } + + fun findEpisodeNumber(text: String): Float? { + val episodeRegex = "(episode|ep|e)[\\s:.\\-]*([\\d]+\\.?[\\d]*)" + val episodePattern: Pattern = Pattern.compile(episodeRegex, Pattern.CASE_INSENSITIVE) + val episodeMatcher: Matcher = episodePattern.matcher(text) + + return if (episodeMatcher.find()) { + episodeMatcher.group(2)?.toFloat() + } else { + null + } + } } } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt b/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt index 03b4091905..89a6087ce0 100644 --- a/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt +++ b/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt @@ -112,7 +112,13 @@ class DynamicAnimeParser(extension: AnimeExtension.Installed) : AnimeParser() { seasonGroups.keys.sorted().flatMap { season -> seasonGroups[season]?.sortedBy { it.episode_number }?.map { episode -> if (episode.episode_number != 0f) { // Skip renumbering for episode number 0 - episode.episode_number = episodeCounter++ + val potentialNumber = AnimeNameAdapter.findEpisodeNumber(episode.name) + if (potentialNumber != null) { + episode.episode_number = potentialNumber + } else { + episode.episode_number = episodeCounter + } + episodeCounter++ } episode } ?: emptyList() @@ -202,7 +208,11 @@ class DynamicAnimeParser(extension: AnimeExtension.Installed) : AnimeParser() { } return Episode( if (episodeNumberInt.toInt() != -1) { - episodeNumberInt.toString() + if (sEpisode.episode_number % 1 == 0f) { + episodeNumberInt.toInt().toString() + } else { + sEpisode.episode_number.toString() + } } else { sEpisode.name },