From 168329bc14b78098aa668ef7a1b93e419bc9c88e Mon Sep 17 00:00:00 2001 From: gzlinz2 <107169210+gzlinz2@users.noreply.github.com> Date: Thu, 27 Oct 2022 17:28:11 +0800 Subject: [PATCH] Add files via upload --- .../java/com/github/catvod/spider/Init.java | 17 +++++ .../java/com/github/catvod/spider/Proxy.java | 64 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 app/src/main/java/com/github/catvod/spider/Init.java create mode 100644 app/src/main/java/com/github/catvod/spider/Proxy.java diff --git a/app/src/main/java/com/github/catvod/spider/Init.java b/app/src/main/java/com/github/catvod/spider/Init.java new file mode 100644 index 0000000..3337ace --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/Init.java @@ -0,0 +1,17 @@ +package com.github.catvod.spider; + + + + +import android.content.Context; + +import com.github.catvod.crawler.SpiderDebug; +import com.github.catvod.demo.MainActivity; + +public class Init { + + + public static void init(Context context) { + SpiderDebug.log("自定义爬虫代码加载成功!"); + } +} diff --git a/app/src/main/java/com/github/catvod/spider/Proxy.java b/app/src/main/java/com/github/catvod/spider/Proxy.java new file mode 100644 index 0000000..ffb68cf --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/Proxy.java @@ -0,0 +1,64 @@ +package com.github.catvod.spider; + +import android.util.Base64; + +import com.github.catvod.crawler.Spider; +import com.github.catvod.crawler.SpiderDebug; +import com.github.catvod.live.TxtSubscribe; +import com.github.catvod.utils.okhttp.OkHttpUtil; + +import java.io.ByteArrayInputStream; +import java.util.Map; + +public class Proxy extends Spider { + + public static int localPort = -1; + + static void adjustLocalPort() { + if (localPort > 0) + return; + int port = 9978; + while (port < 10000) { + String resp = OkHttpUtil.string("http://127.0.0.1:" + port + "/proxy?do=ck", null); + if (resp.equals("ok")) { + SpiderDebug.log("Found local server port " + port); + localPort = port; + break; + } + port++; + } + } + + public static String localProxyUrl() { + adjustLocalPort(); + return "http://127.0.0.1:" + Proxy.localPort + "/proxy"; + } + + public static Object[] proxy(Map params) { + try { + String what = params.get("do"); + if (what.equals("live")) { + String type = params.get("type"); + if (type.equals("txt")) { + String ext = params.get("ext"); + if (!ext.startsWith("http")) { + ext = new String(Base64.decode(ext, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8"); + } + return TxtSubscribe.load(ext); + } + } else if (what.equals("ck")) { + Object[] result = new Object[3]; + result[0] = 200; + result[1] = "text/plain; charset=utf-8"; + ByteArrayInputStream baos = new ByteArrayInputStream("ok".getBytes("UTF-8")); + result[2] = baos; + return result; + } else if (what.equals("czspp")) { + return Czsapp.loadsub(params.get("url")); + } + } catch (Throwable th) { + } + return null; + } + +} \ No newline at end of file