61 lines
1.7 KiB
Java
61 lines
1.7 KiB
Java
package com.github.catvod.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 {
|
|
|
|
private static Method method;
|
|
private static int port;
|
|
|
|
public static Object[] proxy(Map<String, String> params) throws Exception {
|
|
switch (params.get("do")) {
|
|
case "ck":
|
|
return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream("ok".getBytes("UTF-8"))};
|
|
case "bili":
|
|
return Bili.proxy(params);
|
|
case "webdav":
|
|
return WebDAV.vod(params);
|
|
case "local":
|
|
return Local.proxy(params);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void init() {
|
|
try {
|
|
method = Class.forName("com.github.catvod.Proxy").getMethod("getUrl", boolean.class);
|
|
} catch (Throwable e) {
|
|
findPort();
|
|
}
|
|
}
|
|
|
|
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() {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|