Bato: update domain mirrors (#6748)

* batoto: update domain mirrors

* cleanup prefs

* tfw
This commit is contained in:
AwkwardPeak7 2024-12-22 20:19:20 +05:00 committed by Draff
parent caf440aaa2
commit af92d1591d
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 34 additions and 23 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Bato.to' extName = 'Bato.to'
extClass = '.BatoToFactory' extClass = '.BatoToFactory'
extVersionCode = 43 extVersionCode = 44
isNsfw = true isNsfw = true
} }

View File

@ -27,7 +27,6 @@ import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import org.jsoup.Jsoup import org.jsoup.Jsoup
@ -42,7 +41,6 @@ import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit
open class BatoTo( open class BatoTo(
final override val lang: String, final override val lang: String,
@ -51,10 +49,11 @@ open class BatoTo(
private val preferences: SharedPreferences by lazy { private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000) Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
.migrateMirrorPref()
} }
override val name: String = "Bato.to" override val name: String = "Bato.to"
override val baseUrl: String by lazy { getMirrorPref()!! } override val baseUrl: String get() = mirror
override val id: Long = when (lang) { override val id: Long = when (lang) {
"zh-Hans" -> 2818874445640189582 "zh-Hans" -> 2818874445640189582
"zh-Hant" -> 38886079663327225 "zh-Hant" -> 38886079663327225
@ -70,12 +69,9 @@ open class BatoTo(
entryValues = MIRROR_PREF_ENTRY_VALUES entryValues = MIRROR_PREF_ENTRY_VALUES
setDefaultValue(MIRROR_PREF_DEFAULT_VALUE) setDefaultValue(MIRROR_PREF_DEFAULT_VALUE)
summary = "%s" summary = "%s"
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String mirror = newValue as String
val index = findIndexOfValue(selected) true
val entry = entryValues[index] as String
preferences.edit().putString("${MIRROR_PREF_KEY}_$lang", entry).commit()
} }
} }
val altChapterListPref = CheckBoxPreference(screen.context).apply { val altChapterListPref = CheckBoxPreference(screen.context).apply {
@ -83,11 +79,6 @@ open class BatoTo(
title = ALT_CHAPTER_LIST_PREF_TITLE title = ALT_CHAPTER_LIST_PREF_TITLE
summary = ALT_CHAPTER_LIST_PREF_SUMMARY summary = ALT_CHAPTER_LIST_PREF_SUMMARY
setDefaultValue(ALT_CHAPTER_LIST_PREF_DEFAULT_VALUE) setDefaultValue(ALT_CHAPTER_LIST_PREF_DEFAULT_VALUE)
setOnPreferenceChangeListener { _, newValue ->
val checkValue = newValue as Boolean
preferences.edit().putBoolean("${ALT_CHAPTER_LIST_PREF_KEY}_$lang", checkValue).commit()
}
} }
val removeOfficialPref = CheckBoxPreference(screen.context).apply { val removeOfficialPref = CheckBoxPreference(screen.context).apply {
key = "${REMOVE_TITLE_VERSION_PREF}_$lang" key = "${REMOVE_TITLE_VERSION_PREF}_$lang"
@ -103,18 +94,35 @@ open class BatoTo(
screen.addPreference(removeOfficialPref) screen.addPreference(removeOfficialPref)
} }
private var mirror = ""
get() {
val current = field
if (current.isNotEmpty()) {
return current
}
field = getMirrorPref()!!
return field
}
private fun getMirrorPref(): String? = preferences.getString("${MIRROR_PREF_KEY}_$lang", MIRROR_PREF_DEFAULT_VALUE) private fun getMirrorPref(): String? = preferences.getString("${MIRROR_PREF_KEY}_$lang", MIRROR_PREF_DEFAULT_VALUE)
private fun getAltChapterListPref(): Boolean = preferences.getBoolean("${ALT_CHAPTER_LIST_PREF_KEY}_$lang", ALT_CHAPTER_LIST_PREF_DEFAULT_VALUE) private fun getAltChapterListPref(): Boolean = preferences.getBoolean("${ALT_CHAPTER_LIST_PREF_KEY}_$lang", ALT_CHAPTER_LIST_PREF_DEFAULT_VALUE)
private fun isRemoveTitleVersion(): Boolean { private fun isRemoveTitleVersion(): Boolean {
return preferences.getBoolean("${REMOVE_TITLE_VERSION_PREF}_$lang", false) return preferences.getBoolean("${REMOVE_TITLE_VERSION_PREF}_$lang", false)
} }
private fun SharedPreferences.migrateMirrorPref(): SharedPreferences {
val selectedMirror = getString("${MIRROR_PREF_KEY}_$lang", MIRROR_PREF_DEFAULT_VALUE)!!
if (selectedMirror in DEPRECATED_MIRRORS) {
edit().putString("${MIRROR_PREF_KEY}_$lang", MIRROR_PREF_DEFAULT_VALUE).commit()
}
return this
}
override val supportsLatest = true override val supportsLatest = true
private val json: Json by injectLazy() private val json: Json by injectLazy()
override val client: OkHttpClient = network.cloudflareClient.newBuilder() override val client = network.cloudflareClient
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build()
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
return GET("$baseUrl/browse?langs=$siteLang&sort=update&page=$page", headers) return GET("$baseUrl/browse?langs=$siteLang&sort=update&page=$page", headers)
@ -983,7 +991,7 @@ open class BatoTo(
private const val MIRROR_PREF_TITLE = "Mirror" private const val MIRROR_PREF_TITLE = "Mirror"
private const val REMOVE_TITLE_VERSION_PREF = "REMOVE_TITLE_VERSION" private const val REMOVE_TITLE_VERSION_PREF = "REMOVE_TITLE_VERSION"
private val MIRROR_PREF_ENTRIES = arrayOf( private val MIRROR_PREF_ENTRIES = arrayOf(
"bato.to", "zbato.org",
"batocomic.com", "batocomic.com",
"batocomic.net", "batocomic.net",
"batocomic.org", "batocomic.org",
@ -992,9 +1000,6 @@ open class BatoTo(
"battwo.com", "battwo.com",
"comiko.net", "comiko.net",
"comiko.org", "comiko.org",
"mangatoto.com",
"mangatoto.net",
"mangatoto.org",
"readtoto.com", "readtoto.com",
"readtoto.net", "readtoto.net",
"readtoto.org", "readtoto.org",
@ -1009,11 +1014,17 @@ open class BatoTo(
"xbato.org", "xbato.org",
"zbato.com", "zbato.com",
"zbato.net", "zbato.net",
"zbato.org",
) )
private val MIRROR_PREF_ENTRY_VALUES = MIRROR_PREF_ENTRIES.map { "https://$it" }.toTypedArray() private val MIRROR_PREF_ENTRY_VALUES = MIRROR_PREF_ENTRIES.map { "https://$it" }.toTypedArray()
private val MIRROR_PREF_DEFAULT_VALUE = MIRROR_PREF_ENTRY_VALUES[0] private val MIRROR_PREF_DEFAULT_VALUE = MIRROR_PREF_ENTRY_VALUES[0]
private val DEPRECATED_MIRRORS = listOf(
"https://bato.to",
"https://mangatoto.com",
"https://mangatoto.net",
"https://mangatoto.org",
)
private const val ALT_CHAPTER_LIST_PREF_KEY = "ALT_CHAPTER_LIST" private const val ALT_CHAPTER_LIST_PREF_KEY = "ALT_CHAPTER_LIST"
private const val ALT_CHAPTER_LIST_PREF_TITLE = "Alternative Chapter List" private const val ALT_CHAPTER_LIST_PREF_TITLE = "Alternative Chapter List"
private const val ALT_CHAPTER_LIST_PREF_SUMMARY = "If checked, uses an alternate chapter list" private const val ALT_CHAPTER_LIST_PREF_SUMMARY = "If checked, uses an alternate chapter list"