diff --git a/app/build.gradle b/app/build.gradle index 066910f4..41540995 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,6 +47,6 @@ dependencies { implementation 'cn.wanghaomiao:JsoupXpath:2.5.1' implementation 'org.nanohttpd:nanohttpd:2.3.1' implementation 'com.google.zxing:core:3.3.0' - //implementation 'com.orhanobut:logger:2.2.0' + implementation 'com.orhanobut:logger:2.2.0' implementation 'org.jsoup:jsoup:1.15.3' } \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 4c7831de..4e9d28ac 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -32,6 +32,9 @@ -keep class okio.** { *; } -keep class okhttp3.** { *; } +# Logger +-keep class com.orhanobut.logger.** { *; } + # QuickJS -keep class com.whl.quickjs.** { *; } diff --git a/app/src/main/java/com/github/catvod/debug/MainActivity.java b/app/src/main/java/com/github/catvod/debug/MainActivity.java index 0a6b1e34..d3a91916 100644 --- a/app/src/main/java/com/github/catvod/debug/MainActivity.java +++ b/app/src/main/java/com/github/catvod/debug/MainActivity.java @@ -2,24 +2,102 @@ package com.github.catvod.debug; import android.app.Activity; import android.os.Bundle; +import android.widget.Button; import com.github.catvod.R; +import com.github.catvod.crawler.Spider; import com.github.catvod.spider.Init; +import com.github.catvod.spider.Yingshiche; +import com.orhanobut.logger.AndroidLogAdapter; +import com.orhanobut.logger.Logger; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class MainActivity extends Activity { + private ExecutorService executor; + private Spider spider; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - //Logger.addLogAdapter(new AndroidLogAdapter()); - Init.init(getApplicationContext()); - new Thread(() -> { - try { + Button homeContent = findViewById(R.id.homeContent); + Button homeVideoContent = findViewById(R.id.homeVideoContent); + Button categoryContent = findViewById(R.id.categoryContent); + Button detailContent = findViewById(R.id.detailContent); + Button playerContent = findViewById(R.id.playerContent); + Button searchContent = findViewById(R.id.searchContent); + homeContent.setOnClickListener(view -> executor.execute(this::homeContent)); + homeVideoContent.setOnClickListener(view -> executor.execute(this::homeVideoContent)); + categoryContent.setOnClickListener(view -> executor.execute(this::categoryContent)); + detailContent.setOnClickListener(view -> executor.execute(this::detailContent)); + playerContent.setOnClickListener(view -> executor.execute(this::playerContent)); + searchContent.setOnClickListener(view -> executor.execute(this::searchContent)); + Logger.addLogAdapter(new AndroidLogAdapter()); + executor = Executors.newCachedThreadPool(); + executor.execute(this::initSpider); + } - } catch (Exception e) { - e.printStackTrace(); - } - }).start(); + private void initSpider() { + try { + Init.init(getApplicationContext()); + spider = new Yingshiche(); + spider.init(this, "{}"); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public void homeContent() { + try { + Logger.t("homeContent").d(spider.homeContent(true)); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public void homeVideoContent() { + try { + Logger.t("homeVideoContent").d(spider.homeVideoContent()); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public void categoryContent() { + try { + Logger.t("categoryContent").d(spider.categoryContent("tid", "1", true, new HashMap<>())); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public void detailContent() { + try { + Logger.t("detailContent").d(spider.detailContent(Arrays.asList("/voddetail/5553.html"))); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public void playerContent() { + try { + Logger.t("playerContent").d(spider.playerContent("轉存原畫", "kahf2rw5Uuk+652f55f6943ee2f75d8e4fa590b4ec65fd007f8c", new ArrayList<>())); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public void searchContent() { + try { + Logger.t("searchContent").d(spider.searchContent("我的人间烟火", false)); + } catch (Throwable e) { + e.printStackTrace(); + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 222fd5a2..4f9aeb89 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,7 +1,61 @@ - + android:fillViewport="true"> - \ No newline at end of file + + +