[RU]Desu cloudflareClient and title Language (#16634)

* [RU]Desu cloudflareClient

* TitleLanguage

* change split
This commit is contained in:
Eshlender 2023-06-06 14:22:04 +05:00 committed by GitHub
parent 38188d73d8
commit abd91a3156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 7 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Desu' extName = 'Desu'
pkgNameSuffix = 'ru.desu' pkgNameSuffix = 'ru.desu'
extClass = '.Desu' extClass = '.Desu'
extVersionCode = 21 extVersionCode = 22
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -1,7 +1,13 @@
package eu.kanade.tachiyomi.extension.ru.desu package eu.kanade.tachiyomi.extension.ru.desu
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.ListPreference
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter 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
@ -20,14 +26,20 @@ import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.long import kotlinx.serialization.json.long
import okhttp3.Headers import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import rx.Observable import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class Desu : HttpSource() { class Desu : ConfigurableSource, HttpSource() {
override val name = "Desu" override val name = "Desu"
override val id: Long = 6684416167758830305
override val baseUrl = "https://desu.me" override val baseUrl = "https://desu.me"
override val lang = "ru" override val lang = "ru"
@ -36,11 +48,20 @@ class Desu : HttpSource() {
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override fun headersBuilder() = Headers.Builder().apply { override fun headersBuilder() = Headers.Builder().apply {
add("User-Agent", "Tachiyomi") add("User-Agent", "Tachiyomi")
add("Referer", baseUrl) add("Referer", baseUrl)
} }
override val client: OkHttpClient =
network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 3)
.build()
private fun mangaPageFromJSON(jsonStr: String, next: Boolean): MangasPage { private fun mangaPageFromJSON(jsonStr: String, next: Boolean): MangasPage {
val mangaList = json.parseToJsonElement(jsonStr).jsonArray val mangaList = json.parseToJsonElement(jsonStr).jsonArray
.map { .map {
@ -56,9 +77,15 @@ class Desu : HttpSource() {
val id = obj["id"]!!.jsonPrimitive.int val id = obj["id"]!!.jsonPrimitive.int
url = "/$id" url = "/$id"
title = obj["name"]!!.jsonPrimitive.content title = if (isEng.equals("rus")) {
.split(" / ") obj["russian"]!!.jsonPrimitive.content
.first() .split(" / ")
.first()
} else {
obj["name"]!!.jsonPrimitive.content
.split(" / ")
.first()
}
thumbnail_url = obj["image"]!!.jsonObject["original"]!!.jsonPrimitive.content thumbnail_url = obj["image"]!!.jsonObject["original"]!!.jsonPrimitive.content
val ratingValue = obj["score"]!!.jsonPrimitive.floatOrNull ?: 0F val ratingValue = obj["score"]!!.jsonPrimitive.floatOrNull ?: 0F
@ -95,11 +122,19 @@ class Desu : HttpSource() {
if (obj["synonyms"]?.jsonPrimitive?.content.orEmpty().isNotEmpty() && obj["synonyms"]!!.jsonPrimitive.contentOrNull != null) { if (obj["synonyms"]?.jsonPrimitive?.content.orEmpty().isNotEmpty() && obj["synonyms"]!!.jsonPrimitive.contentOrNull != null) {
altName = "Альтернативные названия:\n" + altName = "Альтернативные названия:\n" +
obj["synonyms"]!!.jsonPrimitive.content obj["synonyms"]!!.jsonPrimitive.content
.replace("|", " / ") + .replace("/", " / ") +
"\n\n" "\n\n"
} }
description = obj["russian"]!!.jsonPrimitive.content + "\n" + description = if (isEng.equals("rus")) {
obj["name"]!!.jsonPrimitive.content
.split(" / ")
.first()
} else {
obj["russian"]!!.jsonPrimitive.content
.split(" / ")
.first()
} + "\n" +
ratingStar + " " + ratingValue + ratingStar + " " + ratingValue +
" (голосов: " + " (голосов: " +
obj["score_users"]!!.jsonPrimitive.int + obj["score_users"]!!.jsonPrimitive.int +
@ -343,9 +378,28 @@ class Desu : HttpSource() {
Genre("Яой", "Yaoi"), Genre("Яой", "Yaoi"),
) )
private var isEng: String? = preferences.getString(LANGUAGE_PREF, "eng")
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
val titleLanguagePref = ListPreference(screen.context).apply {
key = LANGUAGE_PREF
title = "Выбор языка на обложке"
entries = arrayOf("Английский", "Русский")
entryValues = arrayOf("eng", "rus")
summary = "%s"
setDefaultValue("eng")
setOnPreferenceChangeListener { _, newValue ->
val warning = "Если язык обложки не изменился очистите базу данных в приложении (Настройки -> Дополнительно -> Очистить базу данных)"
Toast.makeText(screen.context, warning, Toast.LENGTH_LONG).show()
true
}
}
screen.addPreference(titleLanguagePref)
}
companion object { companion object {
const val PREFIX_SLUG_SEARCH = "slug:" const val PREFIX_SLUG_SEARCH = "slug:"
private const val LANGUAGE_PREF = "DesuTitleLanguage"
private const val API_URL = "/manga/api" private const val API_URL = "/manga/api"
} }
} }