Fix search limited to 10 results in Madara sources (#11359)
* Fix search limited to 10 results in Madara sources. * Fix wrong posts_per_page key in search.
This commit is contained in:
parent
cb7d9ad482
commit
9e8cef623b
@ -4,6 +4,15 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
class Toonily : Madara("Toonily", "https://toonily.com", "en", SimpleDateFormat("MMM d, yy", Locale.US)) {
|
||||
class Toonily : Madara(
|
||||
"Toonily",
|
||||
"https://toonily.com",
|
||||
"en",
|
||||
SimpleDateFormat("MMM d, yy", Locale.US)
|
||||
) {
|
||||
|
||||
// The source customized the Madara theme and broke the filter.
|
||||
override val filterNonMangaItems = false
|
||||
|
||||
override val useNewChapterEndpoint: Boolean = true
|
||||
}
|
||||
|
@ -61,12 +61,32 @@ abstract class Madara(
|
||||
*/
|
||||
protected open val filterNonMangaItems = true
|
||||
|
||||
/**
|
||||
* Automatically fetched genres from the source to be used in the filters.
|
||||
*/
|
||||
private var genresList: List<Genre> = emptyList()
|
||||
|
||||
/**
|
||||
* Inner variable to control the genre fetching state.
|
||||
*/
|
||||
private var fetchGenresFailed: Boolean = false
|
||||
|
||||
/**
|
||||
* Inner variable to control how much tries the genres request was called.
|
||||
*/
|
||||
private var fetchGenresCount: Int = 0
|
||||
|
||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/78.0$userAgentRandomizer")
|
||||
.add("Referer", baseUrl)
|
||||
|
||||
// Popular Manga
|
||||
|
||||
override fun popularMangaParse(response: Response): MangasPage {
|
||||
fetchGenres()
|
||||
return super.popularMangaParse(response)
|
||||
}
|
||||
|
||||
// exclude/filter bilibili manga from list
|
||||
override fun popularMangaSelector() = "div.page-item-detail:not(:has(a[href*='bilibilicomics.com']))"
|
||||
|
||||
@ -154,9 +174,9 @@ abstract class Madara(
|
||||
*/
|
||||
open val useLoadMoreSearch = true
|
||||
|
||||
open fun searchFormBuilder(showOnlyManga: Boolean): FormBody.Builder = FormBody.Builder().apply {
|
||||
open fun searchFormBuilder(page: Int, showOnlyManga: Boolean): FormBody.Builder = FormBody.Builder().apply {
|
||||
add("action", "madara_load_more")
|
||||
add("page", "0")
|
||||
add("page", (page - 1).toString())
|
||||
add("template", "madara-core/content/content-search")
|
||||
add("vars[paged]", "1")
|
||||
add("vars[template]", "archive")
|
||||
@ -164,7 +184,7 @@ abstract class Madara(
|
||||
add("vars[post_type]", "wp-manga")
|
||||
add("vars[post_status]", "publish")
|
||||
add("vars[manga_archives_item_layout]", "big_thumbnail")
|
||||
add("vars[post_per_page]", "20")
|
||||
add("vars[posts_per_page]", "20")
|
||||
|
||||
if (filterNonMangaItems && showOnlyManga) {
|
||||
add("vars[meta_query][0][key]", "_wp_manga_chapter_type")
|
||||
@ -195,18 +215,6 @@ abstract class Madara(
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun parseGenres(document: Document): List<Genre> {
|
||||
return document.selectFirst("div.checkbox-group")
|
||||
?.select("div.checkbox")
|
||||
.orEmpty()
|
||||
.map { li ->
|
||||
Genre(
|
||||
li.selectFirst("label").text(),
|
||||
li.selectFirst("input[type=checkbox]").`val`()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun searchPage(page: Int): String = "page/$page/"
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
@ -268,7 +276,7 @@ abstract class Madara(
|
||||
val showOnlyManga = filters.filterIsInstance<ShowOnlyMangaFilter>()
|
||||
.firstOrNull()?.state ?: true
|
||||
|
||||
val formBodyBuilder = searchFormBuilder(showOnlyManga).apply {
|
||||
val formBodyBuilder = searchFormBuilder(page, showOnlyManga).apply {
|
||||
if (query.startsWith(URL_SEARCH_PREFIX)) {
|
||||
add("vars[name]", query.removePrefix(URL_SEARCH_PREFIX))
|
||||
|
||||
@ -513,8 +521,6 @@ abstract class Madara(
|
||||
|
||||
protected class ShowOnlyMangaFilter(label: String) : Filter.CheckBox(label, true)
|
||||
|
||||
private var genresList: List<Genre> = emptyList()
|
||||
|
||||
override fun getFilterList(): FilterList {
|
||||
val filters = mutableListOf(
|
||||
AuthorFilter(authorFilterTitle),
|
||||
@ -556,6 +562,11 @@ abstract class Madara(
|
||||
|
||||
open class Tag(val id: String, name: String) : Filter.CheckBox(name)
|
||||
|
||||
override fun searchMangaParse(response: Response): MangasPage {
|
||||
fetchGenres()
|
||||
return super.searchMangaParse(response)
|
||||
}
|
||||
|
||||
override fun searchMangaSelector() = "div.c-tabs-item__content"
|
||||
|
||||
override fun searchMangaFromElement(element: Element): SManga {
|
||||
@ -574,7 +585,10 @@ abstract class Madara(
|
||||
return manga
|
||||
}
|
||||
|
||||
override fun searchMangaNextPageSelector(): String? = "div.nav-previous, nav.navigation-ajax, a.nextpostslink"
|
||||
override fun searchMangaNextPageSelector(): String? = when {
|
||||
useLoadMoreSearch -> popularMangaNextPageSelector()
|
||||
else -> "div.nav-previous, nav.navigation-ajax, a.nextpostslink"
|
||||
}
|
||||
|
||||
// Manga Details Parse
|
||||
|
||||
@ -950,17 +964,50 @@ abstract class Madara(
|
||||
runCatching { client.newCall(request).execute().close() }
|
||||
}
|
||||
|
||||
init {
|
||||
if (fetchGenresOnInit && genresList.isEmpty()) {
|
||||
Single
|
||||
.fromCallable {
|
||||
val genres = runCatching {
|
||||
client.newCall(GET("$baseUrl/?s=&post_type=wp-manga")).execute()
|
||||
.use { parseGenres(it.asJsoup()) }
|
||||
}
|
||||
/**
|
||||
* Fetch the genres from the source to be used in the filters.
|
||||
*/
|
||||
protected open fun fetchGenres() {
|
||||
if (fetchGenresCount <= 3 && (genresList.isEmpty() || fetchGenresFailed)) {
|
||||
val genres = runCatching {
|
||||
client.newCall(genresRequest()).execute()
|
||||
.use { parseGenres(it.asJsoup()) }
|
||||
}
|
||||
|
||||
genresList = genres.getOrNull().orEmpty()
|
||||
}
|
||||
fetchGenresFailed = genres.isFailure
|
||||
genresList = genres.getOrNull().orEmpty()
|
||||
fetchGenresCount++
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The request to the search page (or another one) that have the genres list.
|
||||
*/
|
||||
protected open fun genresRequest(): Request {
|
||||
return GET("$baseUrl/?s=&post_type=wp-manga", headers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the genres from the search page document.
|
||||
*
|
||||
* @param document The search page document
|
||||
*/
|
||||
protected open fun parseGenres(document: Document): List<Genre> {
|
||||
return document.selectFirst("div.checkbox-group")
|
||||
?.select("div.checkbox")
|
||||
.orEmpty()
|
||||
.map { li ->
|
||||
Genre(
|
||||
li.selectFirst("label").text(),
|
||||
li.selectFirst("input[type=checkbox]").`val`()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
if (fetchGenresOnInit) {
|
||||
Single
|
||||
.fromCallable { fetchGenres() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
|
@ -10,7 +10,7 @@ class MadaraGenerator : ThemeSourceGenerator {
|
||||
|
||||
override val themeClass = "Madara"
|
||||
|
||||
override val baseVersionCode: Int = 18
|
||||
override val baseVersionCode: Int = 19
|
||||
|
||||
override val sources = listOf(
|
||||
MultiLang("Leviatan Scans", "https://leviatanscans.com", listOf("en", "es"), className = "LeviatanScansFactory", overrideVersionCode = 9),
|
||||
|
Loading…
x
Reference in New Issue
Block a user