Add support to the new chapter endpoint in Madara (#8594)
* Add support to the new chapter endpoint in Madara. * Remove unused variable. * Fix unsolved reference in a source that used the old method.
This commit is contained in:
parent
20e87bd4a2
commit
9059548257
|
@ -59,14 +59,20 @@ class ArazNovel : Madara("ArazNovel", "https://www.araznovel.com", "tr", SimpleD
|
|||
)
|
||||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
return getXhrChapters(response.asJsoup().select("div#manga-chapters-holder").attr("data-id")).let { document ->
|
||||
document.select("li.parent").let { elements ->
|
||||
val document = response.asJsoup()
|
||||
val mangaId = document.select("div#manga-chapters-holder").attr("data-id")
|
||||
|
||||
val xhrRequest = xhrChaptersRequest(mangaId)
|
||||
val xhrResponse = client.newCall(xhrRequest).execute()
|
||||
|
||||
return xhrResponse.asJsoup().let { xhrDocument ->
|
||||
xhrDocument.select("li.parent").let { elements ->
|
||||
if (!elements.isNullOrEmpty()) {
|
||||
elements.reversed()
|
||||
.map { volumeElement -> volumeElement.select(chapterListSelector()).map { chapterFromElement(it) } }
|
||||
.flatten()
|
||||
} else {
|
||||
document.select(chapterListSelector()).map { chapterFromElement(it) }
|
||||
xhrDocument.select(chapterListSelector()).map { chapterFromElement(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,7 @@ package eu.kanade.tachiyomi.extension.pt.arthurscan
|
|||
|
||||
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
|
||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import org.jsoup.nodes.Document
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -25,32 +20,10 @@ class ArthurScan : Madara(
|
|||
|
||||
override val altName: String = "Nome alternativo: "
|
||||
|
||||
override val useNewChapterEndpoint = true
|
||||
|
||||
override fun popularMangaSelector() = "div.page-item-detail.manga"
|
||||
|
||||
override fun getXhrChapters(mangaId: String): Document {
|
||||
val xhrHeaders = headersBuilder()
|
||||
.add("Referer", baseUrl)
|
||||
.add("X-Requested-With", "XMLHttpRequest")
|
||||
.build()
|
||||
|
||||
val request = POST("$mangaId/ajax/chapters", xhrHeaders)
|
||||
|
||||
return client.newCall(request).execute().asJsoup()
|
||||
}
|
||||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
val document = response.asJsoup()
|
||||
val dataIdSelector = "div[id^=manga-chapters-holder]"
|
||||
|
||||
return document.select(chapterListSelector())
|
||||
.let { elements ->
|
||||
if (elements.isEmpty() && !document.select(dataIdSelector).isNullOrEmpty())
|
||||
getXhrChapters(document.location().removeSuffix("/")).select(chapterListSelector())
|
||||
else elements
|
||||
}
|
||||
.map(::chapterFromElement)
|
||||
}
|
||||
|
||||
// [...document.querySelectorAll('div.genres li a')]
|
||||
// .map(x => `Genre("${x.innerText.slice(1, -4).trim()}", "${x.href.replace(/.*-genre\/(.*)\//, '$1')}")`)
|
||||
// .join(',\n')
|
||||
|
|
|
@ -3,6 +3,9 @@ package eu.kanade.tachiyomi.extension.en.isekaiscancom
|
|||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||
|
||||
class IsekaiScanCom : Madara("IsekaiScan.com", "https://isekaiscan.com", "en") {
|
||||
|
||||
override val useNewChapterEndpoint = true
|
||||
|
||||
override fun getGenreList() = listOf(
|
||||
Genre("4 koma", "4-koma"),
|
||||
Genre("Action", "action"),
|
||||
|
@ -34,7 +37,7 @@ class IsekaiScanCom : Madara("IsekaiScan.com", "https://isekaiscan.com", "en") {
|
|||
Genre("Manhwa", "manhwa"),
|
||||
Genre("Martial arts", "martial-arts"),
|
||||
Genre("Mature", "mature"),
|
||||
Genre("Mature 2", "adult"), //site says Mature 2 but the value is adult
|
||||
Genre("Mature 2", "adult"), // site says Mature 2 but the value is adult
|
||||
Genre("Mature 3", "mature-3"),
|
||||
Genre("Mecha", "mecha"),
|
||||
Genre("Medical", "medical"),
|
||||
|
|
|
@ -130,7 +130,7 @@ abstract class Madara(
|
|||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
|
||||
if (query.startsWith(URL_SEARCH_PREFIX)){
|
||||
val mangaUrl = "$baseUrl/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}"
|
||||
return client.newCall(GET("$baseUrl/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}", headers))
|
||||
return client.newCall(GET(mangaUrl, headers))
|
||||
.asObservable().map { response ->
|
||||
MangasPage(listOf(mangaDetailsParse(response.asJsoup()).apply { url = "/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}/" }), false)
|
||||
}
|
||||
|
@ -400,25 +400,55 @@ abstract class Madara(
|
|||
}
|
||||
}
|
||||
|
||||
protected open fun getXhrChapters(mangaId: String): Document {
|
||||
val xhrHeaders = headersBuilder().add("Content-Type: application/x-www-form-urlencoded; charset=UTF-8")
|
||||
.add("Referer", baseUrl)
|
||||
/**
|
||||
* Set it to true if the source uses the new AJAX endpoint to
|
||||
* fetch the manga chapters instead of the old admin-ajax.php one.
|
||||
*/
|
||||
protected open val useNewChapterEndpoint: Boolean = false
|
||||
|
||||
protected open fun oldXhrChaptersRequest(mangaId: String): Request {
|
||||
val form = FormBody.Builder()
|
||||
.add("action", "manga_get_chapters")
|
||||
.add("manga", mangaId)
|
||||
.build()
|
||||
val body = "action=manga_get_chapters&manga=$mangaId".toRequestBody(null)
|
||||
return client.newCall(POST("$baseUrl/wp-admin/admin-ajax.php", xhrHeaders, body)).execute().asJsoup()
|
||||
|
||||
val xhrHeaders = headersBuilder()
|
||||
.add("Content-Length", form.contentLength().toString())
|
||||
.add("Content-Type", form.contentType().toString())
|
||||
.add("Referer", baseUrl)
|
||||
.add("X-Requested-With", "XMLHttpRequest")
|
||||
.build()
|
||||
|
||||
return POST("$baseUrl/wp-admin/admin-ajax.php", xhrHeaders, form)
|
||||
}
|
||||
|
||||
protected open fun xhrChaptersRequest(mangaUrl: String): Request {
|
||||
val xhrHeaders = headersBuilder()
|
||||
.add("Referer", baseUrl)
|
||||
.add("X-Requested-With", "XMLHttpRequest")
|
||||
.build()
|
||||
|
||||
return POST("$mangaUrl/ajax/chapters", xhrHeaders)
|
||||
}
|
||||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
val document = response.asJsoup()
|
||||
val dataIdSelector = "div[id^=manga-chapters-holder]"
|
||||
val chaptersWrapper = document.select("div[id^=manga-chapters-holder]")
|
||||
|
||||
return document.select(chapterListSelector())
|
||||
.let { elements ->
|
||||
if (elements.isEmpty() && !document.select(dataIdSelector).isNullOrEmpty())
|
||||
getXhrChapters(document.select(dataIdSelector).attr("data-id")).select(chapterListSelector())
|
||||
else elements
|
||||
}
|
||||
.map { chapterFromElement(it) }
|
||||
var chapterElements = document.select(chapterListSelector())
|
||||
|
||||
if (chapterElements.isEmpty() && !chaptersWrapper.isNullOrEmpty()) {
|
||||
val mangaUrl = document.location().removeSuffix("/")
|
||||
val mangaId = chaptersWrapper.attr("data-id")
|
||||
|
||||
val xhrRequest = if (useNewChapterEndpoint) xhrChaptersRequest(mangaUrl) else oldXhrChaptersRequest(mangaId)
|
||||
val xhrResponse = client.newCall(xhrRequest).execute()
|
||||
|
||||
chapterElements = xhrResponse.asJsoup().select(chapterListSelector())
|
||||
xhrResponse.close()
|
||||
}
|
||||
|
||||
return chapterElements.map(::chapterFromElement)
|
||||
}
|
||||
|
||||
override fun chapterListSelector() = "li.wp-manga-chapter"
|
||||
|
|
|
@ -33,9 +33,9 @@ class MadaraGenerator : ThemeSourceGenerator {
|
|||
SingleLang("Aqua Manga", "https://aquamanga.com", "en"),
|
||||
SingleLang("Anisa Manga", "https://anisamanga.com", "tr"),
|
||||
SingleLang("ApollComics", "https://apollcomics.xyz", "es", overrideVersionCode = 1),
|
||||
SingleLang("ArazNovel", "https://www.araznovel.com", "tr", overrideVersionCode = 1),
|
||||
SingleLang("ArazNovel", "https://www.araznovel.com", "tr", overrideVersionCode = 2),
|
||||
SingleLang("Argos Scan", "https://argosscan.com", "pt-BR", overrideVersionCode = 3),
|
||||
SingleLang("Arthur Scan", "https://arthurscan.xyz", "pt-BR", overrideVersionCode = 3),
|
||||
SingleLang("Arthur Scan", "https://arthurscan.xyz", "pt-BR", overrideVersionCode = 4),
|
||||
SingleLang("Astral Library", "https://www.astrallibrary.net", "en", overrideVersionCode = 2),
|
||||
SingleLang("Asura Raw", "https://asuraraw.com", "en"),
|
||||
SingleLang("Atikrost", "https://atikrost.com", "tr", overrideVersionCode = 1),
|
||||
|
@ -115,7 +115,7 @@ class MadaraGenerator : ThemeSourceGenerator {
|
|||
SingleLang("Império Scans", "https://imperioscans.com.br", "pt-BR", className = "ImperioScans"),
|
||||
SingleLang("Império dos Otakus", "https://imperiodosotakus.tk", "pt-BR", className = "ImperioDosOtakus", overrideVersionCode = 2),
|
||||
SingleLang("InfraFandub", "https://infrafandub.xyz", "es"),
|
||||
SingleLang("IsekaiScan.com", "https://isekaiscan.com", "en", className = "IsekaiScanCom", overrideVersionCode = 2),
|
||||
SingleLang("IsekaiScan.com", "https://isekaiscan.com", "en", className = "IsekaiScanCom", overrideVersionCode = 3),
|
||||
SingleLang("IsekaiScanManga (unoriginal)", "https://isekaiscanmanga.com", "en", className = "IsekaiScanManga", overrideVersionCode = 1),
|
||||
SingleLang("Its Your Right Manhua", "https://itsyourightmanhua.com/", "en", overrideVersionCode = 1),
|
||||
SingleLang("JaiminisBox.net", "https://jaiminisbox.net", "en", className = "Jaiminisboxnet"),
|
||||
|
|
Loading…
Reference in New Issue