Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@ internal abstract class WebtoonsParser(
}

private suspend fun fetchEpisodes(titleNo: Long): List<MangaChapter> {
val url = "https://$mobileApiDomain/api/v1/webtoon/$titleNo/episodes?pageSize=99999"
val json = webClient.httpGet(url).parseJson()

val episodeList = json.optJSONObject("result")?.optJSONArray("episodeList")
?: throw ParseException("No episodes found for title $titleNo", url)

return episodeList.mapChapters { _, jo ->
val url = "https://$mobileApiDomain/api/v1/webtoon/$titleNo/episodes?pageSize=99999"
val testJson = webClient.httpGet(url).parseJson()
val json = if (testJson.getBoolean("success")) { testJson } else {
val fallbackUrl = url.replace("/webtoon/", "/canvas/")
webClient.httpGet(fallbackUrl).parseJson()
}

val episodeList = json.optJSONObject("result")
?.optJSONArray("episodeList")
?: throw ParseException("No episodes found for title $titleNo", url)

return episodeList.mapChapters { _, jo ->
val episodeTitle = jo.getStringOrNull("episodeTitle") ?: ""
val episodeNo = jo.getInt("episodeNo")
val viewerLink = jo.getString("viewerLink")
Expand Down