Lewd Filter upgrade, almost finished

This commit is contained in:
Jobobby04 2020-05-19 17:11:02 -04:00
parent 6da22ea8b0
commit e4d8fea138
3 changed files with 49 additions and 3 deletions

View File

@ -30,7 +30,7 @@ import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.removeCovers
import eu.kanade.tachiyomi.util.updateCoverLastModified
import exh.favorites.FavoritesSyncHelper
import exh.isLewdSource
import exh.util.isLewd
import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
@ -154,7 +154,7 @@ class LibraryPresenter(
else if (filterTracked == STATE_EXCLUDE && tracks.isNotEmpty()) return@f false
}
if (filterLewd != STATE_IGNORE) {
val isLewd = isLewdSource(item.manga.source)
val isLewd = item.manga.isLewd()
if (filterLewd == STATE_INCLUDE && !isLewd) return@f false
else if (filterLewd == STATE_EXCLUDE && isLewd) return@f false
}

View File

@ -48,7 +48,7 @@ private inline fun <reified T> delegatedSourceId(): Long {
}
// Used to speed up isLewdSource
private val lewdDelegatedSourceIds = SourceManager.DELEGATED_SOURCES.filter {
val lewdDelegatedSourceIds = SourceManager.DELEGATED_SOURCES.filter {
it.value.newSourceClass in DELEGATED_LEWD_SOURCES
}.map { it.value.sourceId }.sorted()

View File

@ -0,0 +1,46 @@
package exh.util
import android.util.Log
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.source.SourceManager
import exh.EH_SOURCE_ID
import exh.EXH_SOURCE_ID
import exh.NHENTAI_SOURCE_ID
import exh.lewdDelegatedSourceIds
import java.util.Locale
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
fun Manga.isLewd(): Boolean {
val sourceName = Injekt.get<SourceManager>().getOrStub(source).name
val currentTags =
genre?.split(",")?.map { it.trim().toLowerCase(Locale.US) } ?: emptyList()
val meta =
Log.d("Lewd", currentTags.joinToString(separator = "\n"))
if (source == EH_SOURCE_ID || source == EXH_SOURCE_ID || source == NHENTAI_SOURCE_ID) {
return !currentTags.any { tag -> isNonHentaiTag(tag) }
}
return source in 6905L..6913L ||
source in lewdDelegatedSourceIds ||
isHentaiSource(sourceName) ||
currentTags.any { tag -> isHentaiTag(tag) }
}
private fun isNonHentaiTag(tag: String): Boolean {
return tag.contains("non-h", true)
}
private fun isHentaiTag(tag: String): Boolean {
return tag.contains("hentai", true) ||
tag.contains("adult", true)
}
private fun isHentaiSource(source: String): Boolean {
return source.contains("hentai cafe", true) ||
source.contains("allporncomic", true) ||
source.contains("hentai2read", true) ||
source.contains("hentainexus", true)
}