xfani: format source info for aniyomi

Tmporary disable ssl check for site certificate issue.
This commit is contained in:
ZhendongWu 2024-10-21 17:24:30 +08:00
parent 80f3773bc1
commit 0b13e55d99
2 changed files with 42 additions and 5 deletions

View file

@ -1,7 +1,7 @@
ext {
extName = 'Xfani'
extClass = '.Xfani'
extVersionCode = 1
extVersionCode = 2
}
apply from: "$rootDir/common.gradle"

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.animeextension.zh.xfani
import android.annotation.SuppressLint
import android.app.Application
import android.content.SharedPreferences
import androidx.preference.ListPreference
@ -20,11 +21,17 @@ import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.HttpUrl.Companion.toHttpUrl
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.TrustManager
import javax.net.ssl.X509TrustManager
class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
override val baseUrl: String
@ -41,11 +48,41 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
Injekt.get<Application>().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<X509Certificate> = emptyArray()
override fun checkClientTrusted(certs: Array<X509Certificate>, authType: String) =
Unit
override fun checkServerTrusted(certs: Array<X509Certificate>, authType: String) =
Unit
}
val insecureSocketFactory = SSLContext.getInstance("TLSv1.2").apply {
val trustAllCerts = arrayOf<TrustManager>(naiveTrustManager)
init(null, trustAllCerts, SecureRandom())
}.socketFactory
sslSocketFactory(insecureSocketFactory, naiveTrustManager)
hostnameVerifier { _, _ -> true }
return this
}
override val client: OkHttpClient
get() = network.client.newBuilder().ignoreAllSSLErrors().build()
private val selectedVideoSource
get() = preferences.getString(PREF_KEY_VIDEO_SOURCE, DEFAULT_VIDEO_SOURCE)!!.toInt()
override fun animeDetailsParse(response: Response): SAnime = SAnime.create()
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<SEpisode> {
val jsoup = response.asJsoup()
@ -61,7 +98,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<Video> {
@ -92,9 +129,9 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
url = "/bangumi/${it.vodId}.html"
thumbnail_url = it.vodPicThumb.ifEmpty { it.vodPic }
title = it.vodName
author = it.vodActor
author = it.vodActor.replace(",,,", "")
description = it.vodBlurb
genre = it.vodClass
genre = it.vodClass.replace(",", ", ")
}
}
return AnimesPage(