From f1d84ccb49f1891bdbb1a9b7c960174606300a70 Mon Sep 17 00:00:00 2001 From: paronos Date: Sat, 24 Dec 2016 00:08:49 +0100 Subject: [PATCH] Add "Completed" filter; fix Mangahere; fix Mangafox (#604) * Add "Compled" filter to all english sources; fix Mangahere manga title extraction; fix Mangafox search. * update Mangasee * update Batoto --- .../data/source/online/english/Batoto.kt | 19 +++++++++++++------ .../data/source/online/english/Kissmanga.kt | 6 ++++-- .../data/source/online/english/Mangafox.kt | 5 +++-- .../data/source/online/english/Mangahere.kt | 16 +++++++++------- .../data/source/online/english/Mangasee.kt | 16 +++++++++++++--- .../source/online/english/Readmangatoday.kt | 8 ++++++-- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt index db5a96ad7..028e24fda 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt @@ -109,12 +109,17 @@ class Batoto(override val id: Int) : ParsedOnlineSource(), LoginSource { override fun latestUpdatesNextPageSelector() = "#show_more_row" - override fun searchMangaInitialUrl(query: String, filters: List) = "$baseUrl/search_ajax?name=${Uri.encode(query)}&order_cond=views&order=desc&p=1&genre_cond=and&genres=${getFilterParams(filters)}" + override fun searchMangaInitialUrl(query: String, filters: List) = "$baseUrl/search_ajax?name=${Uri.encode(query)}&order_cond=views&order=desc&p=1${getFilterParams(filters)}" - private fun getFilterParams(filters: List): String = filters - .map { - ";i" + it.id - }.joinToString() + private fun getFilterParams(filters: List): String { + var genres = "" + var completed = "" + for (filter in filters) { + if (filter.equals(completedFilter)) completed = "&completed=c" + else genres += ";i" + filter.id + } + return if (genres.isEmpty()) completed else "&genres=$genres&genre_cond=and$completed" + } override fun searchMangaRequest(page: MangasPage, query: String, filters: List): Request { if (page.page == 1) { @@ -133,7 +138,7 @@ class Batoto(override val id: Int) : ParsedOnlineSource(), LoginSource { } page.nextPageUrl = document.select(searchMangaNextPageSelector()).first()?.let { - "$baseUrl/search_ajax?name=${Uri.encode(query)}&p=${page.page + 1}&order_cond=views&order=desc&genre_cond=and&genres=" + getFilterParams(filters) + "$baseUrl/search_ajax?name=${Uri.encode(query)}&order_cond=views&order=desc&p=${page.page + 1}${getFilterParams(filters)}" } } @@ -301,11 +306,13 @@ class Batoto(override val id: Int) : ParsedOnlineSource(), LoginSource { } } + private val completedFilter = Filter("completed", "Completed") // [...document.querySelectorAll("#advanced_options div.genre_buttons")].map((el,i) => { // const onClick=el.getAttribute('onclick');const id=onClick.substr(14,onClick.length-16);return `Filter("${id}", "${el.textContent.trim()}")` // }).join(',\n') // on https://bato.to/search override fun getFilterList(): List = listOf( + completedFilter, Filter("40", "4-Koma"), Filter("1", "Action"), Filter("2", "Adventure"), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt index 5b10172eb..c8c45b0c1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt @@ -62,10 +62,10 @@ class Kissmanga(override val id: Int) : ParsedOnlineSource() { val form = FormBody.Builder().apply { add("authorArtist", "") add("mangaName", query) - add("status", "") this@Kissmanga.filters.forEach { filter -> - add("genres", if (filter in filters) "1" else "0") + if (filter.equals(completedFilter)) add("status", if (filter in filters) filter.id else "") + else add("genres", if (filter in filters) "1" else "0") } } @@ -131,9 +131,11 @@ class Kissmanga(override val id: Int) : ParsedOnlineSource() { override fun imageUrlParse(document: Document) = "" + private val completedFilter = Filter("Completed", "Completed") // $("select[name=\"genres\"]").map((i,el) => `Filter("${i}", "${$(el).next().text().trim()}")`).get().join(',\n') // on http://kissmanga.com/AdvanceSearch override fun getFilterList(): List = listOf( + completedFilter, Filter("0", "Action"), Filter("1", "Adult"), Filter("2", "Adventure"), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt index 5baa43f22..dda9f62d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt @@ -50,10 +50,10 @@ class Mangafox(override val id: Int) : ParsedOnlineSource() { override fun searchMangaInitialUrl(query: String, filters: List) = "$baseUrl/search.php?name_method=cw&advopts=1&order=za&sort=views&name=$query&page=1&${filters.map { it.id + "=1" }.joinToString("&")}" - override fun searchMangaSelector() = "table#listing > tbody > tr:gt(0)" + override fun searchMangaSelector() = "div#mangalist > ul.list > li" override fun searchMangaFromElement(element: Element, manga: Manga) { - element.select("a.series_preview").first().let { + element.select("a.title").first().let { manga.setUrlWithoutDomain(it.attr("href")) manga.title = it.text() } @@ -132,6 +132,7 @@ class Mangafox(override val id: Int) : ParsedOnlineSource() { // $('select.genres').map((i,el)=>`Filter("${$(el).attr('name')}", "${$(el).next().text().trim()}")`).get().join(',\n') // on http://kissmanga.com/AdvanceSearch override fun getFilterList(): List = listOf( + Filter("is_completed", "Completed"), Filter("genres[Action]", "Action"), Filter("genres[Adult]", "Adult"), Filter("genres[Adventure]", "Adventure"), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt index 5dc81f585..a2d83e483 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt @@ -30,13 +30,17 @@ class Mangahere(override val id: Int) : ParsedOnlineSource() { override fun latestUpdatesSelector() = "div.directory_list > ul > li" - override fun popularMangaFromElement(element: Element, manga: Manga) { - element.select("div.title > a").first().let { + private fun mangaFromElement(query: String, element: Element, manga: Manga) { + element.select(query).first().let { manga.setUrlWithoutDomain(it.attr("href")) - manga.title = it.attr("title") + manga.title = if (it.hasAttr("title")) it.attr("title") else if (it.hasAttr("rel")) it.attr("rel") else it.text() } } + override fun popularMangaFromElement(element: Element, manga: Manga) { + mangaFromElement("div.title > a", element, manga) + } + override fun latestUpdatesFromElement(element: Element, manga: Manga) { popularMangaFromElement(element, manga) } @@ -50,10 +54,7 @@ class Mangahere(override val id: Int) : ParsedOnlineSource() { override fun searchMangaSelector() = "div.result_search > dl:has(dt)" override fun searchMangaFromElement(element: Element, manga: Manga) { - element.select("a.manga_info").first().let { - manga.setUrlWithoutDomain(it.attr("href")) - manga.title = it.attr("title") - } + mangaFromElement("a.manga_info", element, manga) } override fun searchMangaNextPageSelector() = "div.next-page > a.next" @@ -135,6 +136,7 @@ class Mangahere(override val id: Int) : ParsedOnlineSource() { // [...document.querySelectorAll("select[id^='genres'")].map((el,i) => `Filter("${el.getAttribute('name')}", "${el.nextSibling.nextSibling.textContent.trim()}")`).join(',\n') // http://www.mangahere.co/advsearch.htm override fun getFilterList(): List = listOf( + Filter("is_completed", "Completed"), Filter("genres[Action]", "Action"), Filter("genres[Adventure]", "Adventure"), Filter("genres[Comedy]", "Comedy"), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt index f744c374f..7d2eea2cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt @@ -66,8 +66,16 @@ class Mangasee(override val id: Int) : ParsedOnlineSource() { // Not used, overrides parent. override fun popularMangaNextPageSelector() = "" - override fun searchMangaInitialUrl(query: String, filters: List) = - "$baseUrl/search/request.php?sortBy=popularity&sortOrder=descending&keyword=$query&genre=${filters.map { it.id }.joinToString(",")}" + override fun searchMangaInitialUrl(query: String, filters: List): String { + var url = "$baseUrl/search/request.php?sortBy=popularity&sortOrder=descending&keyword=$query" + var genres: String? = null + for (filter in filters) { + if (filter.equals(completedFilter)) url += "&status=Complete" + else if (genres == null) genres = filter.id + else genres += "," + filter.id + } + return if (genres == null) url else url + "&genre=$genres" + } override fun searchMangaSelector() = "div.searchResults > div.requested > div.row" @@ -168,9 +176,11 @@ class Mangasee(override val id: Int) : ParsedOnlineSource() { override fun imageUrlParse(document: Document): String = document.select("img.CurImage").attr("src") + private val completedFilter = Filter("Complete", "Completed") // [...document.querySelectorAll("label.triStateCheckBox input")].map(el => `Filter("${el.getAttribute('name')}", "${el.nextSibling.textContent.trim()}")`).join(',\n') // http://mangasee.co/advanced-search/ override fun getFilterList(): List = listOf( + completedFilter, Filter("Action", "Action"), Filter("Adult", "Adult"), Filter("Adventure", "Adventure"), @@ -250,4 +260,4 @@ class Mangasee(override val id: Int) : ParsedOnlineSource() { } } -} +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt index 2d49fe564..6f74f3768 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt @@ -72,10 +72,12 @@ class Readmangatoday(override val id: Int) : ParsedOnlineSource() { val builder = okhttp3.FormBody.Builder() builder.add("manga-name", query) builder.add("type", "all") - builder.add("status", "both") + var status = "both" for (filter in filters) { - builder.add("include[]", filter.id) + if (filter.equals(completedFilter)) status = filter.id + else builder.add("include[]", filter.id) } + builder.add("status", status) return POST(page.url, headers, builder.build()) } @@ -154,9 +156,11 @@ class Readmangatoday(override val id: Int) : ParsedOnlineSource() { override fun imageUrlParse(document: Document) = document.select("img.img-responsive-2").first().attr("src") + private val completedFilter = Filter("completed", "Completed") // [...document.querySelectorAll("ul.manga-cat span")].map(el => `Filter("${el.getAttribute('data-id')}", "${el.nextSibling.textContent.trim()}")`).join(',\n') // http://www.readmanga.today/advanced-search override fun getFilterList(): List = listOf( + completedFilter, Filter("2", "Action"), Filter("4", "Adventure"), Filter("5", "Comedy"),