ReadManhwa - add filters (#3032)
* ReadManhwa - add filters * Use HttpUrl
This commit is contained in:
parent
c08bbfb10b
commit
df8e210c5c
|
@ -5,7 +5,7 @@ ext {
|
|||
appName = 'Tachiyomi: ReadManhwa'
|
||||
pkgNameSuffix = 'en.readmanhwa'
|
||||
extClass = '.ReadManhwa'
|
||||
extVersionCode = 1
|
||||
extVersionCode = 2
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.google.gson.JsonArray
|
|||
import com.google.gson.JsonObject
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
|
@ -18,6 +19,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
|
@ -70,14 +72,35 @@ class ReadManhwa : HttpSource() {
|
|||
// Search
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
return GET("$baseUrl/api/comics?page=$page&q=$query&sort=uploaded_at&order=desc&duration=day", headers)
|
||||
val url = HttpUrl.parse("$baseUrl/api/comics")!!.newBuilder()
|
||||
.addQueryParameter("per_page", "18")
|
||||
.addQueryParameter("page", page.toString())
|
||||
.addQueryParameter("order", "desc")
|
||||
.addQueryParameter("q", query)
|
||||
|
||||
filters.forEach { filter ->
|
||||
when (filter) {
|
||||
is SortFilter -> url.addQueryParameter("sort", filter.toUriPart())
|
||||
is GenreFilter -> url.addQueryParameter("tags", filter.toUriPart())
|
||||
is DurationFilter -> url.addQueryParameter("duration", filter.toUriPart())
|
||||
}
|
||||
}
|
||||
return GET(url.toString(), headers)
|
||||
}
|
||||
|
||||
override fun searchMangaParse(response: Response): MangasPage = parseMangaFromJson(response)
|
||||
|
||||
// Details
|
||||
|
||||
override fun mangaDetailsRequest(manga: SManga): Request {
|
||||
// Workaround to allow "Open in browser" to use the real URL
|
||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> =
|
||||
client.newCall(apiMangaDetailsRequest(manga)).asObservableSuccess()
|
||||
.map { mangaDetailsParse(it).apply { initialized = true } }
|
||||
|
||||
// Return the real URL for "Open in browser"
|
||||
override fun mangaDetailsRequest(manga: SManga) = GET("$baseUrl/en/webtoon/${manga.url}", headers)
|
||||
|
||||
private fun apiMangaDetailsRequest(manga: SManga): Request {
|
||||
return GET("$baseUrl/api/comics/${manga.url}", headers)
|
||||
}
|
||||
|
||||
|
@ -154,4 +177,93 @@ class ReadManhwa : HttpSource() {
|
|||
}
|
||||
|
||||
override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException("Not used")
|
||||
|
||||
// Filters
|
||||
|
||||
override fun getFilterList() = FilterList(
|
||||
GenreFilter(getGenreList()),
|
||||
DurationFilter(getDurationList()),
|
||||
SortFilter(getSortList())
|
||||
)
|
||||
|
||||
private class GenreFilter(pairs: Array<Pair<String, String>>) : UriPartFilter("Genre", pairs)
|
||||
|
||||
private class DurationFilter(pairs: Array<Pair<String, String>>) : UriPartFilter("Duration", pairs)
|
||||
|
||||
private class SortFilter(pairs: Array<Pair<String, String>>) : UriPartFilter("Sorted by", pairs)
|
||||
|
||||
open class UriPartFilter(displayName: String, private val vals: Array<Pair<String, String>>) :
|
||||
Filter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
|
||||
fun toUriPart() = vals[state].second
|
||||
}
|
||||
|
||||
private fun getGenreList() = arrayOf(
|
||||
Pair("All", "0"),
|
||||
Pair("Action", "14"),
|
||||
Pair("Adult", "27"),
|
||||
Pair("Adventure", "6"),
|
||||
Pair("Angst", "50"),
|
||||
Pair("BL", "20"),
|
||||
Pair("Comedy", "1"),
|
||||
Pair("Completed", "53"),
|
||||
Pair("Crime", "18"),
|
||||
Pair("Cultivation", "37"),
|
||||
Pair("Drama", "2"),
|
||||
Pair("Ecchi", "46"),
|
||||
Pair("Fantasy", "8"),
|
||||
Pair("GL", "42"),
|
||||
Pair("Gender Bender", "35"),
|
||||
Pair("Gossip", "12"),
|
||||
Pair("Harem", "7"),
|
||||
Pair("Historical", "33"),
|
||||
Pair("Horror", "19"),
|
||||
Pair("Incest", "10"),
|
||||
Pair("Isekai", "28"),
|
||||
Pair("Josei", "48"),
|
||||
Pair("M", "43"),
|
||||
Pair("Manhua", "38"),
|
||||
Pair("Manhwa", "40"),
|
||||
Pair("Martial arts", "26"),
|
||||
Pair("Mature", "30"),
|
||||
Pair("Medical", "24"),
|
||||
Pair("Modern", "51"),
|
||||
Pair("Mystery", "15"),
|
||||
Pair("NTR", "32"),
|
||||
Pair("Philosophical", "44"),
|
||||
Pair("Post Apocalyptic", "49"),
|
||||
Pair("Psychological", "16"),
|
||||
Pair("Romance", "3"),
|
||||
Pair("Rpg", "41"),
|
||||
Pair("School LIfe", "11"),
|
||||
Pair("Sci Fi", "9"),
|
||||
Pair("Seinen", "31"),
|
||||
Pair("Shoujo", "36"),
|
||||
Pair("Shounen", "29"),
|
||||
Pair("Slice of Life", "4"),
|
||||
Pair("Smut", "13"),
|
||||
Pair("Sports", "5"),
|
||||
Pair("Superhero", "45"),
|
||||
Pair("Supernatural", "22"),
|
||||
Pair("Suspense", "47"),
|
||||
Pair("Thriller", "17"),
|
||||
Pair("TimeTravel", "52"),
|
||||
Pair("Tragedy", "23"),
|
||||
Pair("Vanilla", "34"),
|
||||
Pair("Webtoon", "39"),
|
||||
Pair("Yaoi", "21"),
|
||||
Pair("Yuri", "25")
|
||||
)
|
||||
|
||||
private fun getDurationList() = arrayOf(
|
||||
Pair("All time", "all"),
|
||||
Pair("Year", "year"),
|
||||
Pair("Month", "month"),
|
||||
Pair("Week", "week"),
|
||||
Pair("Day", "day")
|
||||
)
|
||||
|
||||
private fun getSortList() = arrayOf(
|
||||
Pair("Popularity", "popularity"),
|
||||
Pair("Date", "uploaded_at")
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue