@@ -82,7 +82,7 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:1.2.2') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:d8cb38a9be') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.koitharu.kotatsu.core.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.core.model.UnknownMangaSource
|
import org.koitharu.kotatsu.core.model.UnknownMangaSource
|
||||||
import org.koitharu.kotatsu.core.model.isNsfw
|
import org.koitharu.kotatsu.core.model.isNsfw
|
||||||
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
|
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
|
||||||
import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||||
@@ -15,21 +15,20 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.parsers.util.almostEquals
|
import org.koitharu.kotatsu.parsers.util.almostEquals
|
||||||
import org.koitharu.kotatsu.parsers.util.levenshteinDistance
|
import org.koitharu.kotatsu.parsers.util.levenshteinDistance
|
||||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||||
import org.koitharu.kotatsu.parsers.util.toRelativeUrl
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@Reusable
|
@Reusable
|
||||||
class MangaLinkResolver @Inject constructor(
|
class MangaLinkResolver @Inject constructor(
|
||||||
private val repositoryFactory: MangaRepository.Factory,
|
private val repositoryFactory: MangaRepository.Factory,
|
||||||
private val sourcesRepository: MangaSourcesRepository,
|
|
||||||
private val dataRepository: MangaDataRepository,
|
private val dataRepository: MangaDataRepository,
|
||||||
|
private val context: MangaLoaderContext,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun resolve(uri: Uri): Manga {
|
suspend fun resolve(uri: Uri): Manga {
|
||||||
return if (uri.scheme == "kotatsu" || uri.host == "kotatsu.app") {
|
return if (uri.scheme == "kotatsu" || uri.host == "kotatsu.app") {
|
||||||
resolveAppLink(uri)
|
resolveAppLink(uri)
|
||||||
} else {
|
} else {
|
||||||
resolveExternalLink(uri)
|
resolveExternalLink(uri.toString())
|
||||||
} ?: throw NotFoundException("Cannot resolve link", uri.toString())
|
} ?: throw NotFoundException("Cannot resolve link", uri.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,18 +44,11 @@ class MangaLinkResolver @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun resolveExternalLink(uri: Uri): Manga? {
|
private suspend fun resolveExternalLink(uri: String): Manga? {
|
||||||
dataRepository.findMangaByPublicUrl(uri.toString())?.let {
|
dataRepository.findMangaByPublicUrl(uri)?.let {
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
val host = uri.host ?: return null
|
return context.newLinkResolver(uri).getManga()
|
||||||
val repo = sourcesRepository.allMangaSources.asSequence()
|
|
||||||
.map { source ->
|
|
||||||
repositoryFactory.create(source) as ParserMangaRepository
|
|
||||||
}.find { repo ->
|
|
||||||
host in repo.domains
|
|
||||||
} ?: return null
|
|
||||||
return repo.findExact(uri.toString().toRelativeUrl(host), null)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun MangaRepository.findExact(url: String?, title: String?): Manga? {
|
private suspend fun MangaRepository.findExact(url: String?, title: String?): Manga? {
|
||||||
@@ -85,12 +77,10 @@ class MangaLinkResolver @Inject constructor(
|
|||||||
}.getOrThrow()
|
}.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun MangaRepository.getDetailsNoCache(manga: Manga): Manga {
|
private suspend fun MangaRepository.getDetailsNoCache(manga: Manga): Manga = if (this is CachingMangaRepository) {
|
||||||
return if (this is ParserMangaRepository) {
|
getDetails(manga, CachePolicy.READ_ONLY)
|
||||||
getDetails(manga, CachePolicy.READ_ONLY)
|
} else {
|
||||||
} else {
|
getDetails(manga)
|
||||||
getDetails(manga)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSeedManga(source: MangaSource, url: String, title: String?) = Manga(
|
private fun getSeedManga(source: MangaSource, url: String, title: String?) = Manga(
|
||||||
|
|||||||
Reference in New Issue
Block a user