fix: 修复tvcat.cc选择器和播放页URL提取
- 详情页: sourceSelector/episodeGroupSelector置空,强制走fallback正确提取剧集 - 播放页: 新增fetchPlayUrlFromApi方法,通过/_fetch_p/ API获取m3u8直链 - PlayerActivity: extractFromPlayPage返回空时尝试API获取,失败再用WebView
This commit is contained in:
@@ -259,7 +259,12 @@ class PlayerActivity : AppCompatActivity() {
|
||||
} else if (iframeUrl != null) {
|
||||
playWithWebView(iframeUrl)
|
||||
} else {
|
||||
playWithWebView(ep.playUrl)
|
||||
val apiUrl = videoExtractor.fetchPlayUrlFromApi(ep.playUrl, config.baseUrl)
|
||||
if (apiUrl != null) {
|
||||
playWithExoPlayer(apiUrl)
|
||||
} else {
|
||||
playWithWebView(ep.playUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ data class SitePreset(
|
||||
categorySelector = ".text-muted",
|
||||
dateSelector = "",
|
||||
episodeSelector = "li.list-inline-item a",
|
||||
sourceSelector = "h2",
|
||||
sourceEpisodeGroupSelector = "ul.list-unstyled",
|
||||
sourceSelector = "",
|
||||
sourceEpisodeGroupSelector = "",
|
||||
iframeSelector = "iframe",
|
||||
videoSelector = "video source, video[src]"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.videoapp.tv.engine
|
||||
import com.videoapp.tv.data.SiteConfig
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
import org.jsoup.Jsoup
|
||||
import java.net.URL
|
||||
|
||||
data class Episode(
|
||||
val title: String,
|
||||
@@ -90,4 +92,30 @@ class VideoExtractor {
|
||||
Pair(null, null)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fetchPlayUrlFromApi(
|
||||
playUrl: String,
|
||||
baseUrl: String
|
||||
): String? = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val pattern = Regex("""(\d+)/ep(\d+)""")
|
||||
val match = pattern.find(playUrl) ?: return@withContext null
|
||||
val videoId = match.groupValues[1]
|
||||
val epNum = match.groupValues[2]
|
||||
val apiUrl = "${baseUrl.trimEnd('/')}/_fetch_p/$videoId/ep$epNum"
|
||||
val conn = URL(apiUrl).openConnection()
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/5.0")
|
||||
conn.setRequestProperty("Referer", playUrl)
|
||||
conn.connectTimeout = 15000
|
||||
conn.readTimeout = 15000
|
||||
val json = conn.getInputStream().bufferedReader().use { it.readText() }
|
||||
val obj = JSONObject(json)
|
||||
val playcfgs = obj.getJSONArray("playcfgs")
|
||||
if (playcfgs.length() > 0) {
|
||||
playcfgs.getJSONObject(0).getString("url")
|
||||
} else null
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user