pull/21/head
fengyuecanzhu 3 years ago
parent eb7b98b429
commit da5c5ecd30
  1. 15
      app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java
  2. 16
      app/src/main/java/xyz/fycz/myreader/model/third3/BaseSource.kt
  3. 29
      app/src/main/java/xyz/fycz/myreader/model/third3/Debug.kt
  4. 1
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt
  5. 3
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt
  6. 8
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt
  7. 29
      app/src/main/java/xyz/fycz/myreader/ui/activity/SourceDebugActivity.java
  8. 12
      app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java
  9. 11
      app/src/main/res/layout/activity_source_debug.xml
  10. 5
      app/src/main/res/menu/menu_source_edit.xml
  11. 2
      app/src/main/res/values/strings.xml

@ -425,14 +425,21 @@ public class BookSource extends BaseSource implements Parcelable, Cloneable {
this.concurrentRate = concurrentRate; this.concurrentRate = concurrentRate;
} }
@Nullable
@Override @Override
public String getHeader() { public String getConcurrentRateKt() {
return sourceHeaders; return concurrentRate;
} }
@Nullable
@Override @Override
public void setHeader(@Nullable String header) { public String getLoginUrlKt() {
this.sourceHeaders = header; return loginUrl;
}
@Override
public String getHeader() {
return sourceHeaders;
} }
@NonNull @NonNull

