Use ChapterInfo wherever possible
This commit is contained in:
parent
450aeb5a9d
commit
8ef4a7fbbf
@ -4,10 +4,7 @@ import androidx.compose.runtime.Composable
|
||||
import eu.kanade.domain.manga.interactor.GetFlatMetadataById
|
||||
import eu.kanade.domain.manga.interactor.GetManga
|
||||
import eu.kanade.domain.manga.interactor.InsertFlatMetadata
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toMangaInfo
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaScreenState
|
||||
@ -118,6 +115,4 @@ interface MetadataSource<M : RaisedSearchMetadata, I> : CatalogueSource {
|
||||
fun DescriptionComposable(state: MangaScreenState.Success, openMetadataViewer: () -> Unit, search: (String) -> Unit)
|
||||
|
||||
suspend fun MangaInfo.id() = getManga.await(key, id)?.id
|
||||
val SManga.id get() = (this as? Manga)?.id
|
||||
val SChapter.mangaId get() = (this as? Chapter)?.manga_id
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.source.model.MetadataMangasPage
|
||||
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.model.toChapterInfo
|
||||
import eu.kanade.tachiyomi.source.online.BrowseSourceFilterHeader
|
||||
import eu.kanade.tachiyomi.source.online.FollowsSource
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
@ -198,7 +199,7 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
||||
}
|
||||
|
||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
||||
return runAsObservable { pageHandler.fetchPageList(chapter, isLogged(), usePort443Only(), dataSaver(), delegate) }
|
||||
return runAsObservable { pageHandler.fetchPageList(chapter.toChapterInfo(), isLogged(), usePort443Only(), dataSaver(), delegate) }
|
||||
}
|
||||
|
||||
override fun fetchImage(page: Page): Observable<Response> {
|
||||
|
@ -38,7 +38,6 @@ import tachiyomi.source.model.MangaInfo
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter
|
||||
|
||||
class MergedSource : HttpSource() {
|
||||
private val getManga: GetManga by injectLazy()
|
||||
@ -123,10 +122,6 @@ class MergedSource : HttpSource() {
|
||||
return if (dedupe) dedupeChapterList(mangaReferences, chapters) else chapters
|
||||
}
|
||||
|
||||
fun getChaptersAsBlockingAsDbChapter(mangaId: Long, editScanlators: Boolean = false, dedupe: Boolean = true): List<DbChapter> {
|
||||
return getChaptersAsBlocking(mangaId, editScanlators, dedupe).map(Chapter::toDbChapter)
|
||||
}
|
||||
|
||||
fun getChaptersAsBlocking(mangaId: Long, editScanlators: Boolean = false, dedupe: Boolean = true): List<Chapter> {
|
||||
return runBlocking { getChapters(mangaId, editScanlators, dedupe) }
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
||||
import eu.kanade.tachiyomi.network.parseAs
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import exh.log.xLogD
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
@ -21,6 +20,7 @@ import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import tachiyomi.source.model.ChapterInfo
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class BilibiliHandler(currentClient: OkHttpClient) {
|
||||
@ -44,9 +44,9 @@ class BilibiliHandler(currentClient: OkHttpClient) {
|
||||
val mangaUrl = getMangaUrl(externalUrl)
|
||||
val chapters = getChapterList(mangaUrl)
|
||||
val chapter = chapters
|
||||
.find { it.chapter_number == chapterNumber.toFloatOrNull() }
|
||||
.find { it.number == chapterNumber.toFloatOrNull() }
|
||||
?: throw Exception("Unknown chapter $chapterNumber")
|
||||
chapter.url
|
||||
chapter.key
|
||||
}
|
||||
|
||||
return fetchPageList(chapterUrl)
|
||||
@ -91,12 +91,12 @@ class BilibiliHandler(currentClient: OkHttpClient) {
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun getChapterList(mangaUrl: String): List<SChapter> {
|
||||
suspend fun getChapterList(mangaUrl: String): List<ChapterInfo> {
|
||||
val response = client.newCall(mangaDetailsApiRequest(mangaUrl)).await()
|
||||
return chapterListParse(response)
|
||||
}
|
||||
|
||||
fun chapterListParse(response: Response): List<SChapter> {
|
||||
fun chapterListParse(response: Response): List<ChapterInfo> {
|
||||
val result = response.parseAs<BilibiliResultDto<BilibiliComicDto>>()
|
||||
|
||||
if (result.code != 0) {
|
||||
@ -108,12 +108,11 @@ class BilibiliHandler(currentClient: OkHttpClient) {
|
||||
.map { ep -> chapterFromObject(ep, result.data.id) }
|
||||
}
|
||||
|
||||
private fun chapterFromObject(episode: BilibiliEpisodeDto, comicId: Int): SChapter = SChapter.create().apply {
|
||||
name = "Ep. " + episode.order.toString().removeSuffix(".0") +
|
||||
" - " + episode.title
|
||||
chapter_number = episode.order
|
||||
url = "/mc$comicId/${episode.id}"
|
||||
}
|
||||
private fun chapterFromObject(episode: BilibiliEpisodeDto, comicId: Int): ChapterInfo = ChapterInfo(
|
||||
key = "/mc$comicId/${episode.id}",
|
||||
name = "Ep. " + episode.order.toString().removeSuffix(".0") + " - " + episode.title,
|
||||
number = episode.order,
|
||||
)
|
||||
|
||||
private suspend fun fetchPageList(chapterUrl: String): List<Page> {
|
||||
val response = client.newCall(pageListRequest(chapterUrl)).await()
|
||||
|
@ -5,7 +5,6 @@ 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.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import exh.log.xLogD
|
||||
import exh.md.dto.AtHomeDto
|
||||
@ -16,6 +15,7 @@ import okhttp3.Headers
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import tachiyomi.source.Source
|
||||
import tachiyomi.source.model.ChapterInfo
|
||||
import kotlin.reflect.full.superclasses
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
@ -31,9 +31,9 @@ class PageHandler(
|
||||
private val mdList: MdList,
|
||||
) {
|
||||
|
||||
suspend fun fetchPageList(chapter: SChapter, isLogged: Boolean, usePort443Only: Boolean, dataSaver: Boolean, mangadex: Source): List<Page> {
|
||||
suspend fun fetchPageList(chapter: ChapterInfo, isLogged: Boolean, usePort443Only: Boolean, dataSaver: Boolean, mangadex: Source): List<Page> {
|
||||
return withIOContext {
|
||||
val chapterResponse = service.viewChapter(MdUtil.getChapterId(chapter.url))
|
||||
val chapterResponse = service.viewChapter(MdUtil.getChapterId(chapter.key))
|
||||
|
||||
if (chapterResponse.data.attributes.externalUrl != null && chapterResponse.data.attributes.pages == 0) {
|
||||
when {
|
||||
@ -63,9 +63,9 @@ class PageHandler(
|
||||
}
|
||||
|
||||
val atHomeRequestUrl = if (usePort443Only) {
|
||||
"${MdApi.atHomeServer}/${MdUtil.getChapterId(chapter.url)}?forcePort443=true"
|
||||
"${MdApi.atHomeServer}/${MdUtil.getChapterId(chapter.key)}?forcePort443=true"
|
||||
} else {
|
||||
"${MdApi.atHomeServer}/${MdUtil.getChapterId(chapter.url)}"
|
||||
"${MdApi.atHomeServer}/${MdUtil.getChapterId(chapter.key)}"
|
||||
}
|
||||
|
||||
updateExtensionVariable(mangadex, atHomeRequestUrl)
|
||||
|
@ -3,7 +3,6 @@ package exh.md.utils
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.mdlist.MdList
|
||||
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.all.MangaDex
|
||||
import exh.log.xLogD
|
||||
@ -25,6 +24,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.jsoup.parser.Parser
|
||||
import tachiyomi.source.model.ChapterInfo
|
||||
import tachiyomi.source.model.MangaInfo
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@ -233,7 +233,7 @@ class MdUtil {
|
||||
return scanlators.sorted().joinToString(scanlatorSeparator)
|
||||
}
|
||||
|
||||
fun getMissingChapterCount(chapters: List<SChapter>, mangaStatus: Int): String? {
|
||||
fun getMissingChapterCount(chapters: List<ChapterInfo>, mangaStatus: Int): String? {
|
||||
if (mangaStatus == SManga.COMPLETED) return null
|
||||
|
||||
val remove0ChaptersFromCount = chapters.distinctBy {
|
||||
@ -242,14 +242,14 @@ class MdUtil {
|
||||
} else {*/
|
||||
it.name
|
||||
/*}*/
|
||||
}.sortedByDescending { it.chapter_number }
|
||||
}.sortedByDescending { it.number }
|
||||
|
||||
remove0ChaptersFromCount.firstOrNull()?.let { chapter ->
|
||||
val chpNumber = chapter.chapter_number.floor()
|
||||
val chpNumber = chapter.number.floor()
|
||||
val allChapters = (1..chpNumber).toMutableSet()
|
||||
|
||||
remove0ChaptersFromCount.forEach {
|
||||
allChapters.remove(it.chapter_number.floor())
|
||||
allChapters.remove(it.number.floor())
|
||||
}
|
||||
|
||||
if (allChapters.isEmpty()) return null
|
||||
|
Loading…
x
Reference in New Issue
Block a user