diff --git a/src/all/madara/build.gradle b/src/all/madara/build.gradle index 29a83f829..71acfa32d 100644 --- a/src/all/madara/build.gradle +++ b/src/all/madara/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Madara' pkgNameSuffix = "all.madara" extClass = '.MadaraFactory' - extVersionCode = 7 + extVersionCode = 8 libVersion = '1.2' } diff --git a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt index 1e02e354b..01fe97395 100644 --- a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt +++ b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt @@ -1,18 +1,18 @@ package eu.kanade.tachiyomi.extension.all.madara +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.POST +import eu.kanade.tachiyomi.network.asObservable import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.* -import org.jsoup.nodes.Document -import org.jsoup.nodes.Element import java.text.ParseException import java.text.SimpleDateFormat import java.util.* -import eu.kanade.tachiyomi.source.model.FilterList -import okhttp3.CacheControl -import okhttp3.FormBody -import okhttp3.Request -import eu.kanade.tachiyomi.network.POST +import java.util.concurrent.TimeUnit +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import rx.Observable open class Madara( override val name: String, @@ -21,6 +21,11 @@ open class Madara( private val dateFormat: SimpleDateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.US) ) : ParsedHttpSource() { + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .build() + override val supportsLatest = true // Popular Manga @@ -62,11 +67,11 @@ open class Madara( return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) } - override fun popularMangaNextPageSelector(): String? = searchMangaNextPageSelector() + override fun popularMangaNextPageSelector(): String? = "body:not(:has(.no-posts))" // Latest Updates - override fun latestUpdatesSelector() = "div.page-item-detail" + override fun latestUpdatesSelector() = popularMangaSelector() override fun latestUpdatesFromElement(element: Element): SManga { // Even if it's different from the popular manga's list, the relevant classes are the same @@ -91,7 +96,7 @@ open class Madara( return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) } - override fun latestUpdatesNextPageSelector(): String? = searchMangaNextPageSelector() + override fun latestUpdatesNextPageSelector(): String? = popularMangaNextPageSelector() override fun latestUpdatesParse(response: Response): MangasPage { val mp = super.latestUpdatesParse(response) @@ -99,24 +104,98 @@ open class Madara( return MangasPage(mangas, mp.hasNextPage) } + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + return client.newCall(searchMangaRequest(page, query, filters)) + .asObservable().doOnNext { response -> + if(!response.isSuccessful) { + response.close() + // Error message for exceeding last page + if (response.code() == 404) + error("Already on the Last Page!") + else throw Exception("HTTP error ${response.code()}") + } + } + .map { response -> + searchMangaParse(response) + } + } + // Search Manga override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val form = FormBody.Builder().apply { - add("action", "madara_load_more") - add("page", (page-1).toString()) - add("template", "madara-core/content/content-search") - add("vars[s]", query) - add("vars[orderby]", "") - add("vars[paged]", (page-1).toString()) - add("vars[template]", "search") - add("vars[post_type]", "wp-manga") - add("vars[post_status]", "publish") - add("vars[manga_archives_item_layout]", "default") + val url = HttpUrl.parse("$baseUrl/page/$page/")!!.newBuilder() + url.addQueryParameter("s", query) + url.addQueryParameter("post_type", "wp-manga") + filters.forEach { filter -> + when (filter) { + is AuthorFilter -> { + if(filter.state.isNotBlank()) { + url.addQueryParameter("author", filter.state) + } + } + is ArtistFilter -> { + if(filter.state.isNotBlank()) { + url.addQueryParameter("artist", filter.state) + } + } + is YearFilter -> { + if(filter.state.isNotBlank()) { + url.addQueryParameter("release", filter.state) + } + } + is StatusFilter -> { + filter.state.forEach { + if (it.state) { + url.addQueryParameter("status[]", it.id) + } + } + } + is OrderByFilter -> { + if(filter.state != 0) { + url.addQueryParameter("m_orderby", filter.toUriPart()) + } + } + } } - return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) + return GET(url.build().toString(), headers) } + private class AuthorFilter : Filter.Text("Author") + private class ArtistFilter : Filter.Text("Artist") + private class YearFilter : Filter.Text("Year of Released") + private class StatusFilter(status: List) : Filter.Group("Status", status) + private class OrderByFilter : UriPartFilter("Order By", arrayOf( + Pair("