[RU] Mangalib image servers autoswitch and more filters (#6562)

* Autoswitch test

* Autoswitch test v2

* [Ru-MangaLib]Autosuggest of server

* Fix 18+ alert

* Add Filters and Fix Content-Length Size

* Back "pages.add"

* Fix indexOf hided server

Co-authored-by: pavkazzz <me@pavkazzz.ru>
This commit is contained in:
Eugene 2021-04-15 18:35:27 +05:00 committed by GitHub
parent 03937cb8a1
commit f6aa779214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 11 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'MangaLib' extName = 'MangaLib'
pkgNameSuffix = 'ru.libmanga' pkgNameSuffix = 'ru.libmanga'
extClass = '.LibManga' extClass = '.LibManga'
extVersionCode = 36 extVersionCode = 37
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -11,6 +11,7 @@ import com.github.salomonbrys.kotson.nullArray
import com.github.salomonbrys.kotson.nullString import com.github.salomonbrys.kotson.nullString
import com.github.salomonbrys.kotson.obj import com.github.salomonbrys.kotson.obj
import com.github.salomonbrys.kotson.string import com.github.salomonbrys.kotson.string
import com.github.salomonbrys.kotson.toMap
import com.google.gson.JsonElement import com.google.gson.JsonElement
import com.google.gson.JsonParser import com.google.gson.JsonParser
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
@ -298,12 +299,16 @@ class LibManga : ConfigurableSource, HttpSource() {
.first() .first()
val chapInfoJson = jsonParser.parse(chapInfo).obj val chapInfoJson = jsonParser.parse(chapInfo).obj
val servers = chapInfoJson["servers"].asJsonObject val servers = chapInfoJson["servers"].asJsonObject.toMap()
val defaultServer: String = chapInfoJson["img"]["server"].string val defaultServer: String = chapInfoJson["img"]["server"].string
val autoServer = setOf(defaultServer, "secondary", "fourth", "compress")
val imgUrl: String = chapInfoJson["img"]["url"].string val imgUrl: String = chapInfoJson["img"]["url"].string
val serverToUse = if (this.server == null) defaultServer else this.server val serverToUse = when (this.server) {
val imageServerUrl: String = servers[serverToUse].string null -> autoServer
"auto" -> autoServer
else -> listOf(this.server)
}
// Get pages // Get pages
val pagesArr = document val pagesArr = document
@ -318,11 +323,34 @@ class LibManga : ConfigurableSource, HttpSource() {
val pages = mutableListOf<Page>() val pages = mutableListOf<Page>()
pagesJson.forEach { page -> pagesJson.forEach { page ->
pages.add(Page(page["p"].int, "", imageServerUrl + "/" + imgUrl + page["u"].string)) val keys = servers.keys.filter { serverToUse.indexOf(it) >= 0 }.sortedBy { serverToUse.indexOf(it) }
val serversUrls = keys.map {
servers[it]?.string + imgUrl + page["u"].string
}.joinToString(separator = ",,") { it }
pages.add(Page(page["p"].int, serversUrls))
} }
return pages return pages
} }
private fun checkImage(url: String): Boolean {
val response = client.newCall(Request.Builder().url(url).head().headers(headers).build()).execute()
return response.isSuccessful && (response.header("Content-Length")?.toInt()!! > 320)
}
override fun fetchImageUrl(page: Page): Observable<String> {
if (page.imageUrl != null) {
return Observable.just(page.imageUrl)
}
val urls = page.url.split(",,")
if (urls.size == 1) {
return Observable.just(urls[0])
}
return Observable.from(urls).filter { checkImage(it) }.first()
}
override fun imageUrlParse(response: Response): String = "" override fun imageUrlParse(response: Response): String = ""
private fun searchMangaByIdRequest(id: String): Request { private fun searchMangaByIdRequest(id: String): Request {
@ -365,11 +393,21 @@ class LibManga : ConfigurableSource, HttpSource() {
url.addQueryParameter("types[]", category.id) url.addQueryParameter("types[]", category.id)
} }
} }
is FormatList -> filter.state.forEach { forma ->
if (forma.state != Filter.TriState.STATE_IGNORE) {
url.addQueryParameter(if (forma.isIncluded()) "format[include][]" else "format[exclude][]", forma.id)
}
}
is StatusList -> filter.state.forEach { status -> is StatusList -> filter.state.forEach { status ->
if (status.state) { if (status.state) {
url.addQueryParameter("status[]", status.id) url.addQueryParameter("status[]", status.id)
} }
} }
is StatusTitleList -> filter.state.forEach { title ->
if (title.state) {
url.addQueryParameter("manga_status[]", title.id)
}
}
is GenreList -> filter.state.forEach { genre -> is GenreList -> filter.state.forEach { genre ->
if (genre.state != Filter.TriState.STATE_IGNORE) { if (genre.state != Filter.TriState.STATE_IGNORE) {
url.addQueryParameter(if (genre.isIncluded()) "genres[include][]" else "genres[exclude][]", genre.id) url.addQueryParameter(if (genre.isIncluded()) "genres[include][]" else "genres[exclude][]", genre.id)
@ -433,7 +471,9 @@ class LibManga : ConfigurableSource, HttpSource() {
private class CheckFilter(name: String, val id: String) : Filter.CheckBox(name) private class CheckFilter(name: String, val id: String) : Filter.CheckBox(name)
private class CategoryList(categories: List<CheckFilter>) : Filter.Group<CheckFilter>("Тип", categories) private class CategoryList(categories: List<CheckFilter>) : Filter.Group<CheckFilter>("Тип", categories)
private class FormatList(formas: List<SearchFilter>) : Filter.Group<SearchFilter>("Формат выпуска", formas)
private class StatusList(statuses: List<CheckFilter>) : Filter.Group<CheckFilter>("Статус перевода", statuses) private class StatusList(statuses: List<CheckFilter>) : Filter.Group<CheckFilter>("Статус перевода", statuses)
private class StatusTitleList(titles: List<CheckFilter>) : Filter.Group<CheckFilter>("Статус тайтла", titles)
private class GenreList(genres: List<SearchFilter>) : Filter.Group<SearchFilter>("Жанры", genres) private class GenreList(genres: List<SearchFilter>) : Filter.Group<SearchFilter>("Жанры", genres)
private class TagList(tags: List<SearchFilter>) : Filter.Group<SearchFilter>("Теги", tags) private class TagList(tags: List<SearchFilter>) : Filter.Group<SearchFilter>("Теги", tags)
private class AgeList(ages: List<CheckFilter>) : Filter.Group<CheckFilter>("Возрастное ограничение", ages) private class AgeList(ages: List<CheckFilter>) : Filter.Group<CheckFilter>("Возрастное ограничение", ages)
@ -441,9 +481,11 @@ class LibManga : ConfigurableSource, HttpSource() {
override fun getFilterList() = FilterList( override fun getFilterList() = FilterList(
OrderBy(), OrderBy(),
CategoryList(getCategoryList()), CategoryList(getCategoryList()),
FormatList(getFormatList()),
GenreList(getGenreList()), GenreList(getGenreList()),
TagList(getTagList()), TagList(getTagList()),
StatusList(getStatusList()), StatusList(getStatusList()),
StatusTitleList(getStatusTitleList()),
AgeList(getAgeList()) AgeList(getAgeList())
) )
@ -467,6 +509,15 @@ class LibManga : ConfigurableSource, HttpSource() {
CheckFilter("Комикс западный", "9") CheckFilter("Комикс западный", "9")
) )
private fun getFormatList() = listOf(
SearchFilter("4-кома (Ёнкома)", "1"),
SearchFilter("Сборник", "2"),
SearchFilter("Додзинси", "3"),
SearchFilter("Сингл", "4"),
SearchFilter("В цвете", "5"),
SearchFilter("Веб", "6")
)
/* /*
* Use console * Use console
* Object.entries(__FILTER_ITEMS__.status).map(([k, v]) => `SearchFilter("${v.label}", "${v.id}")`).join(',\n') * Object.entries(__FILTER_ITEMS__.status).map(([k, v]) => `SearchFilter("${v.label}", "${v.id}")`).join(',\n')
@ -479,6 +530,14 @@ class LibManga : ConfigurableSource, HttpSource() {
CheckFilter("Заброшен", "4") CheckFilter("Заброшен", "4")
) )
private fun getStatusTitleList() = listOf(
CheckFilter("Онгоинг", "1"),
CheckFilter("Завершён", "2"),
CheckFilter("Анонс", "3"),
CheckFilter("Приостановлен", "4"),
CheckFilter("Выпуск прекращён", "5"),
)
/* /*
* Use console * Use console
* __FILTER_ITEMS__.genres.map(it => `SearchFilter("${it.name}", "${it.id}")`).join(',\n') * __FILTER_ITEMS__.genres.map(it => `SearchFilter("${it.name}", "${it.id}")`).join(',\n')
@ -489,13 +548,11 @@ class LibManga : ConfigurableSource, HttpSource() {
SearchFilter("боевик", "34"), SearchFilter("боевик", "34"),
SearchFilter("боевые искусства", "35"), SearchFilter("боевые искусства", "35"),
SearchFilter("вампиры", "36"), SearchFilter("вампиры", "36"),
SearchFilter("веб", "78"),
SearchFilter("гарем", "37"), SearchFilter("гарем", "37"),
SearchFilter("гендерная интрига", "38"), SearchFilter("гендерная интрига", "38"),
SearchFilter("героическое фэнтези", "39"), SearchFilter("героическое фэнтези", "39"),
SearchFilter("детектив", "40"), SearchFilter("детектив", "40"),
SearchFilter("дзёсэй", "41"), SearchFilter("дзёсэй", "41"),
SearchFilter("додзинси", "42"),
SearchFilter("драма", "43"), SearchFilter("драма", "43"),
SearchFilter("ёнкома", "75"), SearchFilter("ёнкома", "75"),
SearchFilter("игра", "44"), SearchFilter("игра", "44"),
@ -533,6 +590,7 @@ class LibManga : ConfigurableSource, HttpSource() {
SearchFilter("юри", "73"), SearchFilter("юри", "73"),
SearchFilter("яой", "74") SearchFilter("яой", "74")
) )
private fun getTagList() = listOf( private fun getTagList() = listOf(
SearchFilter("Азартные игры", "304"), SearchFilter("Азартные игры", "304"),
SearchFilter("Алхимия", "225"), SearchFilter("Алхимия", "225"),
@ -639,6 +697,7 @@ class LibManga : ConfigurableSource, HttpSource() {
CheckFilter("16+", "1"), CheckFilter("16+", "1"),
CheckFilter("18+", "2") CheckFilter("18+", "2")
) )
companion object { companion object {
const val PREFIX_SLUG_SEARCH = "slug:" const val PREFIX_SLUG_SEARCH = "slug:"
private const val SERVER_PREF = "MangaLibImageServer" private const val SERVER_PREF = "MangaLibImageServer"
@ -654,8 +713,8 @@ class LibManga : ConfigurableSource, HttpSource() {
val serverPref = ListPreference(screen.context).apply { val serverPref = ListPreference(screen.context).apply {
key = SERVER_PREF key = SERVER_PREF
title = SERVER_PREF_Title title = SERVER_PREF_Title
entries = arrayOf("Основной", "Второй (тестовый)", "Третий (эконом трафика)") entries = arrayOf("Основной", "Второй (тестовый)", "Третий (эконом трафика)", "Авто")
entryValues = arrayOf("secondary", "fourth", "compress") entryValues = arrayOf("secondary", "fourth", "compress", "auto")
summary = "%s" summary = "%s"
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -688,8 +747,8 @@ class LibManga : ConfigurableSource, HttpSource() {
val serverPref = LegacyListPreference(screen.context).apply { val serverPref = LegacyListPreference(screen.context).apply {
key = SERVER_PREF key = SERVER_PREF
title = SERVER_PREF_Title title = SERVER_PREF_Title
entries = arrayOf("Основной", "Второй (тестовый)", "Третий (эконом трафика)") entries = arrayOf("Основной", "Второй (тестовый)", "Третий (эконом трафика)", "Авто")
entryValues = arrayOf("secondary", "fourth", "compress") entryValues = arrayOf("secondary", "fourth", "compress", "auto")
summary = "%s" summary = "%s"
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->