diff --git a/src/zh/xfani/build.gradle b/src/zh/xfani/build.gradle index 03ea035..a7ccc34 100644 --- a/src/zh/xfani/build.gradle +++ b/src/zh/xfani/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Xfani' extClass = '.Xfani' - extVersionCode = 1 + extVersionCode = 2 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/xfani/src/eu/kanade/tachiyomi/animeextension/zh/xfani/Xfani.kt b/src/zh/xfani/src/eu/kanade/tachiyomi/animeextension/zh/xfani/Xfani.kt index be71aeb..77a1e45 100644 --- a/src/zh/xfani/src/eu/kanade/tachiyomi/animeextension/zh/xfani/Xfani.kt +++ b/src/zh/xfani/src/eu/kanade/tachiyomi/animeextension/zh/xfani/Xfani.kt @@ -1,9 +1,12 @@ package eu.kanade.tachiyomi.animeextension.zh.xfani +import android.annotation.SuppressLint import android.app.Application import android.content.SharedPreferences +import android.widget.Toast import androidx.preference.ListPreference import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource import eu.kanade.tachiyomi.animesource.model.AnimeFilter import eu.kanade.tachiyomi.animesource.model.AnimeFilterList @@ -19,12 +22,20 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Interceptor import okhttp3.MultipartBody +import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy +import java.security.SecureRandom +import java.security.cert.X509Certificate +import javax.net.ssl.SSLContext +import javax.net.ssl.SSLHandshakeException +import javax.net.ssl.TrustManager +import javax.net.ssl.X509TrustManager class Xfani : AnimeHttpSource(), ConfigurableAnimeSource { override val baseUrl: String @@ -41,11 +52,53 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource { Injekt.get().getSharedPreferences("source_$id", 0x0000) } private val numberRegex = Regex("\\d+") + private fun OkHttpClient.Builder.ignoreAllSSLErrors(): OkHttpClient.Builder { + val naiveTrustManager = + @SuppressLint("CustomX509TrustManager") + object : X509TrustManager { + override fun getAcceptedIssuers(): Array = emptyArray() + override fun checkClientTrusted(certs: Array, authType: String) = + Unit + + override fun checkServerTrusted(certs: Array, authType: String) = + Unit + } + + val insecureSocketFactory = SSLContext.getInstance("TLSv1.2").apply { + val trustAllCerts = arrayOf(naiveTrustManager) + init(null, trustAllCerts, SecureRandom()) + }.socketFactory + + sslSocketFactory(insecureSocketFactory, naiveTrustManager) + hostnameVerifier { _, _ -> true } + return this + } + + override val client: OkHttpClient + get() = if (preferences.getBoolean(PREF_KEY_IGNORE_SSL_ERROR, false)) { + network.client.newBuilder().ignoreAllSSLErrors().build() + } else { + network.client.newBuilder().addInterceptor(::checkSSLErrorInterceptor).build() + } private val selectedVideoSource get() = preferences.getString(PREF_KEY_VIDEO_SOURCE, DEFAULT_VIDEO_SOURCE)!!.toInt() - override fun animeDetailsParse(response: Response): SAnime = SAnime.create() + private fun checkSSLErrorInterceptor(chain: Interceptor.Chain): Response { + try { + return chain.proceed(chain.request()) + } catch (e: SSLHandshakeException) { + throw SSLHandshakeException("SSL证书验证异常,可以尝试在设置中忽略SSL验证问题。") + } + } + + override fun animeDetailsParse(response: Response): SAnime { + val jsoup = response.asJsoup() + return SAnime.create().apply { + description = jsoup.select("#height_limit.text").text() + title = jsoup.select(".slide-info-title").text() + } + } override fun episodeListParse(response: Response): List { val jsoup = response.asJsoup() @@ -61,7 +114,7 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource { url = it.attr("href") episode_number = numberRegex.find(name)?.value?.toFloat() ?: -1F } - } + }.sortedByDescending { it.episode_number } } override fun videoListParse(response: Response): List