mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
refactor: WIP delegated source refactor
J2K only handles deep link, which was disabled when I forked it as Yokai... Might gonna re-introduce it for some sources I used later (mainly Cubari tbh)
This commit is contained in:
parent
b4377a4609
commit
2cf2fcfc4f
10 changed files with 460 additions and 275 deletions
|
@ -1,20 +1,13 @@
|
|||
package eu.kanade.tachiyomi.source
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.R
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.DelegatedHttpSource
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.source.online.all.Cubari
|
||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||
import eu.kanade.tachiyomi.source.online.english.KireiCake
|
||||
import eu.kanade.tachiyomi.source.online.english.MangaPlus
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
@ -24,7 +17,8 @@ import kotlinx.coroutines.flow.collectLatest
|
|||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
||||
class SourceManager(
|
||||
private val context: Context,
|
||||
|
@ -40,28 +34,8 @@ class SourceManager(
|
|||
val catalogueSources: Flow<List<CatalogueSource>> = sourcesMapFlow.map { it.values.filterIsInstance<CatalogueSource>() }
|
||||
val onlineSources: Flow<List<HttpSource>> = catalogueSources.map { it.filterIsInstance<HttpSource>() }
|
||||
|
||||
private val delegatedSources = listOf(
|
||||
DelegatedSource(
|
||||
"reader.kireicake.com",
|
||||
5509224355268673176,
|
||||
KireiCake(),
|
||||
),
|
||||
DelegatedSource(
|
||||
"mangadex.org",
|
||||
2499283573021220255,
|
||||
MangaDex(),
|
||||
),
|
||||
DelegatedSource(
|
||||
"mangaplus.shueisha.co.jp",
|
||||
1998944621602463790,
|
||||
MangaPlus(),
|
||||
),
|
||||
DelegatedSource(
|
||||
"cubari.moe",
|
||||
6338219619148105941,
|
||||
Cubari(),
|
||||
),
|
||||
).associateBy { it.sourceId }
|
||||
// FIXME: Delegated source, unused at the moment, J2K only delegate deep links
|
||||
private val delegatedSources = emptyList<DelegatedSource>().associateBy { it.sourceId }
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
|
@ -71,8 +45,8 @@ class SourceManager(
|
|||
extensions.forEach { extension ->
|
||||
extension.sources.forEach {
|
||||
mutableMap[it.id] = it
|
||||
delegatedSources[it.id]?.delegatedHttpSource?.delegate = it as? HttpSource
|
||||
// registerStubSource(it)
|
||||
//delegatedSources[it.id]?.delegatedHttpSource?.delegate = it as? HttpSource
|
||||
//registerStubSource(it)
|
||||
}
|
||||
}
|
||||
sourcesMapFlow.value = mutableMap
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package eu.kanade.tachiyomi.source.online
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.create
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
|
||||
abstract class DelegatedHttpSource {
|
||||
|
||||
var delegate: HttpSource? = null
|
||||
abstract val domainName: String
|
||||
|
||||
protected val getChapter: GetChapter by injectLazy()
|
||||
protected val getManga: GetManga by injectLazy()
|
||||
|
||||
protected val network: NetworkHelper by injectLazy()
|
||||
|
||||
abstract fun canOpenUrl(uri: Uri): Boolean
|
||||
abstract fun chapterUrl(uri: Uri): String?
|
||||
open fun pageNumber(uri: Uri): Int? = uri.pathSegments.lastOrNull()?.toIntOrNull()
|
||||
abstract suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>?
|
||||
|
||||
protected open suspend fun getMangaInfo(url: String): Manga? {
|
||||
val id = delegate?.id ?: return null
|
||||
val manga = Manga.create(url, "", id)
|
||||
val networkManga = delegate?.getMangaDetails(manga.copy()) ?: return null
|
||||
val newManga = MangaImpl().apply {
|
||||
this.url = url
|
||||
title = try { networkManga.title } catch (e: Exception) { "" }
|
||||
source = id
|
||||
}
|
||||
newManga.copyFrom(networkManga)
|
||||
return newManga
|
||||
}
|
||||
|
||||
suspend fun getChapters(url: String): List<SChapter>? {
|
||||
val id = delegate?.id ?: return null
|
||||
val manga = Manga.create(url, "", id)
|
||||
return delegate?.getChapterList(manga)
|
||||
}
|
||||
}
|
|
@ -1,22 +1,31 @@
|
|||
package eu.kanade.tachiyomi.source.online.all
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.toChapter
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.DelegatedHttpSource
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import java.util.Locale
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.withContext
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
||||
class Cubari : DelegatedHttpSource() {
|
||||
class Cubari(delegate: HttpSource) :
|
||||
DelegatedHttpSource(delegate) {
|
||||
|
||||
private val getManga: GetManga = Injekt.get()
|
||||
private val getChapter: GetChapter = Injekt.get()
|
||||
|
||||
override val lang = "all"
|
||||
|
||||
override val domainName: String = "cubari"
|
||||
override fun canOpenUrl(uri: Uri): Boolean = true
|
||||
|
||||
|
@ -24,24 +33,24 @@ class Cubari : DelegatedHttpSource() {
|
|||
|
||||
override fun pageNumber(uri: Uri): Int? = uri.pathSegments.getOrNull(4)?.toIntOrNull()
|
||||
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>? {
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<SChapter, SManga, List<SChapter>>? {
|
||||
val cubariType = uri.pathSegments.getOrNull(1)?.lowercase(Locale.ROOT) ?: return null
|
||||
val cubariPath = uri.pathSegments.getOrNull(2) ?: return null
|
||||
val chapterNumber = uri.pathSegments.getOrNull(3)?.replace("-", ".")?.toFloatOrNull() ?: return null
|
||||
val mangaUrl = "/read/$cubariType/$cubariPath"
|
||||
return withContext(Dispatchers.IO) {
|
||||
val deferredManga = async {
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate?.id!!) ?: getMangaInfo(mangaUrl)
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate.id) ?: getMangaDetailsByUrl(mangaUrl)
|
||||
}
|
||||
val deferredChapters = async {
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate?.id!!)?.let { manga ->
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate.id)?.let { manga ->
|
||||
val chapters = getChapter.awaitAll(manga, false)
|
||||
val chapter = findChapter(chapters, cubariType, chapterNumber)
|
||||
if (chapter != null) {
|
||||
return@async chapters
|
||||
}
|
||||
}
|
||||
getChapters(mangaUrl)
|
||||
getChapterListByUrl(mangaUrl)
|
||||
}
|
||||
val manga = deferredManga.await()
|
||||
val chapters = deferredChapters.await()
|
||||
|
@ -50,11 +59,7 @@ class Cubari : DelegatedHttpSource() {
|
|||
?: error(
|
||||
context.getString(MR.strings.chapter_not_found),
|
||||
)
|
||||
if (manga != null) {
|
||||
Triple(trueChapter, manga, chapters.orEmpty())
|
||||
} else {
|
||||
null
|
||||
}
|
||||
Triple(trueChapter, manga, chapters)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package eu.kanade.tachiyomi.source.online.all
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.toChapter
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.DelegatedHttpSource
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import java.util.Locale
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
|
@ -20,10 +20,15 @@ import okhttp3.CacheControl
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
||||
class MangaDex : DelegatedHttpSource() {
|
||||
class MangaDex(delegate: HttpSource) : DelegatedHttpSource(delegate) {
|
||||
|
||||
private val getManga: GetManga = Injekt.get()
|
||||
|
||||
override val lang: String = "all"
|
||||
|
||||
override val domainName: String = "mangadex"
|
||||
|
||||
|
@ -42,13 +47,13 @@ class MangaDex : DelegatedHttpSource() {
|
|||
return uri.pathSegments.getOrNull(2)?.toIntOrNull()
|
||||
}
|
||||
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>? {
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<SChapter, SManga, List<SChapter>>? {
|
||||
val url = chapterUrl(uri) ?: return null
|
||||
val request =
|
||||
GET("https:///api.mangadex.org/v2$url", delegate!!.headers, CacheControl.FORCE_NETWORK)
|
||||
val response = network.client.newCall(request).await()
|
||||
if (response.code != 200) throw Exception("HTTP error ${response.code}")
|
||||
val body = response.body.string().orEmpty()
|
||||
val body = response.body.string()
|
||||
if (body.isEmpty()) {
|
||||
throw Exception("Null Response")
|
||||
}
|
||||
|
@ -56,28 +61,19 @@ class MangaDex : DelegatedHttpSource() {
|
|||
val jsonObject = Json.decodeFromString<MangaDexChapterData>(body)
|
||||
val dataObject = jsonObject.data ?: throw Exception("Chapter not found")
|
||||
val mangaId = dataObject.mangaId ?: throw Exception("No manga associated with chapter")
|
||||
val langCode = getRealLangCode(dataObject.language ?: "en").uppercase(Locale.getDefault())
|
||||
// Use the correct MangaDex source based on the language code, or the api will not return
|
||||
// the correct chapter list
|
||||
delegate = sourceManager.getOnlineSources().find { it.toString() == "MangaDex ($langCode)" }
|
||||
?: error("Source not found")
|
||||
val mangaUrl = "/manga/$mangaId/"
|
||||
return withContext(Dispatchers.IO) {
|
||||
val deferredManga = async {
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate?.id!!) ?: getMangaInfo(mangaUrl)
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate.id) ?: getMangaDetailsByUrl(mangaUrl)
|
||||
}
|
||||
val deferredChapters = async { getChapters(mangaUrl) }
|
||||
val deferredChapters = async { getChapterListByUrl(mangaUrl) }
|
||||
val manga = deferredManga.await()
|
||||
val chapters = deferredChapters.await()
|
||||
val context = Injekt.get<PreferencesHelper>().context
|
||||
val trueChapter = chapters?.find { it.url == "/api$url" }?.toChapter() ?: error(
|
||||
val trueChapter = chapters.find { it.url == "/api$url" }?.toChapter() ?: error(
|
||||
context.getString(MR.strings.chapter_not_found),
|
||||
)
|
||||
if (manga != null) {
|
||||
Triple(trueChapter, manga, chapters.orEmpty())
|
||||
} else {
|
||||
null
|
||||
}
|
||||
Triple(trueChapter, manga, chapters)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
package eu.kanade.tachiyomi.source.online.english
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.toChapter
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.online.DelegatedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.Request
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
||||
open class FoolSlide(override val domainName: String, private val urlModifier: String = "") :
|
||||
DelegatedHttpSource
|
||||
() {
|
||||
|
||||
override fun canOpenUrl(uri: Uri): Boolean = true
|
||||
|
||||
override fun chapterUrl(uri: Uri): String? {
|
||||
val offset = if (urlModifier.isEmpty()) 0 else 1
|
||||
val mangaName = uri.pathSegments.getOrNull(1 + offset) ?: return null
|
||||
val lang = uri.pathSegments.getOrNull(2 + offset) ?: return null
|
||||
val volume = uri.pathSegments.getOrNull(3 + offset) ?: return null
|
||||
val chapterNumber = uri.pathSegments.getOrNull(4 + offset) ?: return null
|
||||
val subChapterNumber = uri.pathSegments.getOrNull(5 + offset)?.toIntOrNull()?.toString()
|
||||
return "$urlModifier/read/" + listOfNotNull(
|
||||
mangaName,
|
||||
lang,
|
||||
volume,
|
||||
chapterNumber,
|
||||
subChapterNumber,
|
||||
).joinToString("/") + "/"
|
||||
}
|
||||
|
||||
override fun pageNumber(uri: Uri): Int? {
|
||||
val count = uri.pathSegments.count()
|
||||
if (count > 2 && uri.pathSegments[count - 2] == "page") {
|
||||
return super.pageNumber(uri)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>? {
|
||||
val offset = if (urlModifier.isEmpty()) 0 else 1
|
||||
val mangaName = uri.pathSegments.getOrNull(1 + offset) ?: return null
|
||||
var chapterNumber = uri.pathSegments.getOrNull(4 + offset) ?: return null
|
||||
val subChapterNumber = uri.pathSegments.getOrNull(5 + offset)?.toIntOrNull()
|
||||
if (subChapterNumber != null) {
|
||||
chapterNumber += ".$subChapterNumber"
|
||||
}
|
||||
return withContext(Dispatchers.IO) {
|
||||
val mangaUrl = "$urlModifier/series/$mangaName/"
|
||||
val sourceId = delegate?.id ?: return@withContext null
|
||||
val deferredManga = async {
|
||||
getManga.awaitByUrlAndSource(mangaUrl, sourceId) ?: getManga(mangaUrl)
|
||||
}
|
||||
val chapterUrl = chapterUrl(uri)
|
||||
val deferredChapters = async { getChapters(mangaUrl) }
|
||||
val manga = deferredManga.await()
|
||||
val chapters = deferredChapters.await()
|
||||
val context = Injekt.get<PreferencesHelper>().context
|
||||
val trueChapter = chapters?.find { it.url == chapterUrl }?.toChapter() ?: error(
|
||||
context.getString(MR.strings.chapter_not_found),
|
||||
)
|
||||
if (manga != null) Triple(trueChapter, manga, chapters) else null
|
||||
}
|
||||
}
|
||||
|
||||
open suspend fun getManga(url: String): Manga? {
|
||||
val request = GET("${delegate!!.baseUrl}$url")
|
||||
val document = network.client.newCall(allowAdult(request)).await().asJsoup()
|
||||
val mangaDetailsInfoSelector = "div.info"
|
||||
val infoElement = document.select(mangaDetailsInfoSelector).first()?.text() ?: return null
|
||||
return MangaImpl().apply {
|
||||
this.url = url
|
||||
source = delegate?.id ?: -1
|
||||
title = infoElement.substringAfter("Title:").substringBefore("Author:").trim()
|
||||
author = infoElement.substringAfter("Author:").substringBefore("Artist:").trim()
|
||||
artist = infoElement.substringAfter("Artist:").substringBefore("Synopsis:").trim()
|
||||
description = infoElement.substringAfter("Synopsis:").trim()
|
||||
thumbnail_url = document.select("div.thumbnail img").firstOrNull()?.attr("abs:src")?.trim()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a GET request into a POST request that automatically authorizes all adult content
|
||||
*/
|
||||
private fun allowAdult(request: Request) = allowAdult(request.url.toString())
|
||||
|
||||
private fun allowAdult(url: String): Request {
|
||||
return POST(
|
||||
url,
|
||||
body = FormBody.Builder()
|
||||
.add("adult", "true")
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package eu.kanade.tachiyomi.source.online.english
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import eu.kanade.tachiyomi.util.lang.capitalizeWords
|
||||
|
||||
class KireiCake : FoolSlide("kireicake") {
|
||||
|
||||
override suspend fun getManga(url: String): Manga? {
|
||||
val request = GET("${delegate!!.baseUrl}$url")
|
||||
val document = network.client.newCall(request).await().asJsoup()
|
||||
val mangaDetailsInfoSelector = "div.info"
|
||||
return MangaImpl().apply {
|
||||
this.url = url
|
||||
source = delegate?.id ?: -1
|
||||
title = document.select("$mangaDetailsInfoSelector li:has(b:contains(title))").first()
|
||||
?.ownText()?.substringAfter(":")?.trim()
|
||||
?: url.split("/").last().replace("_", " " + "").capitalizeWords()
|
||||
description =
|
||||
document.select("$mangaDetailsInfoSelector li:has(b:contains(description))").first()
|
||||
?.ownText()?.substringAfter(":")
|
||||
thumbnail_url = document.select("div.thumbnail img").firstOrNull()?.attr("abs:src")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +1,31 @@
|
|||
package eu.kanade.tachiyomi.source.online.english
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.toChapter
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.DelegatedHttpSource
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.CacheControl
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
||||
class MangaPlus : DelegatedHttpSource() {
|
||||
class MangaPlus(delegate: HttpSource) :
|
||||
DelegatedHttpSource(delegate) {
|
||||
|
||||
private val getManga: GetManga = Injekt.get()
|
||||
|
||||
override val lang: String get() = delegate.lang
|
||||
|
||||
override val domainName: String = "jumpg-webapi.tokyo-cdn"
|
||||
|
||||
private val titleIdRegex =
|
||||
|
@ -34,11 +41,11 @@ class MangaPlus : DelegatedHttpSource() {
|
|||
|
||||
override fun pageNumber(uri: Uri): Int? = null
|
||||
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>? {
|
||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<SChapter, SManga, List<SChapter>>? {
|
||||
val url = chapterUrl(uri) ?: return null
|
||||
val request = GET(
|
||||
chapterUrlTemplate.replace("##", uri.pathSegments[1]),
|
||||
delegate!!.headers,
|
||||
delegate.headers,
|
||||
CacheControl.FORCE_NETWORK,
|
||||
)
|
||||
return withContext(Dispatchers.IO) {
|
||||
|
@ -53,26 +60,22 @@ class MangaPlus : DelegatedHttpSource() {
|
|||
val trimmedTitle = title.substring(0, title.length - 1)
|
||||
val mangaUrl = "#/titles/$titleId"
|
||||
val deferredManga = async {
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate?.id!!) ?: getMangaInfo(mangaUrl)
|
||||
getManga.awaitByUrlAndSource(mangaUrl, delegate.id) ?: getMangaDetailsByUrl(mangaUrl)
|
||||
}
|
||||
val deferredChapters = async { getChapters(mangaUrl) }
|
||||
val deferredChapters = async { getChapterListByUrl(mangaUrl) }
|
||||
val manga = deferredManga.await()
|
||||
val chapters = deferredChapters.await()
|
||||
val context = Injekt.get<PreferencesHelper>().context
|
||||
val trueChapter = chapters?.find { it.url == url }?.toChapter() ?: error(
|
||||
val trueChapter = chapters.find { it.url == url }?.toChapter() ?: error(
|
||||
context.getString(MR.strings.chapter_not_found),
|
||||
)
|
||||
if (manga != null) {
|
||||
Triple(
|
||||
trueChapter,
|
||||
manga.apply {
|
||||
this.title = trimmedTitle
|
||||
},
|
||||
chapters,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
Triple(
|
||||
trueChapter,
|
||||
manga.apply {
|
||||
this.title = trimmedTitle
|
||||
},
|
||||
chapters,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.hippo.unifile.UniFile
|
|||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.create
|
||||
import eu.kanade.tachiyomi.data.database.models.defaultReaderType
|
||||
import eu.kanade.tachiyomi.data.database.models.orientationType
|
||||
import eu.kanade.tachiyomi.data.database.models.readingModeType
|
||||
|
@ -307,6 +308,7 @@ class ReaderViewModel(
|
|||
return delegatedSource.pageNumber(url)?.minus(1)
|
||||
}
|
||||
|
||||
// FIXME: Unused at the moment, handles J2K's delegated deep link, refactor or remove later
|
||||
suspend fun loadChapterURL(url: Uri) {
|
||||
val host = url.host ?: return
|
||||
val context = Injekt.get<Application>()
|
||||
|
@ -314,9 +316,7 @@ class ReaderViewModel(
|
|||
context.getString(MR.strings.source_not_installed),
|
||||
)
|
||||
val chapterUrl = delegatedSource.chapterUrl(url)
|
||||
val sourceId = delegatedSource.delegate?.id ?: error(
|
||||
context.getString(MR.strings.source_not_installed),
|
||||
)
|
||||
val sourceId = delegatedSource.delegate.id
|
||||
if (chapterUrl != null) {
|
||||
val dbChapter = getChapter.awaitAllByUrl(chapterUrl, false).find {
|
||||
val source = getManga.awaitById(it.manga_id!!)?.source ?: return@find false
|
||||
|
@ -334,7 +334,9 @@ class ReaderViewModel(
|
|||
}
|
||||
val info = delegatedSource.fetchMangaFromChapterUrl(url)
|
||||
if (info != null) {
|
||||
val (chapter, manga, chapters) = info
|
||||
val (sChapter, sManga, chapters) = info
|
||||
val manga = Manga.create(sourceId).apply { copyFrom(sManga) }
|
||||
val chapter = Chapter.create().apply { copyFrom(sChapter) }
|
||||
val id = insertManga.await(manga)
|
||||
manga.id = id ?: manga.id
|
||||
chapter.manga_id = manga.id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue