Fix the no results found in Madara sources due to a theme update (#16167)

Fix the no results found in Madara sources due to a theme update.
This commit is contained in:
Alessandro Jean 2023-04-24 23:06:34 -03:00 committed by GitHub
parent 2ba79a0094
commit 8e3efc0a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 33 additions and 303 deletions

View File

@ -6,13 +6,11 @@ import okhttp3.CacheControl
import okhttp3.Request import okhttp3.Request
class AdultWebtoon : Madara("Adult Webtoon", "https://adultwebtoon.com", "en") { class AdultWebtoon : Madara("Adult Webtoon", "https://adultwebtoon.com", "en") {
override val useLoadMoreSearch = false
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
val pageSuffix = if (page != 1) "page/$page/" else "" val pageSuffix = if (page != 1) "page/$page/" else ""
return GET( return GET(
"$baseUrl/manga/$pageSuffix?m_orderby=trending", "$baseUrl/manga/$pageSuffix?m_orderby=trending",
formHeaders, headers,
CacheControl.FORCE_NETWORK, CacheControl.FORCE_NETWORK,
) )
} }
@ -20,7 +18,7 @@ class AdultWebtoon : Madara("Adult Webtoon", "https://adultwebtoon.com", "en") {
val pageSuffix = if (page != 1) "page/$page/" else "" val pageSuffix = if (page != 1) "page/$page/" else ""
return GET( return GET(
"$baseUrl/manga/$pageSuffix?m_orderby=latest", "$baseUrl/manga/$pageSuffix?m_orderby=latest",
formHeaders, headers,
CacheControl.FORCE_NETWORK, CacheControl.FORCE_NETWORK,
) )
} }

View File

