fix: TvcatHandler搜索和详情修复UTF-8编码,使用Jsoup.parseBodyFragment替代parse
This commit is contained in:
@@ -46,18 +46,19 @@ class TvcatHandler : BaseSourceHandler(
|
|||||||
val encoded = URLEncoder.encode(keyword, "UTF-8")
|
val encoded = URLEncoder.encode(keyword, "UTF-8")
|
||||||
val searchUrl = "https://tvcat.cc/search?q=$encoded"
|
val searchUrl = "https://tvcat.cc/search?q=$encoded"
|
||||||
val conn = URL(searchUrl).openConnection() as HttpURLConnection
|
val conn = URL(searchUrl).openConnection() as HttpURLConnection
|
||||||
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
||||||
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9")
|
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
|
||||||
|
conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||||
conn.connectTimeout = 15000
|
conn.connectTimeout = 15000
|
||||||
conn.readTimeout = 15000
|
conn.readTimeout = 15000
|
||||||
val html = if (conn.responseCode == 200) {
|
val html = if (conn.responseCode == 200) {
|
||||||
conn.inputStream.bufferedReader().use { it.readText() }
|
conn.inputStream.bufferedReader(Charsets.UTF_8).use { it.readText() }
|
||||||
} else ""
|
} else ""
|
||||||
conn.disconnect()
|
conn.disconnect()
|
||||||
|
|
||||||
if (html.isEmpty()) return@withContext emptyList<SearchResult>()
|
if (html.isEmpty()) return@withContext emptyList<SearchResult>()
|
||||||
|
|
||||||
val doc = Jsoup.parse(html)
|
val doc = Jsoup.parseBodyFragment(html)
|
||||||
val items = doc.select("li.col-md-2.col-sm-3.col-4")
|
val items = doc.select("li.col-md-2.col-sm-3.col-4")
|
||||||
val resultsList = mutableListOf<SearchResult>()
|
val resultsList = mutableListOf<SearchResult>()
|
||||||
|
|
||||||
@@ -103,17 +104,17 @@ 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 conn = URL(detailUrl).openConnection() as HttpURLConnection
|
val conn = URL(detailUrl).openConnection() as HttpURLConnection
|
||||||
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
||||||
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9")
|
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
|
||||||
conn.connectTimeout = 15000
|
conn.connectTimeout = 15000
|
||||||
conn.readTimeout = 15000
|
conn.readTimeout = 15000
|
||||||
val html = if (conn.responseCode == 200) {
|
val html = if (conn.responseCode == 200) {
|
||||||
conn.inputStream.bufferedReader().use { it.readText() }
|
conn.inputStream.bufferedReader(Charsets.UTF_8).use { it.readText() }
|
||||||
} else ""
|
} else ""
|
||||||
conn.disconnect()
|
conn.disconnect()
|
||||||
if (html.isEmpty()) return@withContext emptyList()
|
if (html.isEmpty()) return@withContext emptyList()
|
||||||
|
|
||||||
val doc = Jsoup.parse(html)
|
val doc = Jsoup.parseBodyFragment(html)
|
||||||
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