Skip to content

Commit

Permalink
feat: 使用okhttp+jsoup的方式代替jsoup自带的http请求
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Nov 12, 2024
1 parent a777e76 commit 28c0a80
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion TvBoxPlugin
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault" >
<meta-data android:name="tv_box_plugin_key" android:value="com.muedsa.tvbox" />
<meta-data android:name="tv_box_plugin_api_version" android:value="4" />
<meta-data android:name="tv_box_plugin_api_version" android:value="5" />
<meta-data android:name="tv_box_plugin_entry_point_impl" android:value="com.muedsa.tvbox.agetv.AgeTvPlugin"/>
</application>

Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/muedsa/tvbox/agetv/AgeTvPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.muedsa.tvbox.api.service.IMainScreenService
import com.muedsa.tvbox.api.service.IMediaDetailService
import com.muedsa.tvbox.api.service.IMediaSearchService
import com.muedsa.tvbox.tool.PluginCookieJar
import com.muedsa.tvbox.tool.PluginCookieStore
import com.muedsa.tvbox.tool.SharedCookieSaver
import com.muedsa.tvbox.tool.createJsonRetrofit
import com.muedsa.tvbox.tool.createOkHttpClient

class AgeTvPlugin(tvBoxContext: TvBoxContext) : IPlugin(tvBoxContext = tvBoxContext) {

Expand All @@ -25,20 +25,24 @@ class AgeTvPlugin(tvBoxContext: TvBoxContext) : IPlugin(tvBoxContext = tvBoxCont

private val cookieSaver by lazy { SharedCookieSaver(store = tvBoxContext.store) }
private val cookieJar by lazy { PluginCookieJar(saver = cookieSaver) }
private val cookieStore by lazy { PluginCookieStore(saver = cookieSaver) }
private val okHttpClient by lazy {
createOkHttpClient(
debug = tvBoxContext.debug,
cookieJar = cookieJar
)
}
private val ageApiService by lazy {
createJsonRetrofit(
baseUrl = AgeMobileApiUrl,
service = AgeApiService::class.java,
debug = tvBoxContext.debug,
cookieJar = cookieJar
okHttpClient = okHttpClient
)
}
private val mainScreenService by lazy { MainScreenService(ageApiService) }
private val mediaDetailService by lazy {
MediaDetailService(
ageApiService = ageApiService,
cookieStore = cookieStore,
okHttpClient = okHttpClient,
cookieJar = cookieJar,
debug = tvBoxContext.debug
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@ import com.muedsa.tvbox.tool.LenientJson
import com.muedsa.tvbox.tool.decryptAES128CBCPKCS7
import com.muedsa.tvbox.tool.encryptAES128CBCPKCS7
import com.muedsa.tvbox.tool.feignChrome
import com.muedsa.tvbox.tool.get
import com.muedsa.tvbox.tool.md5
import com.muedsa.tvbox.tool.parseHtml
import com.muedsa.tvbox.tool.toRequestBuild
import kotlinx.serialization.encodeToString
import okhttp3.CookieJar
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import retrofit2.Retrofit
import timber.log.Timber
import java.net.CookieStore
import java.net.URLDecoder
import java.util.UUID

class MediaDetailService(
private val ageApiService: AgeApiService,
private val cookieStore: CookieStore,
private val okHttpClient: OkHttpClient,
private val cookieJar: CookieJar,
private val debug: Boolean = false
) : IMediaDetailService {
Expand Down Expand Up @@ -136,7 +137,7 @@ class MediaDetailService(
}

private fun getPlayInfo(url: String): AgePlayInfoModel {
val doc = jsoupGet(url = url, cookieStore = cookieStore)
val doc = jsoupGet(url = url)
val head = doc.head()
val body = doc.body()
val key1 = head.selectFirst("meta[http-equiv=\"Content-Type\"]")
Expand Down Expand Up @@ -226,16 +227,15 @@ class MediaDetailService(
}
}

private fun jsoupGet(url: String): Document =
url.toRequestBuild()
.feignChrome(referer = AgeMobileUrl)
.get(okHttpClient = okHttpClient)
.parseHtml()

companion object {
private const val WASM_AES_KEY = "ni po jie ni ** "

private fun jsoupGet(url: String, cookieStore: CookieStore): Document {
return Jsoup.connect(url)
.feignChrome(referrer = AgeMobileUrl, cookieStore = cookieStore)
.timeout(10 * 1000)
.get()
}

private fun getJsStringVar(field: String, content: String): String {
val pattern = "var\\s+$field\\s*=\\s*['\"](.*?)['\"]\\s*;*".toRegex()
return pattern.find(content)?.groups.let {
Expand Down

0 comments on commit 28c0a80

Please sign in to comment.