This commit is contained in:
parent
16fb9d182e
commit
4cb62ebba6
|
|
@ -2,14 +2,12 @@ package com.github.catvod.utils
|
||||||
|
|
||||||
import com.github.catvod.crawler.SpiderDebug
|
import com.github.catvod.crawler.SpiderDebug
|
||||||
import com.github.catvod.net.OkHttp
|
import com.github.catvod.net.OkHttp
|
||||||
import com.google.gson.Gson
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.nio.charset.Charset
|
|
||||||
|
|
||||||
|
|
||||||
object ProxyServer {
|
object ProxyServer {
|
||||||
|
|
@ -18,6 +16,8 @@ object ProxyServer {
|
||||||
private var port = 12345
|
private var port = 12345
|
||||||
private var httpServer: AdvancedHttpServer? = null
|
private var httpServer: AdvancedHttpServer? = null
|
||||||
private val infos = mutableMapOf<String, MutableMap<String, MutableList<String>>>();
|
private val infos = mutableMapOf<String, MutableMap<String, MutableList<String>>>();
|
||||||
|
private val urlMap = mutableMapOf<String, String>();
|
||||||
|
private val headerMap = mutableMapOf<String, Map<String, String>>();
|
||||||
|
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
|
@ -38,21 +38,13 @@ object ProxyServer {
|
||||||
};
|
};
|
||||||
httpServer?.addRoutes("/proxy") { req, response ->
|
httpServer?.addRoutes("/proxy") { req, response ->
|
||||||
run {
|
run {
|
||||||
var url = req.queryParams["url"];
|
val key = req.queryParams["key"];
|
||||||
val headers = req.queryParams["headers"];
|
val url = urlMap[key]
|
||||||
SpiderDebug.log("url: $url")
|
val header = headerMap[key]
|
||||||
SpiderDebug.log("headers: $headers")
|
|
||||||
url = String(
|
if (url != null && header != null) {
|
||||||
org.apache.commons.codec.binary.Base64().decode(url),
|
proxyAsync(url, header, req, response)
|
||||||
Charset.forName("UTF-8")
|
}
|
||||||
)
|
|
||||||
val header: Map<String, String> = Gson().fromJson<Map<String, String>>(
|
|
||||||
String(
|
|
||||||
org.apache.commons.codec.binary.Base64().decode(headers),
|
|
||||||
Charset.forName("UTF-8")
|
|
||||||
), MutableMap::class.java
|
|
||||||
)
|
|
||||||
proxyAsync(url, header, req, response)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httpServer?.start()
|
httpServer?.start()
|
||||||
|
|
@ -197,7 +189,7 @@ object ProxyServer {
|
||||||
return start to end
|
return start to end
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getInfo(
|
private fun getInfo(
|
||||||
url: String?, headers: Map<String, String>
|
url: String?, headers: Map<String, String>
|
||||||
): MutableMap<String, MutableList<String>> {
|
): MutableMap<String, MutableList<String>> {
|
||||||
val newHeaders: MutableMap<String, String> = java.util.HashMap(headers)
|
val newHeaders: MutableMap<String, String> = java.util.HashMap(headers)
|
||||||
|
|
@ -226,14 +218,13 @@ object ProxyServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildProxyUrl(url: String, headers: Map<String, String>): String {
|
fun buildProxyUrl(url: String, headers: Map<String, String>): String {
|
||||||
val urlBase64 = org.apache.commons.codec.binary.Base64()
|
urlMap.clear()
|
||||||
.encodeToString(url.toByteArray(Charset.defaultCharset()))
|
headerMap.clear()
|
||||||
val headerBase64 = org.apache.commons.codec.binary.Base64().encodeToString(
|
val key = Util.MD5(url)
|
||||||
Json.toJson(headers).toByteArray(
|
urlMap[key] = url
|
||||||
Charset.defaultCharset()
|
headerMap[key] = headers
|
||||||
)
|
|
||||||
)
|
return "http://127.0.0.1:$port/proxy?key=$key"
|
||||||
return "http://127.0.0.1:$port/proxy?url=$urlBase64&headers=$headerBase64"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
89689d186862de9fb12508bfe3ac4689
|
14d3c420f76ba891e74f8a858bce6586
|
||||||
|
|
|
||||||
|
|
@ -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": [
|
"lives": [
|
||||||
{
|
{
|
||||||
"name": "电视直播",
|
"name": "电视直播",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue