From 929f14632c552b8dceab425afe5b109608dd9149 Mon Sep 17 00:00:00 2001 From: Pavka Date: Wed, 11 Jul 2018 17:04:04 +0300 Subject: [PATCH] Update Desu Source. Add genres and improve paging (#383) * Update Desu Source. Add genres and improve paging * Update build.gradle * Update build.gradle --- src/ru/desu/build.gradle | 6 +- .../tachiyomi/extension/ru/desu/Desu.kt | 104 ++++++++++++++++-- 2 files changed, 100 insertions(+), 10 deletions(-) diff --git a/src/ru/desu/build.gradle b/src/ru/desu/build.gradle index d126eb9db..6bbcfe0b4 100644 --- a/src/ru/desu/build.gradle +++ b/src/ru/desu/build.gradle @@ -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" diff --git a/src/ru/desu/src/eu/kanade/tachiyomi/extension/ru/desu/Desu.kt b/src/ru/desu/src/eu/kanade/tachiyomi/extension/ru/desu/Desu.kt index b56b75fea..062efdf5e 100644 --- a/src/ru/desu/src/eu/kanade/tachiyomi/extension/ru/desu/Desu.kt +++ b/src/ru/desu/src/eu/kanade/tachiyomi/extension/ru/desu/Desu.kt @@ -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(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() + var genres = mutableListOf() + (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("Сортировка", + arrayOf("Популярность", "Дата", "Имя")) + + private class GenreList(genres: List) : Filter.Group("Жанр", genres) + private class TypeList(types: List) : Filter.Group("Тип", 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") ) }