Skip to content

Commit

Permalink
风车域名支持配置
Browse files Browse the repository at this point in the history
  • Loading branch information
heyanlin committed May 23, 2024
1 parent a584850 commit 1fd0636
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 68 deletions.
6 changes: 3 additions & 3 deletions extension-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
val packageName = "org.easybangumi.extension"

// 库版本,目前 5.0.3 支持的库版本为 3 到 5
val extensionLibVersion = 6
val extensionLibVersion = 7

android {
namespace = packageName
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<Cartoon, List<PlayLine>>> =
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"]!!
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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<SourcePage.SingleCartoonPage>()
document.select("body > div.wrapper").forEach { wrapperEl ->
Expand Down Expand Up @@ -78,7 +81,7 @@ class FengChePage(val okhttpHelper: OkhttpHelper) : ComponentWrapper(), PageComp
category: String,
page: Int
): Pair<Int?, List<CartoonCover>> {
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()
Expand All @@ -102,7 +105,7 @@ class FengChePage(val okhttpHelper: OkhttpHelper) : ComponentWrapper(), PageComp

private fun requestVideoCategories(): List<VideoCategory> {
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SourcePreference> = listOf(
SourcePreference.Switch("自动从 wedm.cc 获取网址", "auto_host_url", true),
SourcePreference.Edit("自定义网址(当自动关闭时才有效)", "BaseUrl", "http://www.fcdm9.com/"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,7 +23,7 @@ class FengCheSearch : ComponentWrapper(), SearchComponent {
keyword: String
): SourceResult<Pair<Int?, List<CartoonCover>>> = 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->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ 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

override fun register(): List<KClass<*>> = listOf(
FengChePage::class,
FengCheDetail::class,
FengChePlay::class,
FengCheSearch::class
FengCheSearch::class,
FengChePrefer::class,
FengCheHostUrlHelper::class
)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

Expand All @@ -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"
)
}
Expand Down

0 comments on commit 1fd0636

Please sign in to comment.