@ -18,7 +18,6 @@ class AiYuManga : Madara(
SimpleDateFormat("MM/dd/yyyy", Locale("es")), SimpleDateFormat("MM/dd/yyyy", Locale("es")),
) { ) {
override val useNewChapterEndpoint = true override val useNewChapterEndpoint = true
override val useLoadMoreSearch = true
override val chapterUrlSuffix = "" override val chapterUrlSuffix = ""
override val mangaDetailsSelectorStatus = "div.post-content_item:contains(Status) > div.summary-content" override val mangaDetailsSelectorStatus = "div.post-content_item:contains(Status) > div.summary-content"

View File

@ -3,14 +3,11 @@ package eu.kanade.tachiyomi.extension.tr.araznovel
import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.FormBody
import okhttp3.Response import okhttp3.Response
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
class ArazNovel : Madara("ArazNovel", "https://www.araznovel.com", "tr", SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())) { class ArazNovel : Madara("ArazNovel", "https://www.araznovel.com", "tr", SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())) {
override fun formBuilder(page: Int, popular: Boolean): FormBody.Builder = super.formBuilder(page, popular)
.add("vars[meta_query][0][0][value]", "manga")
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup() val document = response.asJsoup()

View File

@ -18,7 +18,6 @@ class DoujinHentai : Madara(
SimpleDateFormat("d MMM. yyyy", Locale.ENGLISH), SimpleDateFormat("d MMM. yyyy", Locale.ENGLISH),
) { ) {
override val useLoadMoreSearch = false
override val fetchGenres = false override val fetchGenres = false
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/lista-manga-hentai?orderby=views&page=$page", headers) override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/lista-manga-hentai?orderby=views&page=$page", headers)

View File

@ -14,7 +14,6 @@ class EGYManga : Madara(
) { ) {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
override val pageListParseSelector = "div.separator" override val pageListParseSelector = "div.separator"

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class FreeMangaTop : Madara("FreeMangaTop", "https://freemangatop.com", "en") { class FreeMangaTop : Madara("FreeMangaTop", "https://freemangatop.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -1,32 +1,14 @@
package eu.kanade.tachiyomi.extension.vi.hentaicube package eu.kanade.tachiyomi.extension.vi.hentaicube
import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import okhttp3.CacheControl
import okhttp3.Request
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
class HentaiCB : Madara("Hentai CB", "https://hencb.top", "vi", SimpleDateFormat("dd/MM/yyyy", Locale("vi"))) { class HentaiCB : Madara("Hentai CB", "https://hencb.top", "vi", SimpleDateFormat("dd/MM/yyyy", Locale("vi"))) {
override val id: Long = 823638192569572166 override val id: Long = 823638192569572166
override val useLoadMoreSearch = false
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
return super.pageListParse(document).distinctBy { it.imageUrl } return super.pageListParse(document).distinctBy { it.imageUrl }
} }
override fun popularMangaRequest(page: Int): Request {
return GET(
"$baseUrl/manga/page/$page/?m_orderby=views",
formHeaders,
CacheControl.FORCE_NETWORK,
)
}
override fun latestUpdatesRequest(page: Int): Request {
return GET(
"$baseUrl/manga/page/$page/?m_orderby=latest",
formHeaders,
CacheControl.FORCE_NETWORK,
)
}
} }

View File

@ -12,6 +12,5 @@ class HentaiManga : Madara(
) { ) {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class HentaiWebtoon : Madara("HentaiWebtoon", "https://hentaiwebtoon.com", "en") { class HentaiWebtoon : Madara("HentaiWebtoon", "https://hentaiwebtoon.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -23,7 +23,6 @@ class InariManga : Madara(
override val mangaDetailsSelectorStatus = "div.card-body tr:has(th:contains(Estatus)) > td" override val mangaDetailsSelectorStatus = "div.card-body tr:has(th:contains(Estatus)) > td"
override val mangaDetailsSelectorGenre = "div.my-auto > div.inline-block > a" override val mangaDetailsSelectorGenre = "div.my-auto > div.inline-block > a"
override val useLoadMoreSearch = false
override val useNewChapterEndpoint = true override val useNewChapterEndpoint = true
override fun chapterListSelector() = "tr.wp-manga-chapter" override fun chapterListSelector() = "tr.wp-manga-chapter"

View File

@ -23,7 +23,6 @@ class InstaManhwa : Madara(
) { ) {
override val supportsLatest: Boolean = false override val supportsLatest: Boolean = false
override val useLoadMoreSearch = false
override val fetchGenres = false override val fetchGenres = false
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/latest?page=$page", headers) override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/latest?page=$page", headers)

View File

@ -30,7 +30,6 @@ class Manga18fx : Madara(
override val fetchGenres = false override val fetchGenres = false
override val sendViewCount = false override val sendViewCount = false
override val useLoadMoreSearch = false
override fun popularMangaRequest(page: Int) = GET(baseUrl, headers) override fun popularMangaRequest(page: Int) = GET(baseUrl, headers)

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class MangaGreat : Madara("MangaGreat", "https://mangagreat.com", "en") { class MangaGreat : Madara("MangaGreat", "https://mangagreat.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -9,7 +9,6 @@ import okhttp3.Response
class ManhuaES : Madara("Manhua ES", "https://manhuaes.com", "en") { class ManhuaES : Madara("Manhua ES", "https://manhuaes.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class ManhuaFast : Madara("ManhuaFast", "https://manhuafast.com", "en") { class ManhuaFast : Madara("ManhuaFast", "https://manhuafast.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class ManhuaPlus : Madara("Manhua Plus", "https://manhuaplus.com", "en") { class ManhuaPlus : Madara("Manhua Plus", "https://manhuaplus.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
override val pageListParseSelector = ".read-container img" override val pageListParseSelector = ".read-container img"

View File

@ -7,6 +7,5 @@ class ManhuaUS : Madara("ManhuaUS", "https://manhuaus.com", "en") {
override val useNewChapterEndpoint: Boolean = true override val useNewChapterEndpoint: Boolean = true
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -37,8 +37,6 @@ abstract class Manhwa18Cc(
lang: String, lang: String,
) : Madara(name, baseUrl, lang, SimpleDateFormat("dd MMM yyyy", Locale.US)) { ) : Madara(name, baseUrl, lang, SimpleDateFormat("dd MMM yyyy", Locale.US)) {
override val useLoadMoreSearch = false
override val fetchGenres = false override val fetchGenres = false
override fun popularMangaSelector() = "div.manga-item" override fun popularMangaSelector() = "div.manga-item"

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class Manhwa18Org : Madara("Manhwa18.org", "https://manhwa18.org", "en") { class Manhwa18Org : Madara("Manhwa18.org", "https://manhwa18.org", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -12,6 +12,5 @@ class Manhwa68 : Madara(
) { ) {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -7,21 +7,19 @@ import okhttp3.Request
class Manhwafull : Madara("Manhwafull", "https://manhwafull.com", "en") { class Manhwafull : Madara("Manhwafull", "https://manhwafull.com", "en") {
override val useLoadMoreSearch = false
override fun popularMangaNextPageSelector(): String? = "a.nextpostslink" override fun popularMangaNextPageSelector(): String? = "a.nextpostslink"
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
return GET( return GET(
"$baseUrl/manga-mwf/page/$page/?m_orderby=views", "$baseUrl/manga-mwf/page/$page/?m_orderby=views",
formHeaders, headers,
CacheControl.FORCE_NETWORK, CacheControl.FORCE_NETWORK,
) )
} }
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
return GET( return GET(
"$baseUrl/manga-mwf/page/$page/?m_orderby=latest", "$baseUrl/manga-mwf/page/$page/?m_orderby=latest",
formHeaders, headers,
CacheControl.FORCE_NETWORK, CacheControl.FORCE_NETWORK,
) )
} }

View File

@ -21,8 +21,6 @@ class ManhwaLatino : Madara(
override val supportsLatest = false override val supportsLatest = false
override val useLoadMoreSearch = false
override val useNewChapterEndpoint = true override val useNewChapterEndpoint = true
override val chapterUrlSelector = "a:eq(1)" override val chapterUrlSelector = "a:eq(1)"

View File

@ -16,7 +16,6 @@ class ManhwasMen : Madara("Manhwas Men", "https://manhwas.men", "en") {
override val fetchGenres = false override val fetchGenres = false
override val sendViewCount = false override val sendViewCount = false
override val useLoadMoreSearch = false
// popular // popular
override fun popularMangaSelector() = "div.col-6" override fun popularMangaSelector() = "div.col-6"

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class Manhwatop : Madara("Manhwatop", "https://manhwatop.com", "en") { class Manhwatop : Madara("Manhwatop", "https://manhwatop.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -7,6 +7,5 @@ class ManyToonMe : Madara("ManyToon.me", "https://manytoon.me", "en") {
override val useNewChapterEndpoint: Boolean = true override val useNewChapterEndpoint: Boolean = true
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -1,11 +0,0 @@
package eu.kanade.tachiyomi.extension.en.nightcomic
import eu.kanade.tachiyomi.multisrc.madara.Madara
import okhttp3.Headers
class NightComic : Madara("Night Comic", "https://www.nightcomic.com", "en") {
override val formHeaders: Headers = headersBuilder()
.add("Content-Type", "application/x-www-form-urlencoded")
.add("X-MOD-SBB-CTYPE", "xhr")
.build()
}

View File

@ -11,8 +11,6 @@ import java.util.Locale
class PojokManga : Madara("Pojok Manga", "https://pojokmanga.net", "id", SimpleDateFormat("MMM dd, yyyy", Locale.US)) { class PojokManga : Madara("Pojok Manga", "https://pojokmanga.net", "id", SimpleDateFormat("MMM dd, yyyy", Locale.US)) {
override val useLoadMoreSearch = false
override val useNewChapterEndpoint = true override val useNewChapterEndpoint = true
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {

View File

@ -14,7 +14,6 @@ class ShieldManga : Madara("Shield Manga", "https://shieldmanga.io", "en") {
.build() .build()
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
override fun chapterListSelector() = "li.wp-manga-hapter, .version-chap li" override fun chapterListSelector() = "li.wp-manga-hapter, .version-chap li"

View File

@ -1,16 +1,10 @@
package eu.kanade.tachiyomi.extension.en.shoujohearts package eu.kanade.tachiyomi.extension.en.shoujohearts
import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.POST
import okhttp3.CacheControl
import okhttp3.Request
class ShoujoHearts : Madara("ShoujoHearts", "https://shoujohearts.com", "en") { class ShoujoHearts : Madara("ShoujoHearts", "https://shoujohearts.com", "en") {
override fun popularMangaRequest(page: Int): Request =
POST("$baseUrl/reader/wp-admin/admin-ajax.php", formHeaders, formBuilder(page, true).build(), CacheControl.FORCE_NETWORK)
override fun latestUpdatesRequest(page: Int): Request = override val mangaSubString = "reader/manga"
POST("$baseUrl/reader/wp-admin/admin-ajax.php", formHeaders, formBuilder(page, false).build(), CacheControl.FORCE_NETWORK)
override fun searchPage(page: Int): String = "reader/page/$page/" override fun searchPage(page: Int): String = "reader/page/$page/"
} }

View File

@ -11,7 +11,6 @@ class ToonGod : Madara("ToonGod", "https://www.toongod.com", "en", SimpleDateFor
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/webtoons/page/$page/?m_orderby=views", headers) override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/webtoons/page/$page/?m_orderby=views", headers)
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/webtoons/page/$page/?m_orderby=latest", headers) override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/webtoons/page/$page/?m_orderby=latest", headers)
override val mangaSubString = "webtoons" override val mangaSubString = "webtoons"
override val useLoadMoreSearch = false
override fun imageRequest(page: Page): Request { override fun imageRequest(page: Page): Request {
return GET(page.imageUrl!!, headers) return GET(page.imageUrl!!, headers)
} }

View File

@ -9,6 +9,5 @@ class TopManhua : Madara("Top Manhua", "https://topmanhua.com", "en", SimpleDate
override fun headersBuilder(): Headers.Builder = super.headersBuilder().add("Referer", baseUrl) override fun headersBuilder(): Headers.Builder = super.headersBuilder().add("Referer", baseUrl)
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -13,7 +13,6 @@ class VerManhwas : Madara(
dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("es")), dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("es")),
) { ) {
override val useNewChapterEndpoint = true override val useNewChapterEndpoint = true
override val useLoadMoreSearch = false
override fun genresRequest(): Request { override fun genresRequest(): Request {
return GET("$baseUrl/?s=&post_type=wp-manga", headers) return GET("$baseUrl/?s=&post_type=wp-manga", headers)

View File

@ -26,11 +26,6 @@ class YugenMangas : Madara(
.add("Origin", baseUrl) .add("Origin", baseUrl)
.add("Referer", "$baseUrl/") .add("Referer", "$baseUrl/")
override val formHeaders: Headers = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest")
.set("Referer", "$baseUrl/todas-las-series/")
.build()
override val useNewChapterEndpoint: Boolean = true override val useNewChapterEndpoint: Boolean = true
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply { override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {

View File

@ -5,6 +5,5 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
class Zinmanga : Madara("Zinmanga", "https://zinmanga.com", "en") { class Zinmanga : Madara("Zinmanga", "https://zinmanga.com", "en") {
// The website does not flag the content. // The website does not flag the content.
override val useLoadMoreSearch = false
override val filterNonMangaItems = false override val filterNonMangaItems = false
} }

View File

@ -143,11 +143,21 @@ abstract class Madara(
protected open val json: Json by injectLazy() protected open val json: Json by injectLazy()
/** /**
* If enabled, will remove non-manga items in search. * If enabled, will attempt to remove non-manga items in popular and latest.
* The filter will not be used in search as the theme doesn't set the CSS class.
* Can be disabled if the source incorrectly sets the entry types. * Can be disabled if the source incorrectly sets the entry types.
*/ */
protected open val filterNonMangaItems = true protected open val filterNonMangaItems = true
/**
* The CSS selector used to filter manga items in popular and latest
* if `filterNonMangaItems` is set to `true`. Can be override if needed.
* If the flag is set to `false`, it will be empty by default.
*/
protected open val mangaEntrySelector: String by lazy {
if (filterNonMangaItems) ".manga" else ""
}
/** /**
* Automatically fetched genres from the source to be used in the filters. * Automatically fetched genres from the source to be used in the filters.
*/ */
@ -179,7 +189,7 @@ abstract class Madara(
} }
// exclude/filter bilibili manga from list // exclude/filter bilibili manga from list
override fun popularMangaSelector() = "div.page-item-detail:not(:has(a[href*='bilibilicomics.com']))" override fun popularMangaSelector() = "div.page-item-detail:not(:has(a[href*='bilibilicomics.com']))$mangaEntrySelector"
open val popularMangaUrlSelector = "div.post-title a" open val popularMangaUrlSelector = "div.post-title a"
@ -200,38 +210,15 @@ abstract class Madara(
return manga return manga
} }
open fun formBuilder(page: Int, popular: Boolean) = FormBody.Builder().apply {
add("action", "madara_load_more")
add("page", (page - 1).toString())
add("template", "madara-core/content/content-archive")
add("vars[orderby]", "meta_value_num")
add("vars[paged]", "1")
add("vars[posts_per_page]", "20")
add("vars[post_type]", "wp-manga")
add("vars[post_status]", "publish")
add("vars[meta_key]", if (popular) "_wp_manga_views" else "_latest_update")
add("vars[order]", "desc")
add("vars[sidebar]", if (popular) "full" else "right")
add("vars[manga_archives_item_layout]", "big_thumbnail")
if (filterNonMangaItems) {
add("vars[meta_query][0][key]", "_wp_manga_chapter_type")
add("vars[meta_query][0][value]", "manga")
}
}
open val formHeaders: Headers by lazy { headersBuilder().build() }
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
return POST( return GET(
"$baseUrl/wp-admin/admin-ajax.php", url = "$baseUrl/$mangaSubString/${searchPage(page)}?m_orderby=views",
formHeaders, headers = headers,
formBuilder(page, true).build(), cache = CacheControl.FORCE_NETWORK,
CacheControl.FORCE_NETWORK,
) )
} }
override fun popularMangaNextPageSelector(): String? = "body:not(:has(.no-posts))" override fun popularMangaNextPageSelector(): String? = searchMangaNextPageSelector()
// Latest Updates // Latest Updates
@ -243,7 +230,11 @@ abstract class Madara(
} }
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
return POST("$baseUrl/wp-admin/admin-ajax.php", formHeaders, formBuilder(page, false).build(), CacheControl.FORCE_NETWORK) return GET(
url = "$baseUrl/$mangaSubString/${searchPage(page)}?m_orderby=latest",
headers = headers,
cache = CacheControl.FORCE_NETWORK,
)
} }
override fun latestUpdatesNextPageSelector(): String? = popularMangaNextPageSelector() override fun latestUpdatesNextPageSelector(): String? = popularMangaNextPageSelector()
@ -258,39 +249,15 @@ abstract class Madara(
open val mangaSubString = "manga" open val mangaSubString = "manga"
/**
* If enabled, the search will use the madara_load_more action instead of
* the normal page. This allows more control over the query and will permit
* the filtering of non-manga items such as novels or videos.
*/
open val useLoadMoreSearch = true
open fun searchFormBuilder(page: Int, showOnlyManga: Boolean): FormBody.Builder = FormBody.Builder().apply {
add("action", "madara_load_more")
add("page", (page - 1).toString())
add("template", "madara-core/content/content-search")
add("vars[paged]", "1")
add("vars[template]", "archive")
add("vars[sidebar]", "right")
add("vars[post_type]", "wp-manga")
add("vars[post_status]", "publish")
add("vars[manga_archives_item_layout]", "big_thumbnail")
add("vars[posts_per_page]", "20")
if (filterNonMangaItems && showOnlyManga) {
add("vars[meta_query][0][key]", "_wp_manga_chapter_type")
add("vars[meta_query][0][value]", "manga")
}
}
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> { override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
if (query.startsWith(URL_SEARCH_PREFIX) && !useLoadMoreSearch) { if (query.startsWith(URL_SEARCH_PREFIX)) {
val mangaUrl = "$baseUrl/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}" val mangaUrl = "$baseUrl/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}"
return client.newCall(GET(mangaUrl, headers)) return client.newCall(GET(mangaUrl, headers))
.asObservable().map { response -> .asObservable().map { response ->
MangasPage(listOf(mangaDetailsParse(response.asJsoup()).apply { url = "/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}/" }), false) MangasPage(listOf(mangaDetailsParse(response.asJsoup()).apply { url = "/$mangaSubString/${query.substringAfter(URL_SEARCH_PREFIX)}/" }), false)
} }
} }
return client.newCall(searchMangaRequest(page, query, filters)) return client.newCall(searchMangaRequest(page, query, filters))
.asObservable().doOnNext { response -> .asObservable().doOnNext { response ->
if (!response.isSuccessful) { if (!response.isSuccessful) {
@ -311,10 +278,6 @@ abstract class Madara(
protected open fun searchPage(page: Int): String = "page/$page/" protected open fun searchPage(page: Int): String = "page/$page/"
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
if (useLoadMoreSearch) {
return searchLoadMoreRequest(page, query, filters)
}
val url = "$baseUrl/${searchPage(page)}".toHttpUrlOrNull()!!.newBuilder() val url = "$baseUrl/${searchPage(page)}".toHttpUrlOrNull()!!.newBuilder()
url.addQueryParameter("s", query) url.addQueryParameter("s", query)
url.addQueryParameter("post_type", "wp-manga") url.addQueryParameter("post_type", "wp-manga")
@ -366,148 +329,6 @@ abstract class Madara(
return GET(url.toString(), headers) return GET(url.toString(), headers)
} }
protected open fun searchLoadMoreRequest(page: Int, query: String, filters: FilterList): Request {
val showOnlyManga = filters.filterIsInstance<ShowOnlyMangaFilter>()
.firstOrNull()?.state ?: true
val formBodyBuilder = searchFormBuilder(page, showOnlyManga).apply {
if (query.startsWith(URL_SEARCH_PREFIX)) {
add("vars[name]", query.removePrefix(URL_SEARCH_PREFIX))
return@apply
}
add("vars[s]", query)
var metaQueryIdx = if (filterNonMangaItems && showOnlyManga) 1 else 0
var taxQueryIdx = 0
val genres = filters.filterIsInstance<GenreList>().firstOrNull()?.state
?.filter { it.state }
?.map { it.id }
.orEmpty()
filters.forEach { filter ->
when (filter) {
is AuthorFilter -> {
if (filter.state.isNotBlank()) {
add("vars[tax_query][$taxQueryIdx][taxonomy]", "wp-manga-author")
add("vars[tax_query][$taxQueryIdx][field]", "name")
add("vars[tax_query][$taxQueryIdx][terms]", filter.state)
taxQueryIdx++
}
}
is ArtistFilter -> {
if (filter.state.isNotBlank()) {
add("vars[tax_query][$taxQueryIdx][taxonomy]", "wp-manga-artist")
add("vars[tax_query][$taxQueryIdx][field]", "name")
add("vars[tax_query][$taxQueryIdx][terms]", filter.state)
taxQueryIdx++
}
}
is YearFilter -> {
if (filter.state.isNotBlank()) {
add("vars[tax_query][$taxQueryIdx][taxonomy]", "wp-manga-release")
add("vars[tax_query][$taxQueryIdx][field]", "name")
add("vars[tax_query][$taxQueryIdx][terms]", filter.state)
taxQueryIdx++
}
}
is StatusFilter -> {
val statuses = filter.state
.filter { it.state }
.map { it.id }
if (statuses.isNotEmpty()) {
add("vars[meta_query][$metaQueryIdx][key]", "_wp_manga_status")
statuses.forEachIndexed { i, slug ->
add("vars[meta_query][$metaQueryIdx][value][$i]", slug)
}
metaQueryIdx++
}
}
is OrderByFilter -> {
if (filter.state != 0) {
when (filter.toUriPart()) {
"latest" -> {
add("vars[orderby]", "meta_value_num")
add("vars[order]", "DESC")
add("vars[meta_key]", "_latest_update")
}
"alphabet" -> {
add("vars[orderby]", "post_title")
add("vars[order]", "ASC")
}
"rating" -> {
add("vars[orderby][query_average_reviews]", "DESC")
add("vars[orderby][query_total_reviews]", "DESC")
}
"trending" -> {
add("vars[orderby]", "meta_value_num")
add("vars[meta_key]", "_wp_manga_week_views_value")
add("vars[order]", "DESC")
}
"views" -> {
add("vars[orderby]", "meta_value_num")
add("vars[meta_key]", "_wp_manga_views")
add("vars[order]", "DESC")
}
else -> {
add("vars[orderby]", "date")
add("vars[order]", "DESC")
}
}
}
}
is AdultContentFilter -> {
if (filter.state != 0) {
add("vars[meta_query][$metaQueryIdx][key]", "manga_adult_content")
add(
"vars[meta_query][$metaQueryIdx][compare]",
if (filter.state == 1) "not exists" else "exists",
)
metaQueryIdx++
}
}
is GenreConditionFilter -> {
if (filter.state == 1 && genres.isNotEmpty()) {
add("vars[tax_query][$taxQueryIdx][operation]", "AND")
}
}
is GenreList -> {
if (genres.isNotEmpty()) {
add("vars[tax_query][$taxQueryIdx][taxonomy]", "wp-manga-genre")
add("vars[tax_query][$taxQueryIdx][field]", "slug")
genres.forEachIndexed { i, slug ->
add("vars[tax_query][$taxQueryIdx][terms][$i]", slug)
}
taxQueryIdx++
}
}
else -> {}
}
}
}
val searchHeaders = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest")
.build()
return POST(
"$baseUrl/wp-admin/admin-ajax.php",
searchHeaders,
formBodyBuilder.build(),
CacheControl.FORCE_NETWORK,
)
}
protected open val authorFilterTitle: String = when (lang) { protected open val authorFilterTitle: String = when (lang) {
"pt-BR" -> "Autor" "pt-BR" -> "Autor"
else -> "Author" else -> "Author"
@ -611,11 +432,6 @@ abstract class Madara(
else -> "Press 'Reset' to attempt to show the genres" else -> "Press 'Reset' to attempt to show the genres"
} }
protected open val showOnlyMangaEntriesLabel: String = when (lang) {
"pt-BR" -> "Mostrar somente mangás"
else -> "Show only manga entries"
}
protected class AuthorFilter(title: String) : Filter.Text(title) protected class AuthorFilter(title: String) : Filter.Text(title)
protected class ArtistFilter(title: String) : Filter.Text(title) protected class ArtistFilter(title: String) : Filter.Text(title)
protected class YearFilter(title: String) : Filter.Text(title) protected class YearFilter(title: String) : Filter.Text(title)
@ -638,8 +454,6 @@ abstract class Madara(
protected class GenreList(title: String, genres: List<Genre>) : Filter.Group<Genre>(title, genres) protected class GenreList(title: String, genres: List<Genre>) : Filter.Group<Genre>(title, genres)
class Genre(name: String, val id: String = name) : Filter.CheckBox(name) class Genre(name: String, val id: String = name) : Filter.CheckBox(name)
protected class ShowOnlyMangaFilter(label: String) : Filter.CheckBox(label, true)
override fun getFilterList(): FilterList { override fun getFilterList(): FilterList {
val filters = mutableListOf( val filters = mutableListOf(
AuthorFilter(authorFilterTitle), AuthorFilter(authorFilterTitle),
@ -647,17 +461,13 @@ abstract class Madara(
YearFilter(yearFilterTitle), YearFilter(yearFilterTitle),
StatusFilter(statusFilterTitle, getStatusList()), StatusFilter(statusFilterTitle, getStatusList()),
OrderByFilter( OrderByFilter(
orderByFilterTitle, title = orderByFilterTitle,
orderByFilterOptions.zip(orderByFilterOptionsValues), options = orderByFilterOptions.zip(orderByFilterOptionsValues),
if (useLoadMoreSearch) 5 else 0, state = 0,
), ),
AdultContentFilter(adultContentFilterTitle, adultContentFilterOptions), AdultContentFilter(adultContentFilterTitle, adultContentFilterOptions),
) )
if (useLoadMoreSearch) {
filters.add(ShowOnlyMangaFilter(showOnlyMangaEntriesLabel))
}
if (genresList.isNotEmpty()) { if (genresList.isNotEmpty()) {
filters += listOf( filters += listOf(
Filter.Separator(), Filter.Separator(),
@ -709,10 +519,7 @@ abstract class Madara(
return manga return manga
} }
override fun searchMangaNextPageSelector(): String? = when { override fun searchMangaNextPageSelector(): String? = "div.nav-previous, nav.navigation-ajax, a.nextpostslink"
useLoadMoreSearch -> popularMangaNextPageSelector()
else -> "div.nav-previous, nav.navigation-ajax, a.nextpostslink"
}
// Manga Details Parse // Manga Details Parse