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 17d20bc6770..140ba56793a 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 03b40919051..89a6087ce09 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 },