@ -17,10 +17,16 @@ import javax.script.SimpleBindings
@Suppress("unused") @Suppress("unused")
abstract class BaseSource : JsExtensions { abstract class BaseSource : JsExtensions {
open var concurrentRate: String? = null // 并发率 //var concurrentRate: String? // 并发率
open var loginUrl: String? = null // 登录地址 //var loginUrl: String? // 登录地址
//var loginUi: String? // 登录UI //var loginUi: String? // 登录UI
open var header: String? = null // 请求头 //var header: String? // 请求头
open fun getConcurrentRateKt(): String? = null // 并发率
open fun getLoginUrlKt(): String? = null // 登录地址
open fun getHeader(): String? = null // 请求头
open fun getTag(): String = "" open fun getTag(): String = ""
@ -31,7 +37,7 @@ abstract class BaseSource : JsExtensions {
}*/ }*/
fun getLoginJs(): String? { fun getLoginJs(): String? {
val loginJs = loginUrl val loginJs = getLoginUrlKt()
return when { return when {
loginJs == null -> null loginJs == null -> null
loginJs.startsWith("@js:") -> loginJs.substring(4) loginJs.startsWith("@js:") -> loginJs.substring(4)
@ -52,7 +58,7 @@ abstract class BaseSource : JsExtensions {
*/ */
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply { fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
this[APPCONST.UA_NAME] = APPCONST.DEFAULT_USER_AGENT this[APPCONST.UA_NAME] = APPCONST.DEFAULT_USER_AGENT
header?.let { getHeader()?.let {
GSON.fromJsonObject<Map<String, String>>( GSON.fromJsonObject<Map<String, String>>(
when { when {
it.startsWith("@js:", true) -> it.startsWith("@js:", true) ->

@ -0,0 +1,29 @@
package xyz.fycz.myreader.model.third3
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.*
/**
* @author fengyue
* @date 2022/1/21 10:42
*/
object Debug {
var callback: Callback? = null
@SuppressLint("ConstantLocale")
private val debugTimeFormat = SimpleDateFormat("[hh:mm:ss.SSS]", Locale.getDefault())
fun log(msg: String) {
val time = debugTimeFormat.format(System.currentTimeMillis())
callback?.print("$time $msg")
}
fun log(tag: String, msg: String) {
val time = debugTimeFormat.format(System.currentTimeMillis())
callback?.print("$time $tag$msg")
}
interface Callback {
fun print(msg: String)
}
}

@ -10,7 +10,6 @@ import xyz.fycz.myreader.common.APPCONST.JS_PATTERN_3
import xyz.fycz.myreader.common.APPCONST.SCRIPT_ENGINE import xyz.fycz.myreader.common.APPCONST.SCRIPT_ENGINE
import xyz.fycz.myreader.greendao.entity.Book import xyz.fycz.myreader.greendao.entity.Book
import xyz.fycz.myreader.greendao.entity.Chapter import xyz.fycz.myreader.greendao.entity.Chapter
import xyz.fycz.myreader.greendao.entity.rule.BookSource
import xyz.fycz.myreader.greendao.service.CacheManager import xyz.fycz.myreader.greendao.service.CacheManager
import xyz.fycz.myreader.greendao.service.CookieStore import xyz.fycz.myreader.greendao.service.CookieStore
import xyz.fycz.myreader.model.third3.BaseSource import xyz.fycz.myreader.model.third3.BaseSource

@ -9,7 +9,6 @@ import okhttp3.Response
import xyz.fycz.myreader.common.APPCONST.* import xyz.fycz.myreader.common.APPCONST.*
import xyz.fycz.myreader.greendao.entity.Book import xyz.fycz.myreader.greendao.entity.Book
import xyz.fycz.myreader.greendao.entity.Chapter import xyz.fycz.myreader.greendao.entity.Chapter
import xyz.fycz.myreader.greendao.entity.rule.BookSource
import xyz.fycz.myreader.greendao.service.CacheManager import xyz.fycz.myreader.greendao.service.CacheManager
import xyz.fycz.myreader.greendao.service.CookieStore import xyz.fycz.myreader.greendao.service.CookieStore
import xyz.fycz.myreader.model.third3.BaseSource import xyz.fycz.myreader.model.third3.BaseSource
@ -280,7 +279,7 @@ class AnalyzeUrl(
*/ */
private fun fetchStart(): ConcurrentRecord? { private fun fetchStart(): ConcurrentRecord? {
source ?: return null source ?: return null
val concurrentRate = source.concurrentRate val concurrentRate = source.getConcurrentRateKt()
if (concurrentRate.isNullOrEmpty()) { if (concurrentRate.isNullOrEmpty()) {
return null return null
} }

@ -12,10 +12,10 @@ import org.jsoup.Connection
import org.jsoup.Jsoup import org.jsoup.Jsoup
import xyz.fycz.myreader.application.App import xyz.fycz.myreader.application.App
import xyz.fycz.myreader.common.APPCONST import xyz.fycz.myreader.common.APPCONST
import xyz.fycz.myreader.greendao.entity.rule.BookSource
import xyz.fycz.myreader.greendao.service.CacheManager import xyz.fycz.myreader.greendao.service.CacheManager
import xyz.fycz.myreader.greendao.service.CookieStore import xyz.fycz.myreader.greendao.service.CookieStore
import xyz.fycz.myreader.model.third3.BaseSource import xyz.fycz.myreader.model.third3.BaseSource
import xyz.fycz.myreader.model.third3.Debug
import xyz.fycz.myreader.model.third3.http.* import xyz.fycz.myreader.model.third3.http.*
import xyz.fycz.myreader.util.ZipUtils import xyz.fycz.myreader.util.ZipUtils
import xyz.fycz.myreader.util.utils.* import xyz.fycz.myreader.util.utils.*
@ -484,9 +484,9 @@ interface JsExtensions {
* 输出调试日志 * 输出调试日志
*/ */
fun log(msg: String): String { fun log(msg: String): String {
/*getSource()?.let { getSource()?.let {
Debug.log(it.sourceUrl, msg) Debug.log(it.getKey(), msg)
} ?: Debug.log(msg)*/ } ?: Debug.log(msg)
if (App.isDebug()) { if (App.isDebug()) {
Log.d(TAG + "-" + getSource()?.getKey(), msg) Log.d(TAG + "-" + getSource()?.getKey(), msg)
} }

@ -1,6 +1,7 @@
package xyz.fycz.myreader.ui.activity; package xyz.fycz.myreader.ui.activity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -27,6 +28,7 @@ import okhttp3.RequestBody;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.base.observer.MyObserver;
import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivitySourceDebugBinding; import xyz.fycz.myreader.databinding.ActivitySourceDebugBinding;
import xyz.fycz.myreader.entity.SearchBookBean; import xyz.fycz.myreader.entity.SearchBookBean;
import xyz.fycz.myreader.entity.StrResponse; import xyz.fycz.myreader.entity.StrResponse;
@ -36,7 +38,9 @@ import xyz.fycz.myreader.entity.sourcedebug.DebugEntity;
import xyz.fycz.myreader.entity.sourcedebug.ListResult; import xyz.fycz.myreader.entity.sourcedebug.ListResult;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.mulvalmap.ConMVMap; import xyz.fycz.myreader.model.mulvalmap.ConMVMap;
import xyz.fycz.myreader.model.third3.Debug;
import xyz.fycz.myreader.ui.dialog.LoadingDialog; import xyz.fycz.myreader.ui.dialog.LoadingDialog;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.GsonExtensionsKt;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
@ -63,6 +67,8 @@ public class SourceDebugActivity extends BaseActivity {
private ReadCrawler rc; private ReadCrawler rc;
private Disposable disposable; private Disposable disposable;
private LoadingDialog loadingDialog; private LoadingDialog loadingDialog;
private boolean isThird3;
private StringBuilder logSb;
@Override @Override
protected void bindView() { protected void bindView() {
@ -96,12 +102,20 @@ public class SourceDebugActivity extends BaseActivity {
protected void initData(Bundle savedInstanceState) { protected void initData(Bundle savedInstanceState) {
super.initData(savedInstanceState); super.initData(savedInstanceState);
debugEntity = getIntent().getParcelableExtra("debugEntity"); debugEntity = getIntent().getParcelableExtra("debugEntity");
rc = ReadCrawlerUtil.getReadCrawler(debugEntity.getBookSource(), true); if (debugEntity == null) finish();
BookSource source = debugEntity.getBookSource();
isThird3 = APPCONST.THIRD_3_SOURCE.equals(source.getSourceType());
rc = ReadCrawlerUtil.getReadCrawler(source, true);
loadingDialog = new LoadingDialog(this, "正在请求", () -> { loadingDialog = new LoadingDialog(this, "正在请求", () -> {
if (disposable != null && !disposable.isDisposed()) { if (disposable != null && !disposable.isDisposed()) {
disposable.dispose(); disposable.dispose();
} }
}); });
if (isThird3) {
binding.tabLayout.getTabAt(1).setText(R.string.debug_log);
logSb = new StringBuilder();
Debug.INSTANCE.setCallback(msg -> logSb.append(msg).append("\n"));
}
} }
@Override @Override
@ -112,7 +126,7 @@ public class SourceDebugActivity extends BaseActivity {
debugEntity.getBookSource().getSourceUrl(), debugEntity.getBookSource().getSourceUrl(),
debugEntity.getUrl())); debugEntity.getUrl()));
binding.rvParseResult.setLanguage(Language.JSON); binding.rvParseResult.setLanguage(Language.JSON);
binding.rvSourceCode.setLanguage(Language.HTML); binding.rvSourceCode.setLanguage(Language.AUTO);
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override @Override
public void onTabSelected(TabLayout.Tab tab) { public void onTabSelected(TabLayout.Tab tab) {
@ -142,6 +156,9 @@ public class SourceDebugActivity extends BaseActivity {
if (loadingDialog != null) { if (loadingDialog != null) {
loadingDialog.dismiss(); loadingDialog.dismiss();
} }
if (isThird3) {
Debug.INSTANCE.setCallback(null);
}
super.onDestroy(); super.onDestroy();
} }
@ -196,7 +213,11 @@ public class SourceDebugActivity extends BaseActivity {
@Override @Override
public void onNext(@NonNull Boolean flag) { public void onNext(@NonNull Boolean flag) {
binding.rvParseResult.setCode(debugEntity.getParseResult()).apply(); binding.rvParseResult.setCode(debugEntity.getParseResult()).apply();
if (!isThird3) {
binding.rvSourceCode.setCode(debugEntity.getHtml()).apply(); binding.rvSourceCode.setCode(debugEntity.getHtml()).apply();
} else {
binding.rvSourceCode.setCode(logSb.toString()).apply();
}
loadingDialog.dismiss(); loadingDialog.dismiss();
} }
@ -204,7 +225,11 @@ public class SourceDebugActivity extends BaseActivity {
public void onError(Throwable e) { public void onError(Throwable e) {
binding.rvParseResult.setCode(String.format("{\n\b\b\b\b\"result\": \"error\", \n\b\b\b\b\"msg\": \"%s\"\n}" binding.rvParseResult.setCode(String.format("{\n\b\b\b\b\"result\": \"error\", \n\b\b\b\b\"msg\": \"%s\"\n}"
, e.getLocalizedMessage().replace("\"", "\\\""))).apply(); , e.getLocalizedMessage().replace("\"", "\\\""))).apply();
if (!isThird3) {
binding.rvSourceCode.setCode(debugEntity.getHtml()).apply(); binding.rvSourceCode.setCode(debugEntity.getHtml()).apply();
} else {
binding.rvSourceCode.setCode(logSb.toString()).apply();
}
loadingDialog.dismiss(); loadingDialog.dismiss();
} }
}); });

@ -1,6 +1,9 @@
package xyz.fycz.myreader.ui.activity; package xyz.fycz.myreader.ui.activity;
import android.app.Activity; import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
@ -30,6 +33,7 @@ import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
import xyz.fycz.myreader.util.help.StringHelper; import xyz.fycz.myreader.util.help.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt;
import xyz.fycz.myreader.webapi.crawler.source.MatcherCrawler; import xyz.fycz.myreader.webapi.crawler.source.MatcherCrawler;
/** /**
@ -182,6 +186,14 @@ public class SourceEditActivity extends BaseActivity {
} else { } else {
ToastUtils.showWarring("当前书源没有配置登录地址"); ToastUtils.showWarring("当前书源没有配置登录地址");
} }
} else if (item.getItemId() == R.id.action_copy_source) {
ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
//数据
ClipData mClipData = ClipData.newPlainText("Label",
GsonExtensionsKt.getGSON().toJson(getSource()));
//把数据设置到剪切板上
mClipboardManager.setPrimaryClip(mClipData);
ToastUtils.showSuccess("拷贝成功");
} else if (item.getItemId() == R.id.action_clear_cookie) { } else if (item.getItemId() == R.id.action_clear_cookie) {
DbManager.getDaoSession().getCookieBeanDao().deleteByKey(getSource().getSourceUrl()); DbManager.getDaoSession().getCookieBeanDao().deleteByKey(getSource().getSourceUrl());
ToastUtils.showSuccess("Cookie清除成功"); ToastUtils.showSuccess("Cookie清除成功");

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
@ -19,6 +14,7 @@
android:background="@color/colorForeground" android:background="@color/colorForeground"
android:padding="10dp" android:padding="10dp"
android:textColor="@color/textSecondary" android:textColor="@color/textSecondary"
android:maxLines="6"
android:textSize="13sp" /> android:textSize="13sp" />
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
@ -66,5 +62,4 @@
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView>

@ -32,7 +32,10 @@
android:id="@+id/action_login" android:id="@+id/action_login"
android:title="@string/text_login" android:title="@string/text_login"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_copy_source"
android:title="@string/copy_source"
app:showAsAction="never" />
<item <item
android:id="@+id/action_clear_cookie" android:id="@+id/action_clear_cookie"
android:title="@string/clear_cookie" android:title="@string/clear_cookie"

@ -448,6 +448,7 @@
<string name="share_all">分享所有</string> <string name="share_all">分享所有</string>
<string name="parse_result">解析结果</string> <string name="parse_result">解析结果</string>
<string name="source_code">网页源码</string> <string name="source_code">网页源码</string>
<string name="debug_log">调试日志</string>
<string name="re_request">重新请求</string> <string name="re_request">重新请求</string>
<string name="debug_search">测试搜索配置</string> <string name="debug_search">测试搜索配置</string>
<string name="debug_info">测试书籍详情</string> <string name="debug_info">测试书籍详情</string>
@ -540,6 +541,7 @@
<string name="net_error_10001">没有网络</string> <string name="net_error_10001">没有网络</string>
<string name="net_error_10002">网络连接超时</string> <string name="net_error_10002">网络连接超时</string>
<string name="net_error_10003">数据解析失败</string> <string name="net_error_10003">数据解析失败</string>
<string name="copy_source">拷贝书源</string>
<!--error string end--> <!--error string end-->
<string-array name="reset_screen_time"> <string-array name="reset_screen_time">

Loading…
Cancel
Save