Update Desu Source. Add genres and improve paging (#383)

* Update Desu Source. Add genres and improve paging

* Update build.gradle

* Update build.gradle
This commit is contained in:
Pavka 2018-07-11 17:04:04 +03:00 committed by Carlos
parent 91912fa009
commit 929f14632c
2 changed files with 100 additions and 10 deletions

View File

@ -5,9 +5,9 @@ ext {
appName = 'Tachiyomi: Desu'
pkgNameSuffix = "ru.desu"
extClass = '.Desu'
extVersionCode = 2
extVersionSuffix = 1
libVersion = '1.0'
extVersionCode = 3
extVersionSuffix = 2
libVersion = '1.2'
}
apply from: "$rootDir/common.gradle"

View File

@ -11,7 +11,6 @@ import org.json.JSONObject
import java.util.*
class Desu : HttpSource() {
override val name = "Desu"
override val baseUrl = "http://desu.me/manga/api"
@ -25,7 +24,7 @@ class Desu : HttpSource() {
add("Referer", baseUrl)
}
private fun mangaPageFromJSON(json: String): MangasPage {
private fun mangaPageFromJSON(json: String, next: Boolean): MangasPage {
val arr = JSONArray(json)
val ret = ArrayList<SManga>(arr.length())
for (i in 0 until arr.length()) {
@ -34,7 +33,7 @@ class Desu : HttpSource() {
mangaFromJSON(obj)
})
}
return MangasPage(ret, false)
return MangasPage(ret, next)
}
private fun SManga.mangaFromJSON(obj: JSONObject) {
@ -52,22 +51,46 @@ class Desu : HttpSource() {
}
override fun popularMangaRequest(page: Int) = GET("$baseUrl/?limit=50&order=popular&page=1")
override fun popularMangaRequest(page: Int) = GET("$baseUrl/?limit=50&order=popular&page=$page")
override fun popularMangaParse(response: Response) = searchMangaParse(response)
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/?limit=1&order=updated&page=1")
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/?limit=50&order=updated&page=$page")
override fun latestUpdatesParse(response: Response): MangasPage = searchMangaParse(response)
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
return GET("$baseUrl/?limit=1&order=popular&page=1&search=$query")
var url = "$baseUrl/?limit=20&page=$page"
var types = mutableListOf<Type>()
var genres = mutableListOf<Genre>()
(if (filters.isEmpty()) getFilterList() else filters).forEach { filter ->
when (filter) {
is OrderBy -> url += "&order=" + arrayOf("popular", "updated", "name")[filter.state]
is TypeList -> filter.state.forEach { type -> if (type.state) types.add(type) }
is GenreList -> filter.state.forEach {genre -> if (genre.state) genres.add(genre) }
}
}
if (!types.isEmpty()) {
url += "&kinds=" + types.joinToString(",") { it.id }
}
if (!genres.isEmpty()) {
url += "&genres=" + genres.joinToString(",") { it.id }
}
if (!query.isEmpty()) {
url += "&search=$query"
}
return GET(url)
}
override fun searchMangaParse(response: Response): MangasPage {
val res = response.body()!!.string()
val obj = JSONObject(res).getJSONArray("response")
return mangaPageFromJSON(obj.toString())
val nav = JSONObject(res).getJSONObject("pageNavParams")
val count = nav.getInt("count")
val limit = nav.getInt("limit")
val page = nav.getInt("page")
return mangaPageFromJSON(obj.toString(), count > page*limit)
}
override fun mangaDetailsParse(response: Response) = SManga.create().apply {
@ -109,6 +132,73 @@ class Desu : HttpSource() {
override fun imageUrlParse(response: Response)
= throw UnsupportedOperationException("This method should not be called!")
private class OrderBy : Filter.Select<String>("Сортировка",
arrayOf("Популярность", "Дата", "Имя"))
private class GenreList(genres: List<Genre>) : Filter.Group<Genre>("Жанр", genres)
private class TypeList(types: List<Type>) : Filter.Group<Type>("Тип", types)
private class Type(name: String, val id: String) : Filter.CheckBox(name)
private class Genre(name: String, val id: String) : Filter.CheckBox(name)
override fun getFilterList() = FilterList(
OrderBy(),
TypeList(getTypeList()),
GenreList(getGenreList())
)
private fun getTypeList() = listOf(
Type("Манга", "manga"),
Type("Манхва", "manhwa"),
Type("Маньхуа", "manhua"),
Type("Ваншот", "one_shot"),
Type("Комикс", "comics")
)
private fun getGenreList() = listOf(
Genre("Безумие", "Dementia"),
Genre("Боевые искусства", "Martial Arts"),
Genre("Вампиры", "Vampire"),
Genre("Военное", "Military"),
Genre("Гарем", "Harem"),
Genre("Демоны", "Demons"),
Genre("Детектив", "Mystery"),
Genre("Детское", "Kids"),
Genre("Дзёсей", "Josei"),
Genre("Додзинси", "Doujinshi"),
Genre("Драма", "Drama"),
Genre("Игры", "Game"),
Genre("Исторический", "Historical"),
Genre("Комедия", "Comedy"),
Genre("Космос", "Space"),
Genre("Магия", "Magic"),
Genre("Машины", "Cars"),
Genre("Меха", "Mecha"),
Genre("Музыка", "Music"),
Genre("Пародия", "Parody"),
Genre("Повседневность", "Slice of Life"),
Genre("Полиция", "Police"),
Genre("Приключения", "Adventure"),
Genre("Психологическое", "Psychological"),
Genre("Романтика", "Romance"),
Genre("Самураи", "Samurai"),
Genre("Сверхъестественное", "Supernatural"),
Genre("Сёдзе", "Shoujo"),
Genre("Сёдзе Ай", "Shoujo Ai"),
Genre("Сейнен", "Seinen"),
Genre("Сёнен", "Shounen"),
Genre("Сёнен Ай", "Shounen Ai"),
Genre("Смена пола", "Gender Bender"),
Genre("Спорт", "Sports"),
Genre("Супер сила", "Super Power"),
Genre("Триллер", "Thriller"),
Genre("Ужасы", "Horror"),
Genre("Фантастика", "Sci-Fi"),
Genre("Фэнтези", "Fantasy"),
Genre("Хентай", "Hentai"),
Genre("Школа", "School"),
Genre("Экшен", "Action"),
Genre("Этти", "Ecchi"),
Genre("Юри", "Yuri"),
Genre("Яой", "Yaoi")
)
}