Update proxy

This commit is contained in:
FongMi 2025-04-23 01:55:54 +08:00
parent 8d4920159a
commit 78e08fbc03
4 changed files with 29 additions and 20 deletions

View File

@ -42,6 +42,7 @@ public class Init {
public static void init(Context context) {
get().app = ((Application) context);
SpiderDebug.log("自定義爬蟲代碼載入成功!");
Proxy.init();
}
public static void execute(Runnable runnable) {

View File

@ -1,15 +1,16 @@
package com.github.catvod.spider;
import com.github.catvod.crawler.Spider;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.net.OkHttp;
import java.io.ByteArrayInputStream;
import java.lang.reflect.Method;
import java.util.Map;
public class Proxy extends Spider {
public class Proxy {
private static int port = -1;
private static Method method;
private static int port;
public static Object[] proxy(Map<String, String> params) throws Exception {
switch (params.get("do")) {
@ -26,27 +27,34 @@ public class Proxy extends Spider {
}
}
static void adjustPort() {
if (Proxy.port > 0) return;
int port = 9978;
while (port < 10000) {
String resp = OkHttp.string("http://127.0.0.1:" + port + "/proxy?do=ck", null);
if (resp.equals("ok")) {
SpiderDebug.log("Found local server port " + port);
Proxy.port = port;
break;
}
port++;
public static void init() {
try {
method = Class.forName("com.github.catvod.Proxy").getMethod("getUrl", boolean.class);
} catch (Throwable e) {
findPort();
}
}
public static int getPort() {
adjustPort();
return port;
public static String getUrl(boolean local) {
try {
return (String) method.invoke(null, local);
} catch (Throwable e) {
return "http://127.0.0.1:" + port + "/proxy";
}
}
public static String getUrl() {
adjustPort();
return "http://127.0.0.1:" + port + "/proxy";
return getUrl(true);
}
private static void findPort() {
if (port > 0) return;
for (int p = 8964; p < 9999; p++) {
if ("ok".equals(OkHttp.string("http://127.0.0.1:" + p + "/proxy?do=ck", null))) {
SpiderDebug.log("本地代理端口:" + p);
port = p;
break;
}
}
}
}

Binary file not shown.

View File

@ -1 +1 @@
fd389e3446f23e76f9112a2097d81884
7d41e83085218476c2cd4fc00da14ad8