Remove episode number from episode title like saikou (#119)
* Add files via upload * Add files via upload * Add files via upload * use existing robust episode regex * use existing robust episode regex * use existing robust episode regex * use existing robust episode regex * allow external use of manga chapter regex as well --------- Co-authored-by: rebel onion <87634197+rebelonion@users.noreply.github.com>
This commit is contained in:
parent
038b8f7ff7
commit
97cd3dd43b
5 changed files with 84 additions and 75 deletions
|
@ -5,8 +5,10 @@ import java.util.regex.Pattern
|
||||||
|
|
||||||
class AnimeNameAdapter {
|
class AnimeNameAdapter {
|
||||||
companion object {
|
companion object {
|
||||||
|
val episodeRegex = "(episode|ep|e)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*"
|
||||||
|
val seasonRegex = "(season|s)[\\s:.\\-]*(\\d+)[\\s:.\\-]*"
|
||||||
|
|
||||||
fun findSeasonNumber(text: String): Int? {
|
fun findSeasonNumber(text: String): Int? {
|
||||||
val seasonRegex = "(season|s)[\\s:.\\-]*(\\d+)"
|
|
||||||
val seasonPattern: Pattern = Pattern.compile(seasonRegex, Pattern.CASE_INSENSITIVE)
|
val seasonPattern: Pattern = Pattern.compile(seasonRegex, Pattern.CASE_INSENSITIVE)
|
||||||
val seasonMatcher: Matcher = seasonPattern.matcher(text)
|
val seasonMatcher: Matcher = seasonPattern.matcher(text)
|
||||||
|
|
||||||
|
@ -18,7 +20,6 @@ class AnimeNameAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findEpisodeNumber(text: String): Float? {
|
fun findEpisodeNumber(text: String): Float? {
|
||||||
val episodeRegex = "(episode|ep|e)[\\s:.\\-]*([\\d]+\\.?[\\d]*)"
|
|
||||||
val episodePattern: Pattern = Pattern.compile(episodeRegex, Pattern.CASE_INSENSITIVE)
|
val episodePattern: Pattern = Pattern.compile(episodeRegex, Pattern.CASE_INSENSITIVE)
|
||||||
val episodeMatcher: Matcher = episodePattern.matcher(text)
|
val episodeMatcher: Matcher = episodePattern.matcher(text)
|
||||||
|
|
||||||
|
@ -29,4 +30,4 @@ class AnimeNameAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import ani.dantotsu.*
|
||||||
import ani.dantotsu.databinding.ItemAnimeWatchBinding
|
import ani.dantotsu.databinding.ItemAnimeWatchBinding
|
||||||
import ani.dantotsu.databinding.ItemChipBinding
|
import ani.dantotsu.databinding.ItemChipBinding
|
||||||
import ani.dantotsu.databinding.DialogLayoutBinding
|
import ani.dantotsu.databinding.DialogLayoutBinding
|
||||||
|
import ani.dantotsu.media.anime.AnimeNameAdapter
|
||||||
import ani.dantotsu.media.Media
|
import ani.dantotsu.media.Media
|
||||||
import ani.dantotsu.media.MediaDetailsActivity
|
import ani.dantotsu.media.MediaDetailsActivity
|
||||||
import ani.dantotsu.media.SourceSearchDialogFragment
|
import ani.dantotsu.media.SourceSearchDialogFragment
|
||||||
|
@ -310,70 +311,74 @@ class AnimeWatchAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun handleEpisodes() {
|
fun handleEpisodes() {
|
||||||
val binding = _binding
|
val binding = _binding
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
if (media.anime?.episodes != null) {
|
if (media.anime?.episodes != null) {
|
||||||
val episodes = media.anime.episodes!!.keys.toTypedArray()
|
val episodes = media.anime.episodes!!.keys.toTypedArray()
|
||||||
|
|
||||||
val anilistEp = (media.userProgress ?: 0).plus(1)
|
val anilistEp = (media.userProgress ?: 0).plus(1)
|
||||||
val appEp = loadData<String>("${media.id}_current_ep")?.toIntOrNull() ?: 1
|
val appEp = loadData<String>("${media.id}_current_ep")?.toIntOrNull() ?: 1
|
||||||
|
|
||||||
var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
||||||
if (episodes.contains(continueEp)) {
|
if (episodes.contains(continueEp)) {
|
||||||
binding.animeSourceContinue.visibility = View.VISIBLE
|
binding.animeSourceContinue.visibility = View.VISIBLE
|
||||||
handleProgress(
|
handleProgress(
|
||||||
binding.itemEpisodeProgressCont,
|
binding.itemEpisodeProgressCont,
|
||||||
binding.itemEpisodeProgress,
|
binding.itemEpisodeProgress,
|
||||||
binding.itemEpisodeProgressEmpty,
|
binding.itemEpisodeProgressEmpty,
|
||||||
media.id,
|
media.id,
|
||||||
continueEp
|
continueEp
|
||||||
)
|
)
|
||||||
if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight > fragment.playerSettings.watchPercentage) {
|
if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight > fragment.playerSettings.watchPercentage) {
|
||||||
val e = episodes.indexOf(continueEp)
|
val e = episodes.indexOf(continueEp)
|
||||||
if (e != -1 && e + 1 < episodes.size) {
|
if (e != -1 && e + 1 < episodes.size) {
|
||||||
continueEp = episodes[e + 1]
|
continueEp = episodes[e + 1]
|
||||||
handleProgress(
|
handleProgress(
|
||||||
binding.itemEpisodeProgressCont,
|
binding.itemEpisodeProgressCont,
|
||||||
binding.itemEpisodeProgress,
|
binding.itemEpisodeProgress,
|
||||||
binding.itemEpisodeProgressEmpty,
|
binding.itemEpisodeProgressEmpty,
|
||||||
media.id,
|
media.id,
|
||||||
continueEp
|
continueEp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
val ep = media.anime.episodes!![continueEp]!!
|
||||||
|
|
||||||
|
val cleanedTitle = ep.title?.replace(Regex(AnimeNameAdapter.episodeRegex, RegexOption.IGNORE_CASE), "")
|
||||||
|
|
||||||
|
binding.itemEpisodeImage.loadImage(
|
||||||
|
ep.thumb ?: FileUrl[media.banner ?: media.cover], 0
|
||||||
|
)
|
||||||
|
if (ep.filler) binding.itemEpisodeFillerView.visibility = View.VISIBLE
|
||||||
|
binding.animeSourceContinueText.text =
|
||||||
|
currActivity()!!.getString(R.string.continue_episode) + "${ep.number}${if (ep.filler) " - Filler" else ""}${if (cleanedTitle != null) "\n$cleanedTitle" else ""}"
|
||||||
|
binding.animeSourceContinue.setOnClickListener {
|
||||||
|
fragment.onEpisodeClick(continueEp)
|
||||||
|
}
|
||||||
|
if (fragment.continueEp) {
|
||||||
|
if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight < fragment.playerSettings.watchPercentage) {
|
||||||
|
binding.animeSourceContinue.performClick()
|
||||||
|
fragment.continueEp = false
|
||||||
}
|
}
|
||||||
val ep = media.anime.episodes!![continueEp]!!
|
|
||||||
binding.itemEpisodeImage.loadImage(
|
|
||||||
ep.thumb ?: FileUrl[media.banner ?: media.cover], 0
|
|
||||||
)
|
|
||||||
if (ep.filler) binding.itemEpisodeFillerView.visibility = View.VISIBLE
|
|
||||||
binding.animeSourceContinueText.text =
|
|
||||||
currActivity()!!.getString(R.string.continue_episode) + "${ep.number}${if (ep.filler) " - Filler" else ""}${if (ep.title != null) "\n${ep.title}" else ""}"
|
|
||||||
binding.animeSourceContinue.setOnClickListener {
|
|
||||||
fragment.onEpisodeClick(continueEp)
|
|
||||||
}
|
|
||||||
if (fragment.continueEp) {
|
|
||||||
if ((binding.itemEpisodeProgress.layoutParams as LinearLayout.LayoutParams).weight < fragment.playerSettings.watchPercentage) {
|
|
||||||
binding.animeSourceContinue.performClick()
|
|
||||||
fragment.continueEp = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
binding.animeSourceContinue.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
binding.animeSourceProgressBar.visibility = View.GONE
|
|
||||||
if (media.anime.episodes!!.isNotEmpty())
|
|
||||||
binding.animeSourceNotFound.visibility = View.GONE
|
|
||||||
else
|
|
||||||
binding.animeSourceNotFound.visibility = View.VISIBLE
|
|
||||||
} else {
|
} else {
|
||||||
binding.animeSourceContinue.visibility = View.GONE
|
binding.animeSourceContinue.visibility = View.GONE
|
||||||
binding.animeSourceNotFound.visibility = View.GONE
|
|
||||||
clearChips()
|
|
||||||
binding.animeSourceProgressBar.visibility = View.VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.animeSourceProgressBar.visibility = View.GONE
|
||||||
|
if (media.anime.episodes!!.isNotEmpty())
|
||||||
|
binding.animeSourceNotFound.visibility = View.GONE
|
||||||
|
else
|
||||||
|
binding.animeSourceNotFound.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
binding.animeSourceContinue.visibility = View.GONE
|
||||||
|
binding.animeSourceNotFound.visibility = View.GONE
|
||||||
|
clearChips()
|
||||||
|
binding.animeSourceProgressBar.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setLanguageList(lang: Int, source: Int) {
|
private fun setLanguageList(lang: Int, source: Int) {
|
||||||
val binding = _binding
|
val binding = _binding
|
||||||
|
@ -413,4 +418,4 @@ class AnimeWatchAdapter(
|
||||||
countDown(media, binding.animeSourceContainer)
|
countDown(media, binding.animeSourceContainer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import ani.dantotsu.connections.updateProgress
|
||||||
import ani.dantotsu.databinding.ItemEpisodeCompactBinding
|
import ani.dantotsu.databinding.ItemEpisodeCompactBinding
|
||||||
import ani.dantotsu.databinding.ItemEpisodeGridBinding
|
import ani.dantotsu.databinding.ItemEpisodeGridBinding
|
||||||
import ani.dantotsu.databinding.ItemEpisodeListBinding
|
import ani.dantotsu.databinding.ItemEpisodeListBinding
|
||||||
|
import ani.dantotsu.media.anime.AnimeNameAdapter
|
||||||
import ani.dantotsu.media.Media
|
import ani.dantotsu.media.Media
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.model.GlideUrl
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
|
@ -76,12 +77,11 @@ class EpisodeAdapter(
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
val ep = arr[position]
|
val ep = arr[position]
|
||||||
val title =
|
val title = if (!ep.title.isNullOrEmpty() && ep.title != "null") {
|
||||||
"${
|
(ep.title as? String)?.replaceFirst(Regex(AnimeNameAdapter.episodeRegex, RegexOption.IGNORE_CASE), "")
|
||||||
if (!ep.title.isNullOrEmpty() && ep.title != "null") "" else currContext()!!.getString(
|
} else {
|
||||||
R.string.episode_singular
|
ep.number
|
||||||
)
|
} ?: ""
|
||||||
} ${if (!ep.title.isNullOrEmpty() && ep.title != "null") ep.title else ep.number}"
|
|
||||||
|
|
||||||
when (holder) {
|
when (holder) {
|
||||||
is EpisodeListViewHolder -> {
|
is EpisodeListViewHolder -> {
|
||||||
|
@ -246,4 +246,3 @@ class EpisodeAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ import ani.dantotsu.connections.discord.DiscordServiceRunningSingleton
|
||||||
import ani.dantotsu.connections.discord.RPC
|
import ani.dantotsu.connections.discord.RPC
|
||||||
import ani.dantotsu.connections.updateProgress
|
import ani.dantotsu.connections.updateProgress
|
||||||
import ani.dantotsu.databinding.ActivityExoplayerBinding
|
import ani.dantotsu.databinding.ActivityExoplayerBinding
|
||||||
|
import ani.dantotsu.media.anime.AnimeNameAdapter
|
||||||
import ani.dantotsu.media.Media
|
import ani.dantotsu.media.Media
|
||||||
import ani.dantotsu.media.MediaDetailsViewModel
|
import ani.dantotsu.media.MediaDetailsViewModel
|
||||||
import ani.dantotsu.media.SubtitleDownloader
|
import ani.dantotsu.media.SubtitleDownloader
|
||||||
|
@ -946,14 +947,17 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
|
||||||
//Anime Title
|
//Anime Title
|
||||||
animeTitle.text = media.userPreferredName
|
animeTitle.text = media.userPreferredName
|
||||||
|
|
||||||
episodeArr = episodes.keys.toList()
|
episodeArr = episodes.keys.toList()
|
||||||
currentEpisodeIndex = episodeArr.indexOf(media.anime!!.selectedEpisode!!)
|
currentEpisodeIndex = episodeArr.indexOf(media.anime!!.selectedEpisode!!)
|
||||||
|
|
||||||
episodeTitleArr = arrayListOf()
|
val episodeTitleArr = arrayListOf<String>()
|
||||||
episodes.forEach {
|
episodes.forEach {
|
||||||
val episode = it.value
|
val episode = it.value
|
||||||
episodeTitleArr.add("${if (!episode.title.isNullOrEmpty() && episode.title != "null") "" else "Episode "}${episode.number}${if (episode.filler) " [Filler]" else ""}${if (!episode.title.isNullOrEmpty() && episode.title != "null") " : " + episode.title else ""}")
|
episodeTitleArr.add("${if (!episode.title.isNullOrEmpty() && episode.title != "null") "" else "numeric :"}${episode.number}${if (episode.filler) " [Filler]" else ""}${if (!episode.title.isNullOrEmpty() && episode.title != "null") " : " + episode.title else ""}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val regexPattern = Regex(AnimeNameAdapter.episodeRegex, RegexOption.IGNORE_CASE)
|
||||||
|
episodeTitleArr.replaceAll { it.replace(regexPattern, "") }
|
||||||
|
|
||||||
//Episode Change
|
//Episode Change
|
||||||
fun change(index: Int) {
|
fun change(index: Int) {
|
||||||
|
|
|
@ -5,8 +5,8 @@ import java.util.regex.Pattern
|
||||||
|
|
||||||
class MangaNameAdapter {
|
class MangaNameAdapter {
|
||||||
companion object {
|
companion object {
|
||||||
|
val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*"
|
||||||
fun findChapterNumber(text: String): Float? {
|
fun findChapterNumber(text: String): Float? {
|
||||||
val regex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)"
|
|
||||||
val pattern: Pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
|
val pattern: Pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
|
||||||
val matcher: Matcher = pattern.matcher(text)
|
val matcher: Matcher = pattern.matcher(text)
|
||||||
|
|
||||||
|
@ -17,4 +17,4 @@ class MangaNameAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue