diff --git a/TvBoxPlugin b/TvBoxPlugin index d8c6366..4d6d163 160000 --- a/TvBoxPlugin +++ b/TvBoxPlugin @@ -1 +1 @@ -Subproject commit d8c63661de07fb2c0dcd5246189f946d94e906da +Subproject commit 4d6d1634dc53958b99bb24f23e82e1415222d75a diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3041e55..12b877b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ android:value="com.muedsa.tvbox" /> + android:value="5" /> diff --git a/app/src/main/java/com/muedsa/tvbox/an1me/An1mePlugin.kt b/app/src/main/java/com/muedsa/tvbox/an1me/An1mePlugin.kt index 2efef25..f18f8ab 100644 --- a/app/src/main/java/com/muedsa/tvbox/an1me/An1mePlugin.kt +++ b/app/src/main/java/com/muedsa/tvbox/an1me/An1mePlugin.kt @@ -11,35 +11,37 @@ 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.createOkHttpClient class An1mePlugin(tvBoxContext: TvBoxContext) : IPlugin(tvBoxContext = tvBoxContext) { override var options: PluginOptions = PluginOptions(enableDanDanPlaySearch = true) - private val cookieSaver by lazy { SharedCookieSaver(store = tvBoxContext.store) } - private val cookieStore by lazy { PluginCookieStore(saver = cookieSaver) } - private val cookieJar by lazy { PluginCookieJar(saver = cookieSaver) } - private val okHttpClient by lazy { createOkHttpClient(debug = tvBoxContext.debug, cookieJar = cookieJar) } - private val an1meService by lazy { An1meService() } + private val okHttpClient by lazy { + createOkHttpClient( + debug = tvBoxContext.debug, + cookieJar = PluginCookieJar( + saver = SharedCookieSaver(store = tvBoxContext.store) + ) + ) + } + private val an1meService by lazy { An1meService(okHttpClient = okHttpClient) } private val mainScreenService by lazy { MainScreenService( an1meService = an1meService, - cookieStore = cookieStore + okHttpClient = okHttpClient ) } private val mediaDetailService by lazy { MediaDetailService( an1meService = an1meService, - cookieStore = cookieStore, okHttpClient = okHttpClient ) } private val mediaSearchService by lazy { MediaSearchService( an1meService = an1meService, - cookieStore = cookieStore + okHttpClient = okHttpClient ) } override fun provideMainScreenService(): IMainScreenService = mainScreenService diff --git a/app/src/main/java/com/muedsa/tvbox/an1me/service/An1meService.kt b/app/src/main/java/com/muedsa/tvbox/an1me/service/An1meService.kt index 9ed870d..a188c0d 100644 --- a/app/src/main/java/com/muedsa/tvbox/an1me/service/An1meService.kt +++ b/app/src/main/java/com/muedsa/tvbox/an1me/service/An1meService.kt @@ -1,21 +1,29 @@ package com.muedsa.tvbox.an1me.service import com.muedsa.tvbox.tool.feignChrome +import com.muedsa.tvbox.tool.get +import com.muedsa.tvbox.tool.parseHtml +import com.muedsa.tvbox.tool.toRequestBuild import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import okhttp3.HttpUrl.Companion.toHttpUrl -import org.jsoup.Jsoup +import okhttp3.OkHttpClient import timber.log.Timber -class An1meService { +class An1meService( + private val okHttpClient: OkHttpClient +) { private var siteUrl: String? = null private val mutex = Mutex() suspend fun getSiteUrl(): String = mutex.withLock { if (siteUrl == null) { - val body = Jsoup.connect("https://1anime.org/") + val body = "https://1anime.org/".toRequestBuild() .feignChrome() - .get() + .header("Connection", "close") // 这里使用http1.1 + .header("http.protocol", "http/1.1") // 这里使用http1.1 + .get(okHttpClient = okHttpClient) + .parseHtml() .body() val links = body.select(".release-main .links ul li a[href]") .map { it.attr("href") } diff --git a/app/src/main/java/com/muedsa/tvbox/an1me/service/MainScreenService.kt b/app/src/main/java/com/muedsa/tvbox/an1me/service/MainScreenService.kt index a5c78dc..6fa2772 100644 --- a/app/src/main/java/com/muedsa/tvbox/an1me/service/MainScreenService.kt +++ b/app/src/main/java/com/muedsa/tvbox/an1me/service/MainScreenService.kt @@ -6,19 +6,22 @@ import com.muedsa.tvbox.api.data.MediaCardRow import com.muedsa.tvbox.api.data.MediaCardType import com.muedsa.tvbox.api.service.IMainScreenService import com.muedsa.tvbox.tool.feignChrome -import org.jsoup.Jsoup +import com.muedsa.tvbox.tool.get +import com.muedsa.tvbox.tool.parseHtml +import com.muedsa.tvbox.tool.toRequestBuild +import okhttp3.OkHttpClient import org.jsoup.nodes.Element -import java.net.CookieStore class MainScreenService( private val an1meService: An1meService, - private val cookieStore: CookieStore + private val okHttpClient: OkHttpClient ) : IMainScreenService { override suspend fun getRowsData(): List { - val body = Jsoup.connect("${an1meService.getSiteUrl()}/") - .feignChrome(cookieStore = cookieStore) - .get() + val body = "${an1meService.getSiteUrl()}/".toRequestBuild() + .feignChrome() + .get(okHttpClient = okHttpClient) + .parseHtml() .body() val rows: MutableList = mutableListOf() body.select("#index-main >.content >.module") diff --git a/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaDetailService.kt b/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaDetailService.kt index de34661..943076b 100644 --- a/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaDetailService.kt +++ b/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaDetailService.kt @@ -14,16 +14,15 @@ import com.muedsa.tvbox.tool.ChromeUserAgent import com.muedsa.tvbox.tool.LenientJson import com.muedsa.tvbox.tool.decodeBase64ToStr import com.muedsa.tvbox.tool.feignChrome +import com.muedsa.tvbox.tool.get +import com.muedsa.tvbox.tool.parseHtml +import com.muedsa.tvbox.tool.toRequestBuild import okhttp3.OkHttpClient -import okhttp3.Request -import org.jsoup.Jsoup import org.jsoup.nodes.Element import timber.log.Timber -import java.net.CookieStore class MediaDetailService( private val an1meService: An1meService, - private val cookieStore: CookieStore, private val okHttpClient: OkHttpClient ) : IMediaDetailService { @@ -31,9 +30,10 @@ class MediaDetailService( if (!detailUrl.startsWith("/voddetail/")) { throw RuntimeException("不支持的类型 $detailUrl") } - val body = Jsoup.connect("${an1meService.getSiteUrl()}$detailUrl") - .feignChrome(cookieStore = cookieStore) - .get() + val body = "${an1meService.getSiteUrl()}$detailUrl".toRequestBuild() + .feignChrome() + .get(okHttpClient = okHttpClient) + .parseHtml() .body() val boxEl = body.selectFirst("#main .content .box")!! val imgUrl = boxEl.selectFirst(".module-item-cover .module-item-pic img")!! @@ -163,9 +163,10 @@ class MediaDetailService( throw RuntimeException("不支持的播放地址-> ${episode.flag5}") } val url = "${an1meService.getSiteUrl()}${episode.flag5}" - val body = Jsoup.connect(url) - .feignChrome(cookieStore = cookieStore) - .get() + val body = url.toRequestBuild() + .feignChrome() + .get(okHttpClient = okHttpClient) + .parseHtml() .body() val scriptEl = body.selectFirst("#main .player-wrapper script")!! val result = An1meConst.PLAYER_INFO_REGEX.find(scriptEl.outerHtml()) @@ -298,14 +299,11 @@ class MediaDetailService( referer: String? = null, failureMsg: String = "请求失败" ): String { - val req = Request.Builder() - .url(url) - .apply { - referer?.let { addHeader("Referer", it) } - } - .addHeader("User-Agent", ChromeUserAgent) - .build() - val resp = okHttpClient.newCall(req).execute() + val resp = url.toRequestBuild() + .feignChrome(referer = referer) + .header("Connection", "close") // 这里使用http1.1 + .header("http.protocol", "http/1.1") // 这里使用http1.1 + .get(okHttpClient = okHttpClient) if (!resp.isSuccessful) throw RuntimeException(failureMsg) val bodyStr = resp.body?.string() ?: throw RuntimeException(failureMsg) return bodyStr diff --git a/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaSearchService.kt b/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaSearchService.kt index f82e430..4428d82 100644 --- a/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaSearchService.kt +++ b/app/src/main/java/com/muedsa/tvbox/an1me/service/MediaSearchService.kt @@ -5,18 +5,21 @@ import com.muedsa.tvbox.api.data.MediaCard import com.muedsa.tvbox.api.data.MediaCardRow import com.muedsa.tvbox.api.service.IMediaSearchService import com.muedsa.tvbox.tool.feignChrome -import org.jsoup.Jsoup -import java.net.CookieStore +import com.muedsa.tvbox.tool.get +import com.muedsa.tvbox.tool.parseHtml +import com.muedsa.tvbox.tool.toRequestBuild +import okhttp3.OkHttpClient class MediaSearchService( private val an1meService: An1meService, - private val cookieStore: CookieStore + private val okHttpClient: OkHttpClient ) : IMediaSearchService { override suspend fun searchMedias(query: String): MediaCardRow { - val body = Jsoup.connect("${an1meService.getSiteUrl()}/vodsearch/-------------.html?wd=$query") - .feignChrome(cookieStore = cookieStore) - .get() + val body = "${an1meService.getSiteUrl()}/vodsearch/-------------.html?wd=$query".toRequestBuild() + .feignChrome() + .get(okHttpClient = okHttpClient) + .parseHtml() .body() val moduleEl = body.selectFirst("#main .content .module") ?: return MediaCardRow( diff --git a/app/src/test/java/com/muedsa/tvbox/an1me/PlaySourceValidator.kt b/app/src/test/java/com/muedsa/tvbox/an1me/PlaySourceValidator.kt index ce534ae..a79013a 100644 --- a/app/src/test/java/com/muedsa/tvbox/an1me/PlaySourceValidator.kt +++ b/app/src/test/java/com/muedsa/tvbox/an1me/PlaySourceValidator.kt @@ -8,8 +8,8 @@ import org.junit.Test class PlaySourceValidator { - private val an1meService = An1meService() private val okHttpClient = createOkHttpClient(debug = true) + private val an1meService = An1meService(okHttpClient = okHttpClient) @Test fun addonsDpPlayerIndexPhp_valid() = runTest {