MadTheme: support external chapters (#13758)

* MadTheme: support external chapters

* simplify prefix removal
This commit is contained in:
Vetle Ledaal 2022-10-08 15:44:42 +02:00 committed by GitHub
parent 4bf9327b70
commit 7579ca391f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
@ -203,7 +204,11 @@ abstract class MadTheme(
override fun chapterListSelector(): String = "#chapter-list > li"
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
setUrlWithoutDomain(element.select("a").first()!!.attr("abs:href"))
// Not using setUrlWithoutDomain() to support external chapters
url = element.selectFirst("a")
.absUrl("href")
.removePrefix(baseUrl)
name = element.select(".chapter-title").first()!!.text()
date_upload = parseChapterDate(element.select(".chapter-update").first()?.text())
chapter_number = name.substringAfterLast(' ').toFloatOrNull() ?: -1f
@ -255,6 +260,15 @@ abstract class MadTheme(
}
// Image
override fun pageListRequest(chapter: SChapter): Request {
return if (chapter.url.toHttpUrlOrNull() != null) {
// External chapter
GET(chapter.url, headers)
} else {
super.pageListRequest(chapter)
}
}
override fun imageUrlParse(document: Document): String =
throw UnsupportedOperationException("Not used.")

View File

@ -9,7 +9,7 @@ class MadThemeGenerator : ThemeSourceGenerator {
override val themeClass = "MadTheme"
override val baseVersionCode: Int = 9
override val baseVersionCode: Int = 10
override val sources = listOf(
SingleLang("BeeHentai", "https://beehentai.com", "en", isNsfw = true),