fix: Jsoup请求添加User-Agent头,防止tvcat反爬拦截
This commit is contained in:
@@ -24,6 +24,9 @@ abstract class BaseSourceHandler(
|
|||||||
val url = "${baseUrl.trimEnd('/')}/${config.searchPath.trimStart('/')}"
|
val url = "${baseUrl.trimEnd('/')}/${config.searchPath.trimStart('/')}"
|
||||||
val connection: Connection = Jsoup.connect(url)
|
val connection: Connection = Jsoup.connect(url)
|
||||||
.data(config.keywordParam, keyword)
|
.data(config.keywordParam, keyword)
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
||||||
|
.header("Accept", "text/html,application/xhtml+xml")
|
||||||
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
||||||
.timeout(15000)
|
.timeout(15000)
|
||||||
|
|
||||||
config.extraParams.forEach { (key, value) ->
|
config.extraParams.forEach { (key, value) ->
|
||||||
@@ -83,7 +86,10 @@ abstract class BaseSourceHandler(
|
|||||||
|
|
||||||
override suspend fun extractVideos(detailUrl: String): List<PlaySource> =
|
override suspend fun extractVideos(detailUrl: String): List<PlaySource> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val doc = Jsoup.connect(detailUrl).timeout(15000).get()
|
val doc = Jsoup.connect(detailUrl)
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
||||||
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
||||||
|
.timeout(15000).get()
|
||||||
|
|
||||||
val sourceTabs = doc.select(config.sourceSelector)
|
val sourceTabs = doc.select(config.sourceSelector)
|
||||||
val sourceNames = sourceTabs.map { it.text().trim() }.filter { it.isNotEmpty() }
|
val sourceNames = sourceTabs.map { it.text().trim() }.filter { it.isNotEmpty() }
|
||||||
@@ -115,7 +121,10 @@ abstract class BaseSourceHandler(
|
|||||||
override suspend fun resolvePlayUrl(playUrl: String): Pair<String?, String?> =
|
override suspend fun resolvePlayUrl(playUrl: String): Pair<String?, String?> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val doc = Jsoup.connect(playUrl).timeout(15000).get()
|
val doc = Jsoup.connect(playUrl)
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
||||||
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
||||||
|
.timeout(15000).get()
|
||||||
|
|
||||||
val iframeEl = doc.selectFirst(config.iframeSelector)
|
val iframeEl = doc.selectFirst(config.iframeSelector)
|
||||||
var iframeUrl = iframeEl?.attr("src")
|
var iframeUrl = iframeEl?.attr("src")
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ class TvcatHandler : BaseSourceHandler(
|
|||||||
) {
|
) {
|
||||||
override suspend fun extractVideos(detailUrl: String): List<PlaySource> =
|
override suspend fun extractVideos(detailUrl: String): List<PlaySource> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val doc = Jsoup.connect(detailUrl).timeout(15000).get()
|
val doc = Jsoup.connect(detailUrl)
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
||||||
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
||||||
|
.timeout(15000).get()
|
||||||
val episodes = doc.select("li.list-inline-item a").mapNotNull { ep ->
|
val episodes = doc.select("li.list-inline-item a").mapNotNull { ep ->
|
||||||
val title = ep.text().trim()
|
val title = ep.text().trim()
|
||||||
val href = ep.attr("href").trim()
|
val href = ep.attr("href").trim()
|
||||||
|
|||||||
Reference in New Issue
Block a user