Manga18fx: add support for genre filter (#13240)
* Manga18fx: add support for genre filter * add comment about the site * apply review suggestion * improve control flow * fix compile error
This commit is contained in:
parent
756e27d4a8
commit
edb2590359
|
@ -2,17 +2,22 @@ package eu.kanade.tachiyomi.extension.en.manga18fx
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import org.jsoup.select.Evaluator
|
import org.jsoup.select.Evaluator
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
// The site isn't actually based on Madara but reproduces it very well
|
||||||
class Manga18fx : Madara(
|
class Manga18fx : Madara(
|
||||||
"Manga18fx",
|
"Manga18fx",
|
||||||
"https://manga18fx.com",
|
"https://manga18fx.com",
|
||||||
|
@ -30,6 +35,7 @@ class Manga18fx : Madara(
|
||||||
|
|
||||||
override fun popularMangaParse(response: Response): MangasPage {
|
override fun popularMangaParse(response: Response): MangasPage {
|
||||||
val document = response.asJsoup()
|
val document = response.asJsoup()
|
||||||
|
loadGenres(document)
|
||||||
val block = document.selectFirst(Evaluator.Class("trending-block"))
|
val block = document.selectFirst(Evaluator.Class("trending-block"))
|
||||||
val mangas = block.select(Evaluator.Tag("a")).map(::mangaFromElement)
|
val mangas = block.select(Evaluator.Tag("a")).map(::mangaFromElement)
|
||||||
return MangasPage(mangas, false)
|
return MangasPage(mangas, false)
|
||||||
|
@ -45,6 +51,7 @@ class Manga18fx : Madara(
|
||||||
|
|
||||||
override fun latestUpdatesParse(response: Response): MangasPage {
|
override fun latestUpdatesParse(response: Response): MangasPage {
|
||||||
val document = response.asJsoup()
|
val document = response.asJsoup()
|
||||||
|
loadGenres(document)
|
||||||
val mangas = document.select(Evaluator.Class("bsx-item")).map {
|
val mangas = document.select(Evaluator.Class("bsx-item")).map {
|
||||||
mangaFromElement(it.selectFirst(Evaluator.Tag("a")))
|
mangaFromElement(it.selectFirst(Evaluator.Tag("a")))
|
||||||
}
|
}
|
||||||
|
@ -53,8 +60,21 @@ class Manga18fx : Madara(
|
||||||
return MangasPage(mangas, hasNextPage)
|
return MangasPage(mangas, hasNextPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList) =
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
GET("$baseUrl/search?q=$query&page=$page", headers)
|
if (query.isEmpty()) {
|
||||||
|
filters.forEach { filter ->
|
||||||
|
if (filter is GenreFilter)
|
||||||
|
return GET(filter.vals[filter.state].second, headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val url = "$baseUrl/search".toHttpUrl().newBuilder()
|
||||||
|
.addQueryParameter("q", query)
|
||||||
|
.addQueryParameter("page", page.toString())
|
||||||
|
.toString()
|
||||||
|
|
||||||
|
return GET(url, headers)
|
||||||
|
}
|
||||||
|
|
||||||
override fun searchMangaParse(response: Response) = latestUpdatesParse(response)
|
override fun searchMangaParse(response: Response) = latestUpdatesParse(response)
|
||||||
|
|
||||||
|
@ -68,5 +88,43 @@ class Manga18fx : Madara(
|
||||||
|
|
||||||
override fun chapterDateSelector() = "span.chapter-time"
|
override fun chapterDateSelector() = "span.chapter-time"
|
||||||
|
|
||||||
override fun getFilterList() = FilterList(emptyList())
|
class GenreFilter(val vals: List<Pair<String, String>>) :
|
||||||
|
Filter.Select<String>("Genre", vals.map { it.first }.toTypedArray())
|
||||||
|
|
||||||
|
private fun loadGenres(document: Document) {
|
||||||
|
genresList = document.select(".header-bottom li a").map {
|
||||||
|
val href = it.attr("href")
|
||||||
|
val url = if (href.startsWith("http")) href else "$baseUrl/$href"
|
||||||
|
|
||||||
|
Pair(it.text(), url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var genresList: List<Pair<String, String>> = emptyList()
|
||||||
|
private var hardCodedTypes: List<Pair<String, String>> = listOf(
|
||||||
|
Pair("Manhwa", "$baseUrl/manga-genre/manhwa"),
|
||||||
|
Pair("Manhua", "$baseUrl/manga-genre/manhua"),
|
||||||
|
Pair("Raw", "$baseUrl/manga-genre/raw"),
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun getFilterList(): FilterList {
|
||||||
|
|
||||||
|
val filters = mutableListOf<Filter<*>>(
|
||||||
|
Filter.Header("Filters are ignored for text search!"),
|
||||||
|
)
|
||||||
|
|
||||||
|
filters.apply {
|
||||||
|
if (genresList.isNotEmpty()) {
|
||||||
|
add(
|
||||||
|
GenreFilter(hardCodedTypes + genresList)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
add(
|
||||||
|
Filter.Header("Wait for mangas to load then tap Reset")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FilterList(filters)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ class MadaraGenerator : ThemeSourceGenerator {
|
||||||
SingleLang("Manga-Online.co", "https://www.manga-online.co", "th", className = "MangaOnlineCo"),
|
SingleLang("Manga-Online.co", "https://www.manga-online.co", "th", className = "MangaOnlineCo"),
|
||||||
SingleLang("Manga-Scantrad", "https://manga-scantrad.net", "fr", className = "MangaScantrad", overrideVersionCode = 2),
|
SingleLang("Manga-Scantrad", "https://manga-scantrad.net", "fr", className = "MangaScantrad", overrideVersionCode = 2),
|
||||||
SingleLang("Manga-TX", "https://manga-tx.com", "en", className = "Mangatxunoriginal"),
|
SingleLang("Manga-TX", "https://manga-tx.com", "en", className = "Mangatxunoriginal"),
|
||||||
SingleLang("Manga18fx", "https://manga18fx.com", "en", isNsfw = true, overrideVersionCode = 2),
|
SingleLang("Manga18fx", "https://manga18fx.com", "en", isNsfw = true, overrideVersionCode = 3),
|
||||||
SingleLang("Manga1st", "https://manga1st.com", "en", overrideVersionCode = 2),
|
SingleLang("Manga1st", "https://manga1st.com", "en", overrideVersionCode = 2),
|
||||||
SingleLang("Manga1st.online", "https://manga1st.online", "en", className = "MangaFirstOnline", overrideVersionCode = 1),
|
SingleLang("Manga1st.online", "https://manga1st.online", "en", className = "MangaFirstOnline", overrideVersionCode = 1),
|
||||||
SingleLang("Manga347", "https://manga347.com", "en", overrideVersionCode = 3),
|
SingleLang("Manga347", "https://manga347.com", "en", overrideVersionCode = 3),
|
||||||
|
@ -356,9 +356,9 @@ class MadaraGenerator : ThemeSourceGenerator {
|
||||||
SingleLang("MR Yaoi Fansub", "https://mrtenzus.com", "pt-BR", isNsfw = true, className = "MrYaoiFansub"),
|
SingleLang("MR Yaoi Fansub", "https://mrtenzus.com", "pt-BR", isNsfw = true, className = "MrYaoiFansub"),
|
||||||
SingleLang("Muctau", "https://muctau.com", "en", overrideVersionCode = 1),
|
SingleLang("Muctau", "https://muctau.com", "en", overrideVersionCode = 1),
|
||||||
SingleLang("MurimScan", "https://murimscan.run", "en", isNsfw = true),
|
SingleLang("MurimScan", "https://murimscan.run", "en", isNsfw = true),
|
||||||
|
SingleLang("My Universe Scanlator", "https://muscan.com.br", "pt-BR"),
|
||||||
SingleLang("MyKomiks", "https://mykomiks.fun", "en", overrideVersionCode = 2),
|
SingleLang("MyKomiks", "https://mykomiks.fun", "en", overrideVersionCode = 2),
|
||||||
SingleLang("Mystical Merries", "https://mysticalmerries.com", "en", overrideVersionCode = 2),
|
SingleLang("Mystical Merries", "https://mysticalmerries.com", "en", overrideVersionCode = 2),
|
||||||
SingleLang("My Universe Scanlator", "https://muscan.com.br", "pt-BR"),
|
|
||||||
SingleLang("NeatManga", "https://neatmanga.com", "en", overrideVersionCode = 2),
|
SingleLang("NeatManga", "https://neatmanga.com", "en", overrideVersionCode = 2),
|
||||||
SingleLang("NekoBreaker Scan", "https://nekobreakerscan.com", "pt-BR", overrideVersionCode = 1),
|
SingleLang("NekoBreaker Scan", "https://nekobreakerscan.com", "pt-BR", overrideVersionCode = 1),
|
||||||
SingleLang("NekoScan", "https://nekoscan.com", "en", overrideVersionCode = 2),
|
SingleLang("NekoScan", "https://nekoscan.com", "en", overrideVersionCode = 2),
|
||||||
|
|
Loading…
Reference in New Issue