Handle getImage for delegate sources
This commit is contained in:
parent
83e23dedae
commit
a51c25bdcf
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.track.mdlist.MdList
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.MetadataMangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
@ -194,9 +195,13 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
||||
}
|
||||
|
||||
override fun fetchImage(page: Page): Observable<Response> {
|
||||
return pageHandler.fetchImage(page) {
|
||||
super.fetchImage(it)
|
||||
val call = pageHandler.getImageCall(page)
|
||||
return call?.asObservableSuccess() ?: super.fetchImage(page)
|
||||
}
|
||||
|
||||
override suspend fun getImage(page: Page): Response {
|
||||
val call = pageHandler.getImageCall(page)
|
||||
return call?.awaitSuccess() ?: super.getImage(page)
|
||||
}
|
||||
|
||||
override fun fetchImageUrl(page: Page): Observable<String> {
|
||||
|
@ -62,6 +62,7 @@ class MergedSource : HttpSource() {
|
||||
override fun fetchChapterList(manga: SManga) = throw UnsupportedOperationException()
|
||||
override suspend fun getChapterList(manga: SManga) = throw UnsupportedOperationException()
|
||||
override fun fetchImage(page: Page) = throw UnsupportedOperationException()
|
||||
override suspend fun getImage(page: Page): Response = throw UnsupportedOperationException()
|
||||
override fun fetchImageUrl(page: Page) = throw UnsupportedOperationException()
|
||||
|
||||
@Deprecated("Use the 1.x API instead", replaceWith = ReplaceWith("getPageList"))
|
||||
|
@ -3,7 +3,6 @@ package exh.md.handlers
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.tachiyomi.data.track.mdlist.MdList
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
@ -13,8 +12,8 @@ import exh.md.dto.AtHomeDto
|
||||
import exh.md.service.MangaDexService
|
||||
import exh.md.utils.MdApi
|
||||
import exh.md.utils.MdUtil
|
||||
import okhttp3.Call
|
||||
import okhttp3.Headers
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import kotlin.reflect.full.superclasses
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
@ -103,30 +102,25 @@ class PageHandler(
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchImage(page: Page, superMethod: (Page) -> Observable<Response>): Observable<Response> {
|
||||
fun getImageCall(page: Page): Call? {
|
||||
xLogD(page.imageUrl)
|
||||
return when {
|
||||
page.imageUrl?.contains("mangaplus", true) == true -> {
|
||||
mangaPlusHandler.client.newCall(GET(page.imageUrl!!, headers))
|
||||
.asObservableSuccess()
|
||||
}
|
||||
page.imageUrl?.contains("comikey", true) == true -> {
|
||||
comikeyHandler.client.newCall(GET(page.imageUrl!!, comikeyHandler.headers))
|
||||
.asObservableSuccess()
|
||||
}
|
||||
page.imageUrl?.contains("/bfs/comic/", true) == true -> {
|
||||
bilibiliHandler.client.newCall(GET(page.imageUrl!!, bilibiliHandler.headers))
|
||||
.asObservableSuccess()
|
||||
}
|
||||
page.imageUrl?.contains("azuki", true) == true -> {
|
||||
azukiHandler.client.newCall(GET(page.imageUrl!!, azukiHandler.headers))
|
||||
.asObservableSuccess()
|
||||
}
|
||||
page.imageUrl?.contains("mangahot", true) == true -> {
|
||||
mangaHotHandler.client.newCall(GET(page.imageUrl!!, mangaHotHandler.headers))
|
||||
.asObservableSuccess()
|
||||
}
|
||||
else -> superMethod(page)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,8 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param page the page whose source image has to be downloaded.
|
||||
*/
|
||||
suspend fun getImage(page: Page): Response {
|
||||
/* SY --> */
|
||||
open /* SY <-- */ suspend fun getImage(page: Page): Response {
|
||||
// images will be cached or saved manually, so don't take up network cache
|
||||
return client.newCachelessCallWithProgress(imageRequest(page), page)
|
||||
.awaitSuccess()
|
||||
|
@ -266,6 +266,16 @@ abstract class DelegatedHttpSource(val delegate: HttpSource) : HttpSource() {
|
||||
return delegate.fetchImage(page)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response of the source image.
|
||||
*
|
||||
* @param page the page whose source image has to be downloaded.
|
||||
*/
|
||||
override suspend fun getImage(page: Page): Response {
|
||||
ensureDelegateCompatible()
|
||||
return delegate.getImage(page)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before inserting a new chapter into database. Use it if you need to override chapter
|
||||
* fields, like the title or the chapter number. Do not change anything to [manga].
|
||||
|
@ -233,6 +233,13 @@ class EnhancedHttpSource(
|
||||
*/
|
||||
override fun fetchImage(page: Page) = source().fetchImage(page)
|
||||
|
||||
/**
|
||||
* Returns the response of the source image.
|
||||
*
|
||||
* @param page the page whose source image has to be downloaded.
|
||||
*/
|
||||
override suspend fun getImage(page: Page) = source().getImage(page)
|
||||
|
||||
/**
|
||||
* Called before inserting a new chapter into database. Use it if you need to override chapter
|
||||
* fields, like the title or the chapter number. Do not change anything to [manga].
|
||||
|
Loading…
x
Reference in New Issue
Block a user