diff --git a/app/src/main/java/com/github/catvod/spider/Feiyang.java b/app/src/main/java/com/github/catvod/spider/Feiyang.java new file mode 100644 index 00000000..b5b10a28 --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/Feiyang.java @@ -0,0 +1,69 @@ +package com.github.catvod.spider; + +import android.content.Context; +import android.os.SystemClock; + +import com.github.catvod.crawler.Spider; +import com.github.catvod.net.OkHttp; +import com.github.catvod.utils.Path; +import com.github.catvod.utils.Shell; + +import java.io.File; + +public class Feiyang extends Spider { + + private static final String AIO = "allinone-linux-musl"; + private static final String SHELL = "run-allinone.sh"; + private static Thread thread; + private String extend; + + @Override + public void init(Context context, String extend) throws Exception { + this.extend = extend; + } + + @Override + public String liveContent() { + String content; + int retry = 0; + while ((content = OkHttp.string(extend)).isEmpty() && retry++ < 5) SystemClock.sleep(250); + return content; + } + + public static void startAIO() { + writeShell(); + findAIO(Path.tv().listFiles()); + findAIO(Path.download().listFiles()); + } + + private static void findAIO(File[] files) { + if (files == null || thread != null) return; + for (File f : files) { + if (f.getName().equals("allinone") || f.getName().startsWith("allinone-linux")) { + Path.copy(f, new File(Path.files(), AIO)); + thread = new Thread(() -> Shell.exec("nohup " + new File(Path.files(), SHELL).getAbsolutePath() + " &")); + thread.start(); + } + } + } + + private static void writeShell() { + File cache = Path.cache("allinone.cache"); + File shell = new File(Path.files(), SHELL); + File aio = new File(Path.files(), AIO); + String cachePath = cache.getAbsolutePath(); + String shellPath = shell.getAbsolutePath(); + String aioPath = aio.getAbsolutePath(); + String script = "if [ -e " + shellPath + ".kill ]; then\n" + "sh " + shellPath + ".kill;\n" + "killall -9 " + AIO + ";\n" + "sleep 1;\n" + "rm -f " + shellPath + ".kill;\n" + "fi\n" + "echo \"kill -9 $$\" >> " + shellPath + ".kill;\n" + "while(true)\n" + "do\n" + "TMPDIR=" + cachePath + " " + aioPath + " -ipv6=true " + " -port 35345 " + " >/dev/null 2>&1\n" + "pidlist=$(ps -ef|grep " + SHELL + "|grep -v grep|awk '{print $2}')\n" + "selfpid=$$\n" + "for pid in $pidlist\n" + "do\n" + "if [[ $pid != \"$selfpid\" ]] then\n" + "kill -9 $pid\n" + "fi\n" + "done\n" + "killall -9 " + AIO + "\n" + "rm -rf \"" + cachePath + "\"/*\n" + "sleep 5;\n" + "done"; + Path.write(shell, script); + } + + @Override + public void destroy() { + try { + if (thread != null) thread.interrupt(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/com/github/catvod/spider/Init.java b/app/src/main/java/com/github/catvod/spider/Init.java index 865f8704..5a561295 100644 --- a/app/src/main/java/com/github/catvod/spider/Init.java +++ b/app/src/main/java/com/github/catvod/spider/Init.java @@ -42,6 +42,7 @@ public class Init { public static void init(Context context) { get().app = ((Application) context); SpiderDebug.log("自定義爬蟲代碼載入成功!"); + Feiyang.startAIO(); } public static void execute(Runnable runnable) { diff --git a/jar/custom_spider.jar b/jar/custom_spider.jar index 97c2ba67..e121af7c 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 f69bdc50..b2f9a87e 100644 --- a/jar/custom_spider.jar.md5 +++ b/jar/custom_spider.jar.md5 @@ -1 +1 @@ -1594afa59c3a799dfb126c214aced2b7 +b71bc7bc451c71b3d352ce5806328d28