Skip to content

Commit

Permalink
fix for decimal episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Dec 27, 2023
1 parent ebabff4 commit bf908c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
14 changes: 12 additions & 2 deletions app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit bf908c5

Please sign in to comment.