MadTheme: Support fetching pages from lazy-loading hosts (like MangaB… (#15758)
MadTheme: Support fetching pages from lazy-loading hosts (like MangaBuddy now)
This commit is contained in:
parent
226d0d662c
commit
b58f4977d0
|
@ -214,8 +214,39 @@ abstract class MadTheme(
|
||||||
val html = document.html()
|
val html = document.html()
|
||||||
|
|
||||||
if (!html.contains("var mainServer = \"")) {
|
if (!html.contains("var mainServer = \"")) {
|
||||||
// No fancy CDN, all images are available directly in <img> tags
|
val chapterImagesFromHtml = document.select("#chapter-images img")
|
||||||
return document.select("#chapter-images img").mapIndexed { index, element ->
|
|
||||||
|
// 17/03/2023: Certain hosts only embed two pages in their "#chapter-images" and leave
|
||||||
|
// the rest to be lazily(?) loaded by javascript. Let's extract `chapImages` and compare
|
||||||
|
// the count against our select query. If both counts are the same, extract the original
|
||||||
|
// images directly from the <img> tags otherwise pick the higher count. (heuristic)
|
||||||
|
// First things first, let's verify `chapImages` actually exists.
|
||||||
|
if (html.contains("var chapImages = '")) {
|
||||||
|
val chapterImagesFromJs = html
|
||||||
|
.substringAfter("var chapImages = '")
|
||||||
|
.substringBefore("'")
|
||||||
|
.split(',')
|
||||||
|
|
||||||
|
// Make sure chapter images we've got from javascript all have a host, otherwise
|
||||||
|
// we've got no choice but to fallback to chapter images from HTML.
|
||||||
|
// TODO: This might need to be solved one day ^
|
||||||
|
if (chapterImagesFromJs.all { e ->
|
||||||
|
e.startsWith("http://") || e.startsWith("https://")
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
// Great, we can use these.
|
||||||
|
if (chapterImagesFromHtml.count() < chapterImagesFromJs.count()) {
|
||||||
|
// Seems like we've hit such a host, let's use the images we've obtained
|
||||||
|
// from the javascript string.
|
||||||
|
return chapterImagesFromJs.mapIndexed { index, path ->
|
||||||
|
Page(index, imageUrl = path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No fancy CDN, all images are available directly in <img> tags (hopefully)
|
||||||
|
return chapterImagesFromHtml.mapIndexed { index, element ->
|
||||||
Page(index, imageUrl = element.attr("abs:data-src"))
|
Page(index, imageUrl = element.attr("abs:data-src"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ class MadThemeGenerator : ThemeSourceGenerator {
|
||||||
|
|
||||||
override val themeClass = "MadTheme"
|
override val themeClass = "MadTheme"
|
||||||
|
|
||||||
override val baseVersionCode: Int = 11
|
override val baseVersionCode: Int = 12
|
||||||
|
|
||||||
override val sources = listOf(
|
override val sources = listOf(
|
||||||
SingleLang("BeeHentai", "https://beehentai.com", "en", isNsfw = true),
|
SingleLang("BeeHentai", "https://beehentai.com", "en", isNsfw = true),
|
||||||
|
|
Loading…
Reference in New Issue