diff --git a/app/src/main/java/com/github/catvod/utils/ProxyServer.kt b/app/src/main/java/com/github/catvod/utils/ProxyServer.kt index 3ab455e5..ccf630f1 100644 --- a/app/src/main/java/com/github/catvod/utils/ProxyServer.kt +++ b/app/src/main/java/com/github/catvod/utils/ProxyServer.kt @@ -2,14 +2,12 @@ package com.github.catvod.utils import com.github.catvod.crawler.SpiderDebug import com.github.catvod.net.OkHttp -import com.google.gson.Gson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import java.nio.charset.Charset object ProxyServer { @@ -18,6 +16,8 @@ object ProxyServer { private var port = 12345 private var httpServer: AdvancedHttpServer? = null private val infos = mutableMapOf>>(); + private val urlMap = mutableMapOf(); + private val headerMap = mutableMapOf>(); fun stop() { @@ -38,21 +38,13 @@ object ProxyServer { }; httpServer?.addRoutes("/proxy") { req, response -> run { - var url = req.queryParams["url"]; - val headers = req.queryParams["headers"]; - SpiderDebug.log("url: $url") - SpiderDebug.log("headers: $headers") - url = String( - org.apache.commons.codec.binary.Base64().decode(url), - Charset.forName("UTF-8") - ) - val header: Map = Gson().fromJson>( - String( - org.apache.commons.codec.binary.Base64().decode(headers), - Charset.forName("UTF-8") - ), MutableMap::class.java - ) - proxyAsync(url, header, req, response) + val key = req.queryParams["key"]; + val url = urlMap[key] + val header = headerMap[key] + + if (url != null && header != null) { + proxyAsync(url, header, req, response) + } } } httpServer?.start() @@ -197,7 +189,7 @@ object ProxyServer { return start to end } - fun getInfo( + private fun getInfo( url: String?, headers: Map ): MutableMap> { val newHeaders: MutableMap = java.util.HashMap(headers) @@ -226,14 +218,13 @@ object ProxyServer { } fun buildProxyUrl(url: String, headers: Map): String { - val urlBase64 = org.apache.commons.codec.binary.Base64() - .encodeToString(url.toByteArray(Charset.defaultCharset())) - val headerBase64 = org.apache.commons.codec.binary.Base64().encodeToString( - Json.toJson(headers).toByteArray( - Charset.defaultCharset() - ) - ) - return "http://127.0.0.1:$port/proxy?url=$urlBase64&headers=$headerBase64" + urlMap.clear() + headerMap.clear() + val key = Util.MD5(url) + urlMap[key] = url + headerMap[key] = headers + + return "http://127.0.0.1:$port/proxy?key=$key" } diff --git a/jar/custom_spider.jar b/jar/custom_spider.jar index bdb11938..178f691f 100644 Binary files a/jar/custom_spider.jar and b/jar/custom_spider.jar differ diff --git a/jar/custom_spider.jar.md5 b/jar/custom_spider.jar.md5 index cdc5a43d..67e4510d 100644 --- a/jar/custom_spider.jar.md5 +++ b/jar/custom_spider.jar.md5 @@ -1 +1 @@ -89689d186862de9fb12508bfe3ac4689 +14d3c420f76ba891e74f8a858bce6586 diff --git a/json/test.json b/json/test.json index 4b94efc0..4756a5e5 100644 --- a/json/test.json +++ b/json/test.json @@ -1,5 +1,5 @@ { - "spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;89689d186862de9fb12508bfe3ac4689", + "spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;14d3c420f76ba891e74f8a858bce6586", "lives": [ { "name": "电视直播",