Skip to content

Commit

Permalink
Improve GigaViewer chapter list parse to fix NullPointerException (#6514
Browse files Browse the repository at this point in the history
)

* Improved chapter list parsing

Uses a more generic method of getting chapter information that resolves compatibility issues caused by sites that use a paginated version of the GigaViewer chapter list

* Increment GigaViewer base version code
  • Loading branch information
hatozuki-programmer authored Dec 8, 2024
1 parent a88ad07 commit a0467ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib-multisrc/gigaviewer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ plugins {
id("lib-multisrc")
}

baseVersionCode = 5
baseVersionCode = 6
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Call
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request
Expand Down Expand Up @@ -137,19 +136,22 @@ abstract class GigaViewer(

override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup()
val readableProductList = document.selectFirst("div.js-readable-product-list")!!
val firstListEndpoint = readableProductList.attr("data-first-list-endpoint")
.toHttpUrl()
val latestListEndpoint = readableProductList.attr("data-latest-list-endpoint")
.toHttpUrlOrNull() ?: firstListEndpoint
val numberSince = latestListEndpoint.queryParameter("number_since")!!.toFloat()
.coerceAtLeast(firstListEndpoint.queryParameter("number_since")!!.toFloat())
val aggregateId = document.selectFirst("script.js-valve")!!.attr("data-giga_series")

val newHeaders = headers.newBuilder()
.set("Referer", response.request.url.toString())
.build()
var readMoreEndpoint = firstListEndpoint.newBuilder()
.setQueryParameter("number_since", numberSince.toString())

var readMoreEndpoint = baseUrl.toHttpUrl().newBuilder()
.addPathSegment("api")
.addPathSegment("viewer")
.addPathSegment("readable_products")
.addQueryParameter("aggregate_id", aggregateId)
.addQueryParameter("number_since", Int.MAX_VALUE.toString())
.addQueryParameter("number_until", "0")
.addQueryParameter("read_more_num", "150")
.addQueryParameter("type", "episode")
.build()
.toString()

val chapters = mutableListOf<SChapter>()
Expand Down

0 comments on commit a0467ce

Please sign in to comment.