diff --git a/extension-app/build.gradle.kts b/extension-app/build.gradle.kts index a9688ee..383006f 100644 --- a/extension-app/build.gradle.kts +++ b/extension-app/build.gradle.kts @@ -7,7 +7,7 @@ plugins { val packageName = "org.easybangumi.extension" // 库版本,目前 5.0.3 支持的库版本为 3 到 5 -val extensionLibVersion = 6 +val extensionLibVersion = 7 android { namespace = packageName @@ -17,8 +17,8 @@ android { applicationId = packageName minSdk = 21 targetSdk = 34 - versionCode = 5 - versionName = "1.4" + versionCode = 6 + versionName = "1.5" manifestPlaceholders.put("extensionLibVersion", extensionLibVersion) diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/Common.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/Common.kt index f669150..6182f24 100644 --- a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/Common.kt +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/Common.kt @@ -12,54 +12,48 @@ import java.util.concurrent.locks.ReentrantLock import kotlin.concurrent.withLock -private val urlPageUrl = "https://wedm.cc/" - -private val baseUrlFallback = "https://www.886dm.tv" - -@Volatile -private var _fengCheBaseUrl: String? = null - -val FengCheBaseUrl: String - get() = requireFengCheBaseUrl() - -private val baseUrlLock = ReentrantLock() - -private fun requireFengCheBaseUrl(): String { - if (_fengCheBaseUrl == null) { - baseUrlLock.withLock { - if (_fengCheBaseUrl == null) { - _fengCheBaseUrl = runCatching { - requestFengCheBaseUrl() - }.onFailure { - Log.e("FengCheSourceCommon", "requireFengCheBaseUrl:${it.message}", it) - } - .getOrNull() ?: baseUrlFallback - } - } - } - return _fengCheBaseUrl!! -} - -private fun requestFengCheBaseUrl(): String { - val doc = commonHttpClient.newGetRequest { - url(urlPageUrl) - }.asDocument() - - val website = doc.selectFirst(".main .item p")?.text()?.trim()?.let { text -> - val colonIndex = - text.lastIndexOf(':').takeIf { it >= 0 } ?: text.lastIndexOf(':') - if (colonIndex >= 0) { - text.substring(colonIndex + 1).trim() - } else { - null - } - } - return if (website?.isNotBlank() == true) { - "https://$website" - } else { - baseUrlFallback - } -} +//private val urlPageUrl = "https://wedm.cc/" +// +//private val baseUrlFallback = "https://www.886dm.tv" +// +//@Volatile +//private var _fengCheBaseUrl: String? = null +// +//val FengCheBaseUrl: String +// get() = requireFengCheBaseUrl() +// +//private val baseUrlLock = ReentrantLock() +// +//private fun requireFengCheBaseUrl(): String { +// if (_fengCheBaseUrl == null) { +// baseUrlLock.withLock { +// if (_fengCheBaseUrl == null) { +// _fengCheBaseUrl = runCatching { +// requestFengCheBaseUrl() +// }.onFailure { +// Log.e("FengCheSourceCommon", "requireFengCheBaseUrl:${it.message}", it) +// } +// .getOrNull() ?: baseUrlFallback +// } +// } +// } +// return _fengCheBaseUrl!! +//} +// +//private fun requestFengCheBaseUrl(): String { +// val doc = commonHttpClient.newGetRequest { +// url(urlPageUrl) +// }.asDocument() +// +// val website = doc.selectFirst(".main .speedlist li a i")?.text()?.trim()?.let { text -> +// text +// } +// return if (website?.isNotBlank() == true) { +// "https://$website" +// } else { +// baseUrlFallback +// } +//} fun String.extractFengCheIdFromUrl() = diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheDetail.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheDetail.kt index 9128373..2b301ed 100644 --- a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheDetail.kt +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheDetail.kt @@ -16,11 +16,13 @@ import io.github.easybangumiorg.source.aio.map import io.github.easybangumiorg.source.aio.newGetRequest import kotlinx.coroutines.Dispatchers -class FengCheDetail : ComponentWrapper(), DetailedComponent { +class FengCheDetail ( + private val hostUrlHelper: FengCheHostUrlHelper +): ComponentWrapper(), DetailedComponent { override suspend fun getAll(summary: CartoonSummary): SourceResult>> = withResult(Dispatchers.IO) { val document = commonHttpClient.newGetRequest { - url("$FengCheBaseUrl/video/${summary.id}.html") + url("${hostUrlHelper.fengcheBaseUrl}/video/${summary.id}.html") }.asDocument() val imageUrl = document.selectFirst(".con_c1 .img_wrapper")!!.dataset()["original"]!! @@ -60,7 +62,7 @@ class FengCheDetail : ComponentWrapper(), DetailedComponent { val cartoon = CartoonImpl( id = summary.id, source = source.key, - url = "$FengCheBaseUrl/video/${summary.id}.html", + url = "${hostUrlHelper.fengcheBaseUrl}/video/${summary.id}.html", title = title, coverUrl = imageUrl, description = desc, diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheHostUrlHelper.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheHostUrlHelper.kt new file mode 100644 index 0000000..f5b7a21 --- /dev/null +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheHostUrlHelper.kt @@ -0,0 +1,50 @@ +package io.github.easybangumiorg.source.aio.fengche + +import com.heyanle.easybangumi4.source_api.utils.api.PreferenceHelper +import io.github.easybangumiorg.source.aio.asDocument +import io.github.easybangumiorg.source.aio.commonHttpClient +import io.github.easybangumiorg.source.aio.newGetRequest + +/** + * Created by heyanlin on 2024/5/23. + */ +class FengCheHostUrlHelper( + private val preferenceHelper: PreferenceHelper +) { + + private val autoHostUrl: Boolean + get() = preferenceHelper.get("auto_host_url", "false") == "true" + + private val diyUrl: String + get() = preferenceHelper.get("BaseUrl", "http://www.fcdm9.com/") + + private val urlPageUrl = "https://wedm.cc/" + + private val fengcheBaseUrlAutoUrl: String by lazy { + val doc = commonHttpClient.newGetRequest { + url(urlPageUrl) + }.asDocument() + + val website = doc.selectFirst(".main .speedlist li a i")?.text()?.trim()?.let { text -> + text + } + return@lazy if (website?.isNotBlank() == true) { + "https://$website" + } else { + diyUrl + } + } + + val fengcheBaseUrl: String + get() = (if(autoHostUrl) fengcheBaseUrlAutoUrl else diyUrl).let { + if (it.endsWith("/")){ + it.substring(0, it.length - 1) + }else{ + it + } + } + + + + +} \ No newline at end of file diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePage.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePage.kt index a7c9092..469120a 100644 --- a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePage.kt +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePage.kt @@ -15,7 +15,10 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -class FengChePage(val okhttpHelper: OkhttpHelper) : ComponentWrapper(), PageComponent { +class FengChePage( + val okhttpHelper: OkhttpHelper, + private val hostUrlHelper: FengCheHostUrlHelper +) : ComponentWrapper(), PageComponent { private val categoryLock = Mutex() @@ -25,7 +28,7 @@ class FengChePage(val okhttpHelper: OkhttpHelper) : ComponentWrapper(), PageComp val home = SourcePage.Group("首页", false) { withResult(Dispatchers.IO) { val document = okhttpHelper.client.newGetRequest { - url(FengCheBaseUrl) + url(hostUrlHelper.fengcheBaseUrl) }.asDocument() val pages = mutableListOf() document.select("body > div.wrapper").forEach { wrapperEl -> @@ -78,7 +81,7 @@ class FengChePage(val okhttpHelper: OkhttpHelper) : ComponentWrapper(), PageComp category: String, page: Int ): Pair> { - val pageUrl = "$FengCheBaseUrl/show/$typeKey---$category-----$page---.html" + val pageUrl = "${hostUrlHelper.fengcheBaseUrl}/show/$typeKey---$category-----$page---.html" val document = okhttpHelper.client.newGetRequest { url(pageUrl) }.asDocument() @@ -102,7 +105,7 @@ class FengChePage(val okhttpHelper: OkhttpHelper) : ComponentWrapper(), PageComp private fun requestVideoCategories(): List { val document = okhttpHelper.client.newGetRequest { - url("$FengCheBaseUrl/type/ribendongman.html") + url("${hostUrlHelper.fengcheBaseUrl}/type/ribendongman.html") }.asDocument() val row = document.select("body > div.wrapper.culum_list > div.conx.star_bot > div > div")[1] diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePlay.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePlay.kt index f35a3fe..7189e17 100644 --- a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePlay.kt +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePlay.kt @@ -18,7 +18,9 @@ import javax.crypto.Cipher import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec -class FengChePlay : ComponentWrapper(), PlayComponent { +class FengChePlay( + private val hostUrlHelper: FengCheHostUrlHelper +) : ComponentWrapper(), PlayComponent { override suspend fun getPlayInfo( summary: CartoonSummary, playLine: PlayLine, @@ -45,7 +47,7 @@ class FengChePlay : ComponentWrapper(), PlayComponent { private fun extractPlayerParam(episodeId: String): String { val html = commonHttpClient.newGetRequest { - url("$FengCheBaseUrl/play/$episodeId.html") + url("${hostUrlHelper.fengcheBaseUrl}/play/$episodeId.html") }.bodyString() val startIndex = html.indexOf("player_aaaa") val startBracketIndex = html.indexOf('{', startIndex + 1) diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePrefer.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePrefer.kt new file mode 100644 index 0000000..42a9864 --- /dev/null +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengChePrefer.kt @@ -0,0 +1,17 @@ +package io.github.easybangumiorg.source.aio.fengche + +import com.heyanle.easybangumi4.source_api.component.ComponentWrapper +import com.heyanle.easybangumi4.source_api.component.preference.PreferenceComponent +import com.heyanle.easybangumi4.source_api.component.preference.SourcePreference +import com.heyanle.easybangumi4.source_api.component.search.SearchComponent + +/** + * Created by heyanlin on 2024/5/23. + */ +class FengChePrefer : ComponentWrapper(), PreferenceComponent { + + override fun register(): List = listOf( + SourcePreference.Switch("自动从 wedm.cc 获取网址", "auto_host_url", true), + SourcePreference.Edit("自定义网址(当自动关闭时才有效)", "BaseUrl", "http://www.fcdm9.com/"), + ) +} \ No newline at end of file diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSearch.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSearch.kt index 28451e5..c536570 100644 --- a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSearch.kt +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSearch.kt @@ -12,7 +12,9 @@ import io.github.easybangumiorg.source.aio.encodeUri import io.github.easybangumiorg.source.aio.newGetRequest import kotlinx.coroutines.Dispatchers -class FengCheSearch : ComponentWrapper(), SearchComponent { +class FengCheSearch( + private val hostUrlHelper: FengCheHostUrlHelper +) : ComponentWrapper(), SearchComponent { override fun getFirstSearchKey(keyword: String): Int = 1 @@ -21,7 +23,7 @@ class FengCheSearch : ComponentWrapper(), SearchComponent { keyword: String ): SourceResult>> = withResult(Dispatchers.IO) { val document = commonHttpClient.newGetRequest { - url("$FengCheBaseUrl/search/${keyword.encodeUri()}----------$pageKey---.html") + url("${hostUrlHelper.fengcheBaseUrl}/search/${keyword.encodeUri()}----------$pageKey---.html") }.asDocument() val videos = document.select(".sear_con > .reusltbox").map { box-> diff --git a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSource.kt b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSource.kt index 8d57e7d..5e603a3 100644 --- a/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSource.kt +++ b/extension-app/src/main/java/io/github/easybangumiorg/source/aio/fengche/FengCheSource.kt @@ -13,9 +13,9 @@ class FengCheSource : Source, ExtensionIconSource { override val label: String get() = "风车动漫" override val version: String - get() = "2.0" + get() = "2.1" override val versionCode: Int - get() = 4 + get() = 5 override fun getIconResourcesId(): Int = R.drawable.fengche @@ -23,6 +23,8 @@ class FengCheSource : Source, ExtensionIconSource { FengChePage::class, FengCheDetail::class, FengChePlay::class, - FengCheSearch::class + FengCheSearch::class, + FengChePrefer::class, + FengCheHostUrlHelper::class ) } \ No newline at end of file diff --git a/extension-app/src/main/java/io/github/peacefulprogram/easybangumi_mxdm/MxdmUtil.kt b/extension-app/src/main/java/io/github/peacefulprogram/easybangumi_mxdm/MxdmUtil.kt index 62a8cf1..7099dee 100644 --- a/extension-app/src/main/java/io/github/peacefulprogram/easybangumi_mxdm/MxdmUtil.kt +++ b/extension-app/src/main/java/io/github/peacefulprogram/easybangumi_mxdm/MxdmUtil.kt @@ -1,5 +1,6 @@ package io.github.peacefulprogram.easybangumi_mxdm +import com.heyanle.easybangumi4.source_api.utils.api.NetworkHelper import com.heyanle.easybangumi4.source_api.utils.api.OkhttpHelper import com.heyanle.easybangumi4.source_api.utils.api.PreferenceHelper import okhttp3.Request @@ -8,10 +9,17 @@ import org.jsoup.nodes.Element class MxdmUtil( private val okhttpHelper: OkhttpHelper, + private val networkHelper: NetworkHelper, private val preferenceHelper: PreferenceHelper ) { val baseUrl:String - get() = preferenceHelper.get("BaseUrl", "https://www.mxdm.tv/") + get() = preferenceHelper.get("BaseUrl", "https://www.mxdm.tv").let { + if (it.endsWith("/")){ + it.substring(0, it.length - 1) + }else{ + it + } + } val userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" @@ -22,11 +30,11 @@ class MxdmUtil( baseUrl + url } val req = Request.Builder() - .header("user-agent", userAgent) + .header("user-agent", networkHelper.defaultAndroidUA) .url(actualUrl) .get() .build() - return okhttpHelper.client.newCall(req).execute().body?.string() ?: throw RuntimeException( + return okhttpHelper.cloudflareWebViewClient.newCall(req).execute().body?.string() ?: throw RuntimeException( "响应为空:$url" ) }