diff --git a/src/all/kavita/build.gradle b/src/all/kavita/build.gradle index 307bf378..7175427c 100644 --- a/src/all/kavita/build.gradle +++ b/src/all/kavita/build.gradle @@ -2,7 +2,7 @@ ext { kmkVersionCode = 1 extName = 'Kavita' extClass = '.KavitaFactory' - extVersionCode = 22 + extVersionCode = 23 isNsfw = false } diff --git a/src/all/kavita/src/eu/kanade/tachiyomi/extension/all/kavita/Kavita.kt b/src/all/kavita/src/eu/kanade/tachiyomi/extension/all/kavita/Kavita.kt index 8b67d053..2cb1d1c7 100644 --- a/src/all/kavita/src/eu/kanade/tachiyomi/extension/all/kavita/Kavita.kt +++ b/src/all/kavita/src/eu/kanade/tachiyomi/extension/all/kavita/Kavita.kt @@ -1586,15 +1586,17 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou val allChapters = mutableListOf() - // Get the series name to use as mangaTitle - val seriesName = seriesId?.let { id: Int -> - // First try from cache - series.find { it.id == id }?.name + val seriesDtoForContext = seriesId?.let { id: Int -> + series.find { it.id == id } ?: runCatching { client.newCall(GET("$apiUrl/Series/$id", headersBuilder().build())) - .execute().parseAs().name + .execute().parseAs() }.getOrNull() - } ?: "" + } + + // Get the series name to use as mangaTitle + val seriesName = seriesDtoForContext?.name ?: "" + val isPdfSeries = seriesDtoForContext?.format == MangaFormat.Pdf.format Log.d(LOG_TAG, "Processing chapters for series $seriesId with name: '$seriesName'") @@ -1696,7 +1698,7 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou scanlatorFormat = preferences.scanlatorFormat, volumePageCount = volume.pages, ) - sChapter.url = chapterUrlWithPageCount(chapter, volume.pages) + sChapter.url = chapterUrlWithPageCount(chapter, volume.pages, forceExtractPdf = isPdfSeries) // For singleFileVolume, ensure the scanlator field reflects webtoon terminology sChapter.scanlator = if (isWebtoon) "Season" else "Volume" @@ -1715,7 +1717,7 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou scanlatorFormat = preferences.scanlatorFormat, ) - sChapter.url = chapterUrlWithPageCount(chapter) + sChapter.url = chapterUrlWithPageCount(chapter, forceExtractPdf = isPdfSeries) allChapters.add(sChapter) } @@ -1760,12 +1762,16 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou return GET("$apiUrl/$chapterId", headersBuilder().build()) } - private fun chapterUrlWithPageCount(chapter: ChapterDto, pageCount: Int = chapter.pages): String { + private fun chapterUrlWithPageCount( + chapter: ChapterDto, + pageCount: Int = chapter.pages, + forceExtractPdf: Boolean = false, + ): String { val params = mutableListOf() if (pageCount > 0) { params += "pages=$pageCount" } - params += "extractPdf=${shouldExtractPdf(chapter)}" + params += "extractPdf=${shouldExtractPdf(chapter, forceExtractPdf)}" if (chapter.fileCount > 1) { params += "split=${chapter.fileCount}" } @@ -1784,11 +1790,22 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou .toIntOrNull() ?.takeIf { it > 0 } - private fun shouldExtractPdf(chapter: ChapterDto): Boolean = - chapter.files.orEmpty().any { file -> + private fun shouldExtractPdf(chapter: ChapterDto, forceExtractPdf: Boolean = false): Boolean = + forceExtractPdf || chapter.files.orEmpty().any { file -> file.format == MangaFormat.Pdf.format || file.extension.equals("pdf", ignoreCase = true) } + private fun isPdfSeries(seriesId: Int?): Boolean = + seriesId?.let { id -> + series.find { it.id == id }?.format == MangaFormat.Pdf.format || + runCatching { + client.newCall(GET("$apiUrl/Series/$id", headersBuilder().build())) + .execute() + .parseAs() + .format == MangaFormat.Pdf.format + }.getOrDefault(false) + } ?: false + private fun extractPdfFromChapterUrl(chapter: SChapter): Boolean = chapter.url.substringAfter("extractPdf=", "") .substringBefore("&") @@ -1849,7 +1866,7 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou } // Generate pages with consistent URL format - val extractPdf = shouldExtractPdf(chapterDetails) + val extractPdf = shouldExtractPdf(chapterDetails, isPdfSeries(seriesId)) return@withContext (0 until chapterDetails.pages).map { i -> readerPage(i, chapterDetails.id, extractPdf = extractPdf) } } catch (e: Exception) { Log.e(LOG_TAG, "Error processing reading list item", e) @@ -1885,7 +1902,7 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou .runningFold(0) { acc, chapter -> acc + chapter.pages } .zip(volume.chapters.sortedBy { it.number.toFloatOrNull() ?: 0f }) .flatMap { (startIndex, chapter) -> - val extractPdf = shouldExtractPdf(chapter) + val extractPdf = shouldExtractPdf(chapter, isPdfSeries(volume.seriesId)) (0 until chapter.pages).map { i -> readerPage(startIndex + i, chapter.id, i, extractPdf) } @@ -1923,7 +1940,7 @@ class Kavita(private val suffix: String = "") : ConfigurableSource, UnmeteredSou throw IOException(errorMessage) } - val fetchedExtractPdf = shouldExtractPdf(chapterDetails) + val fetchedExtractPdf = extractPdf || shouldExtractPdf(chapterDetails) return@withContext (0 until chapterDetails.pages).map { i -> readerPage(i, chapterId, extractPdf = fetchedExtractPdf) } } } catch (e: Exception) {