|
|
|
|
@ -7,6 +7,7 @@ import org.koitharu.kotatsu.core.util.ext.asArrayList
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
|
|
|
|
import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
|
|
|
|
|
import org.koitharu.kotatsu.history.data.HistoryRepository
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.ContentType
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.Manga
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
|
|
|
|
@ -21,19 +22,39 @@ class ExploreRepository @Inject constructor(
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
suspend fun findRandomManga(tagsLimit: Int): Manga {
|
|
|
|
|
val blacklistTagRegex = TagsBlacklist(settings.suggestionsTagsBlacklist, 0.4f)
|
|
|
|
|
val tagsBlacklist = TagsBlacklist(settings.suggestionsTagsBlacklist, 0.4f)
|
|
|
|
|
val tags = historyRepository.getPopularTags(tagsLimit).mapNotNull {
|
|
|
|
|
if (it in blacklistTagRegex) null else it.title
|
|
|
|
|
if (it in tagsBlacklist) null else it.title
|
|
|
|
|
}
|
|
|
|
|
val sources = sourcesRepository.getEnabledSources()
|
|
|
|
|
check(sources.isNotEmpty()) { "No sources available" }
|
|
|
|
|
for (i in 0..4) {
|
|
|
|
|
val list = getList(sources.random(), tags, blacklistTagRegex)
|
|
|
|
|
val list = getList(sources.random(), tags, tagsBlacklist)
|
|
|
|
|
val manga = list.randomOrNull() ?: continue
|
|
|
|
|
val details = runCatchingCancellable {
|
|
|
|
|
mangaRepositoryFactory.create(manga.source).getDetails(manga)
|
|
|
|
|
}.getOrNull() ?: continue
|
|
|
|
|
if ((settings.isSuggestionsExcludeNsfw && details.isNsfw) || details in blacklistTagRegex) {
|
|
|
|
|
if ((settings.isSuggestionsExcludeNsfw && details.isNsfw) || details in tagsBlacklist) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
return details
|
|
|
|
|
}
|
|
|
|
|
throw NoSuchElementException()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun findRandomManga(source: MangaSource, tagsLimit: Int): Manga {
|
|
|
|
|
val tagsBlacklist = TagsBlacklist(settings.suggestionsTagsBlacklist, 0.4f)
|
|
|
|
|
val skipNsfw = settings.isSuggestionsExcludeNsfw && source.contentType != ContentType.HENTAI
|
|
|
|
|
val tags = historyRepository.getPopularTags(tagsLimit).mapNotNull {
|
|
|
|
|
if (it in tagsBlacklist) null else it.title
|
|
|
|
|
}
|
|
|
|
|
for (i in 0..4) {
|
|
|
|
|
val list = getList(source, tags, tagsBlacklist)
|
|
|
|
|
val manga = list.randomOrNull() ?: continue
|
|
|
|
|
val details = runCatchingCancellable {
|
|
|
|
|
mangaRepositoryFactory.create(manga.source).getDetails(manga)
|
|
|
|
|
}.getOrNull() ?: continue
|
|
|
|
|
if ((skipNsfw && details.isNsfw) || details in tagsBlacklist) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
return details
|
|
|
|
|
|