适配第三方书源

pull/5/head
fengyuecanzhu 4 years ago
parent cf8f5b797f
commit db31cf2500
  1. 2
      app/build.gradle
  2. 2
      app/src/main/java/xyz/fycz/myreader/application/App.java
  3. 1
      app/src/main/java/xyz/fycz/myreader/common/APPCONST.java
  4. 4
      app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSource3Bean.java
  5. 7
      app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSourceBean.java
  6. 100
      app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java
  7. 39
      app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java
  8. 14
      app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/FindRule.java
  9. 96
      app/src/main/java/xyz/fycz/myreader/model/analyzeRule/AnalyzeRule.java
  10. 2
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BaseAnalyzer.java
  11. 89
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java
  12. 2
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/JsonPathAnalyzer.java
  13. 2
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/MatcherAnalyzer.java
  14. 8
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/ThirdAnalyzer.java
  15. 2
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/XpathAnalyzer.java
  16. 2
      app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java
  17. 1
      app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java
  18. 4
      app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java
  19. 2
      app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java
  20. 16
      app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java
  21. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java
  22. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java
  23. 9
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookSourceHolder.java
  24. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookStoreBookHolder.java
  25. 3
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/LocalSourceHolder.java
  26. 12
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SearchBookHolder.java
  27. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SourceExchangeHolder.java
  28. 2
      app/src/main/java/xyz/fycz/myreader/ui/dialog/ReplaceDialog.java
  29. 7
      app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java
  30. 3
      app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalSourceFragment.java
  31. 41
      app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java
  32. 6
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java
  33. 4
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseSourceCrawler.java
  34. 7
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/JsonPathCrawler.java
  35. 4
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/MatcherCrawler.java
  36. 2
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/XpathCrawler.java
  37. 1
      app/src/main/res/values/strings.xml
  38. 12
      app/src/test/java/Test.java

@ -208,7 +208,7 @@ dependencies {
} }
greendao { greendao {
schemaVersion 24 schemaVersion 26
daoPackage 'xyz.fycz.myreader.greendao.gen' daoPackage 'xyz.fycz.myreader.greendao.gen'
// targetGenDir 'src/main/java' // targetGenDir 'src/main/java'
} }

@ -48,7 +48,7 @@ import xyz.fycz.myreader.R;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.common.URLCONST; import xyz.fycz.myreader.common.URLCONST;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.ui.activity.MainActivity; import xyz.fycz.myreader.ui.activity.MainActivity;
import xyz.fycz.myreader.ui.dialog.APPDownloadTip; import xyz.fycz.myreader.ui.dialog.APPDownloadTip;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;

@ -44,6 +44,7 @@ public class APPCONST {
public static final String MATCHER = "Matcher"; public static final String MATCHER = "Matcher";
public static final String XPATH = "Xpath"; public static final String XPATH = "Xpath";
public static final String JSON_PATH = "JsonPath"; public static final String JSON_PATH = "JsonPath";
public static final String THIRD_SOURCE = "ThirdSource";
public static final String BOOK = "book"; public static final String BOOK = "book";
public static final String TITLE = "title"; public static final String TITLE = "title";

@ -263,4 +263,8 @@ public class BookSource3Bean {
userAgent // httpUserAgent userAgent // httpUserAgent
); );
} }
public String getBookSourceComment() {
return bookSourceComment;
}
} }

@ -22,19 +22,14 @@ import static android.text.TextUtils.isEmpty;
* Created by GKF on 2017/12/14. * Created by GKF on 2017/12/14.
* 书源信息 * 书源信息
*/ */
@Entity
public class BookSourceBean implements Cloneable { public class BookSourceBean implements Cloneable {
@Id
private String bookSourceUrl; private String bookSourceUrl;
private String bookSourceName; private String bookSourceName;
private String bookSourceGroup; private String bookSourceGroup;
private String bookSourceType; private String bookSourceType;
private String loginUrl; private String loginUrl;
private Long lastUpdateTime; private Long lastUpdateTime;
@OrderBy
private int serialNumber; private int serialNumber;
@OrderBy
@NotNull
private int weight = 0; private int weight = 0;
private boolean enable; private boolean enable;
//发现规则 //发现规则
@ -78,10 +73,8 @@ public class BookSourceBean implements Cloneable {
private String ruleBookContentReplace; private String ruleBookContentReplace;
private String httpUserAgent; private String httpUserAgent;
@Transient
private transient ArrayList<String> groupList; private transient ArrayList<String> groupList;
@Generated(hash = 243497779)
public BookSourceBean(String bookSourceUrl, String bookSourceName, String bookSourceGroup, String bookSourceType, String loginUrl, Long lastUpdateTime, int serialNumber, int weight, boolean enable, String ruleFindUrl, String ruleFindList, public BookSourceBean(String bookSourceUrl, String bookSourceName, String bookSourceGroup, String bookSourceType, String loginUrl, Long lastUpdateTime, int serialNumber, int weight, boolean enable, String ruleFindUrl, String ruleFindList,
String ruleFindName, String ruleFindAuthor, String ruleFindKind, String ruleFindIntroduce, String ruleFindLastChapter, String ruleFindCoverUrl, String ruleFindNoteUrl, String ruleSearchUrl, String ruleSearchList, String ruleFindName, String ruleFindAuthor, String ruleFindKind, String ruleFindIntroduce, String ruleFindLastChapter, String ruleFindCoverUrl, String ruleFindNoteUrl, String ruleSearchUrl, String ruleSearchList,
String ruleSearchName, String ruleSearchAuthor, String ruleSearchKind, String ruleSearchIntroduce, String ruleSearchLastChapter, String ruleSearchCoverUrl, String ruleSearchNoteUrl, String ruleBookUrlPattern, String ruleSearchName, String ruleSearchAuthor, String ruleSearchKind, String ruleSearchIntroduce, String ruleSearchLastChapter, String ruleSearchCoverUrl, String ruleSearchNoteUrl, String ruleBookUrlPattern,

@ -0,0 +1,100 @@
package xyz.fycz.myreader.entity.thirdsource;
import java.util.ArrayList;
import java.util.List;
import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.entity.rule.ContentRule;
import xyz.fycz.myreader.greendao.entity.rule.FindRule;
import xyz.fycz.myreader.greendao.entity.rule.InfoRule;
import xyz.fycz.myreader.greendao.entity.rule.SearchRule;
import xyz.fycz.myreader.greendao.entity.rule.TocRule;
/**
* @author fengyue
* @date 2021/5/14 9:24
*/
public class ThirdSourceUtil {
public static BookSource source2ToSource(BookSourceBean bean) {
BookSource bookSource = new BookSource();
bookSource.setSourceUrl(bean.getBookSourceUrl());
bookSource.setSourceName(bean.getBookSourceName());
bookSource.setSourceGroup(bean.getBookSourceGroup());
bookSource.setSourceType(APPCONST.THIRD_SOURCE);
bookSource.setLastUpdateTime(bean.getLastUpdateTime());
bookSource.setOrderNum(bean.getSerialNumber());
bookSource.setWeight(bean.getWeight());
bookSource.setEnable(bean.getEnable());
SearchRule searchRule = new SearchRule();
searchRule.setSearchUrl(bean.getRuleSearchUrl());
searchRule.setList(bean.getRuleSearchList());
searchRule.setName(bean.getRuleSearchName());
searchRule.setAuthor(bean.getRuleSearchAuthor());
searchRule.setType(bean.getRuleSearchKind());
searchRule.setDesc(bean.getRuleSearchIntroduce());
searchRule.setLastChapter(bean.getRuleSearchLastChapter());
searchRule.setImgUrl(bean.getRuleSearchCoverUrl());
searchRule.setTocUrl(bean.getRuleSearchNoteUrl());
searchRule.setRelatedWithInfo(true);
bookSource.setSearchRule(searchRule);
InfoRule infoRule = new InfoRule();
infoRule.setName(bean.getRuleBookName());
infoRule.setAuthor(bean.getRuleBookAuthor());
infoRule.setType(bean.getRuleBookKind());
infoRule.setDesc(bean.getRuleIntroduce());
infoRule.setLastChapter(bean.getRuleBookLastChapter());
infoRule.setImgUrl(bean.getRuleCoverUrl());
infoRule.setTocUrl(bean.getRuleChapterUrl());
bookSource.setInfoRule(infoRule);
TocRule tocRule = new TocRule();
tocRule.setChapterList(bean.getRuleChapterList());
tocRule.setChapterName(bean.getRuleChapterName());
tocRule.setChapterUrl(bean.getRuleContentUrl());
tocRule.setTocUrlNext(bean.getRuleChapterUrlNext());
bookSource.setTocRule(tocRule);
ContentRule contentRule = new ContentRule();
contentRule.setContent(bean.getRuleBookContent());
contentRule.setContentUrlNext(bean.getRuleContentUrlNext());
bookSource.setContentRule(contentRule);
FindRule findRule = new FindRule();
findRule.setUrl(bean.getRuleFindUrl());
findRule.setBookList(bean.getRuleFindList());
findRule.setName(bean.getRuleFindName());
findRule.setAuthor(bean.getRuleFindAuthor());
findRule.setType(bean.getRuleFindKind());
findRule.setDesc(bean.getRuleFindIntroduce());
findRule.setLastChapter(bean.getRuleFindLastChapter());
findRule.setImgUrl(bean.getRuleFindCoverUrl());
findRule.setTocUrl(bean.getRuleFindNoteUrl());
bookSource.setFindRule(findRule);
return bookSource;
}
public static BookSource source3ToSource(BookSource3Bean bean) {
BookSource bookSource = source2ToSource(bean.toBookSourceBean());
bookSource.setSourceComment(bean.getBookSourceComment());
return bookSource;
}
public static List<BookSource> source2sToSources(List<BookSourceBean> beans){
List<BookSource> sources = new ArrayList<>();
for (BookSourceBean bean : beans){
sources.add(source2ToSource(bean));
}
return sources;
}
public static List<BookSource> source3sToSources(List<BookSource3Bean> beans){
List<BookSource> sources = new ArrayList<>();
for (BookSource3Bean bean : beans){
sources.add(source3ToSource(bean));
}
return sources;
}
}

@ -1,6 +1,8 @@
package xyz.fycz.myreader.greendao.entity; package xyz.fycz.myreader.greendao.entity;
import android.text.TextUtils;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -13,8 +15,12 @@ import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import static xyz.fycz.myreader.common.APPCONST.MAP_STRING;
/** /**
* *
* Created by fengyue on 2020/08/23. * Created by fengyue on 2020/08/23.
@ -70,13 +76,18 @@ public class Book implements Serializable {
private long lastReadTime; private long lastReadTime;
@Generated(hash = 1963023743) private String variable;
@Transient
private Map<String, String> variableMap;
@Generated(hash = 1284526947)
public Book(String id, String name, String chapterUrl, String infoUrl, String imgUrl, String desc, public Book(String id, String name, String chapterUrl, String infoUrl, String imgUrl, String desc,
String author, String type, String updateDate, String wordCount, String status, String author, String type, String updateDate, String wordCount, String status,
String newestChapterId, String newestChapterTitle, String newestChapterUrl, String historyChapterId, String newestChapterId, String newestChapterTitle, String newestChapterUrl, String historyChapterId,
int histtoryChapterNum, int sortCode, int noReadNum, int chapterTotalNum, int lastReadPosition, int histtoryChapterNum, int sortCode, int noReadNum, int chapterTotalNum, int lastReadPosition,
String source, boolean isCloseUpdate, boolean isDownLoadAll, String groupId, int groupSort, String source, boolean isCloseUpdate, boolean isDownLoadAll, String groupId, int groupSort,
String tag, Boolean replaceEnable, long lastReadTime) { String tag, Boolean replaceEnable, long lastReadTime, String variable) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.chapterUrl = chapterUrl; this.chapterUrl = chapterUrl;
@ -105,6 +116,7 @@ public class Book implements Serializable {
this.tag = tag; this.tag = tag;
this.replaceEnable = replaceEnable; this.replaceEnable = replaceEnable;
this.lastReadTime = lastReadTime; this.lastReadTime = lastReadTime;
this.variable = variable;
} }
@ -340,5 +352,28 @@ public class Book implements Serializable {
public void setStatus(String status) { public void setStatus(String status) {
this.status = status; this.status = status;
} }
public void putVariable(String key, String value) {
if (variableMap == null) {
variableMap = new HashMap<>();
}
variableMap.put(key, value);
variable = new Gson().toJson(variableMap);
}
public Map<String, String> getVariableMap() {
if (variableMap == null && !TextUtils.isEmpty(variable)) {
variableMap = new Gson().fromJson(variable, MAP_STRING);
}
return variableMap;
}
public String getVariable() {
return this.variable;
}
public void setVariable(String variable) {
this.variable = variable;
}
} }

@ -14,6 +14,7 @@ import static xyz.fycz.myreader.util.utils.StringUtils.stringEquals;
* @date 2021/2/10 8:57 * @date 2021/2/10 8:57
*/ */
public class FindRule implements Parcelable { public class FindRule implements Parcelable {
private String url;
private String bookList; private String bookList;
private String name; private String name;
private String author; private String author;
@ -30,6 +31,7 @@ public class FindRule implements Parcelable {
} }
protected FindRule(Parcel in) { protected FindRule(Parcel in) {
url = in.readString();
bookList = in.readString(); bookList = in.readString();
name = in.readString(); name = in.readString();
author = in.readString(); author = in.readString();
@ -45,6 +47,7 @@ public class FindRule implements Parcelable {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(url);
dest.writeString(bookList); dest.writeString(bookList);
dest.writeString(name); dest.writeString(name);
dest.writeString(author); dest.writeString(author);
@ -75,6 +78,14 @@ public class FindRule implements Parcelable {
} }
}; };
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getBookList() { public String getBookList() {
return bookList; return bookList;
} }
@ -169,7 +180,8 @@ public class FindRule implements Parcelable {
if (o == null) o = new FindRule(); if (o == null) o = new FindRule();
if (getClass() != o.getClass()) return false; if (getClass() != o.getClass()) return false;
FindRule findRule = (FindRule) o; FindRule findRule = (FindRule) o;
return stringEquals(bookList, findRule.bookList) && return stringEquals(url, findRule.url) &&
stringEquals(bookList, findRule.bookList) &&
stringEquals(name, findRule.name) && stringEquals(name, findRule.name) &&
stringEquals(author, findRule.author) && stringEquals(author, findRule.author) &&
stringEquals(type, findRule.type) && stringEquals(type, findRule.type) &&

@ -1,8 +1,34 @@
package xyz.fycz.myreader.model.analyzeRule; package xyz.fycz.myreader.model.analyzeRule;
import android.annotation.SuppressLint;
import androidx.annotation.Keep; import androidx.annotation.Keep;
import com.google.gson.Gson;
import org.jsoup.nodes.Entities;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.script.SimpleBindings;
import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.help.JsExtensions; import xyz.fycz.myreader.util.help.JsExtensions;
import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.StringUtils;
import static xyz.fycz.myreader.common.APPCONST.EXP_PATTERN;
import static xyz.fycz.myreader.common.APPCONST.JS_PATTERN;
import static xyz.fycz.myreader.common.APPCONST.MAP_STRING;
import static xyz.fycz.myreader.common.APPCONST.SCRIPT_ENGINE;
import static xyz.fycz.myreader.util.StringHelper.isEmpty;
import static xyz.fycz.myreader.util.utils.NetworkUtils.headerPattern;
/** /**
@ -12,10 +38,10 @@ import xyz.fycz.myreader.util.help.JsExtensions;
@Keep @Keep
@SuppressWarnings({"unused", "WeakerAccess"}) @SuppressWarnings({"unused", "WeakerAccess"})
public class AnalyzeRule implements JsExtensions { public class AnalyzeRule implements JsExtensions {
/*private static final Pattern putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE); private static final Pattern putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE);
private static final Pattern getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE); private static final Pattern getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE);
private BaseBookBean book; private Book book;
private Object object; private Object object;
private Boolean isJSON = false; private Boolean isJSON = false;
private String baseUrl = null; private String baseUrl = null;
@ -28,11 +54,11 @@ public class AnalyzeRule implements JsExtensions {
private boolean objectChangedJS = false; private boolean objectChangedJS = false;
private boolean objectChangedJP = false; private boolean objectChangedJP = false;
public AnalyzeRule(BaseBookBean bookBean) { public AnalyzeRule(Book bookBean) {
book = bookBean; book = bookBean;
} }
public void setBook(BaseBookBean book) { public void setBook(Book book) {
this.book = book; this.book = book;
} }
@ -61,9 +87,9 @@ public class AnalyzeRule implements JsExtensions {
return this.baseUrl; return this.baseUrl;
} }
*//** /**
* 获取XPath解析类 * 获取XPath解析类
*//* */
private AnalyzeByXPath getAnalyzeByXPath(Object o) { private AnalyzeByXPath getAnalyzeByXPath(Object o) {
if (o != object) { if (o != object) {
return new AnalyzeByXPath().parse(o); return new AnalyzeByXPath().parse(o);
@ -80,9 +106,9 @@ public class AnalyzeRule implements JsExtensions {
return analyzeByXPath; return analyzeByXPath;
} }
*//** /**
* 获取JSOUP解析类 * 获取JSOUP解析类
*//* */
private AnalyzeByJSoup getAnalyzeByJSoup(Object o) { private AnalyzeByJSoup getAnalyzeByJSoup(Object o) {
if (o != object) { if (o != object) {
return new AnalyzeByJSoup().parse(o); return new AnalyzeByJSoup().parse(o);
@ -99,9 +125,9 @@ public class AnalyzeRule implements JsExtensions {
return analyzeByJSoup; return analyzeByJSoup;
} }
*//** /**
* 获取JSON解析类 * 获取JSON解析类
*//* */
private AnalyzeByJSonPath getAnalyzeByJSonPath(Object o) { private AnalyzeByJSonPath getAnalyzeByJSonPath(Object o) {
if (o != object) { if (o != object) {
return new AnalyzeByJSonPath().parse(o); return new AnalyzeByJSonPath().parse(o);
@ -118,9 +144,9 @@ public class AnalyzeRule implements JsExtensions {
return analyzeByJSonPath; return analyzeByJSonPath;
} }
*//** /**
* 获取文本列表 * 获取文本列表
*//* */
public List<String> getStringList(String rule) throws Exception { public List<String> getStringList(String rule) throws Exception {
return getStringList(rule, false); return getStringList(rule, false);
} }
@ -180,9 +206,9 @@ public class AnalyzeRule implements JsExtensions {
return (List<String>) result; return (List<String>) result;
} }
*//** /**
* 获取文本 * 获取文本
*//* */
public String getString(String rule) throws Exception { public String getString(String rule) throws Exception {
return getString(rule, false); return getString(rule, false);
} }
@ -235,9 +261,9 @@ public class AnalyzeRule implements JsExtensions {
} }
} }
*//** /**
* 获取Element * 获取Element
*//* */
public Object getElement(String ruleStr) throws Exception { public Object getElement(String ruleStr) throws Exception {
List<SourceRule> ruleList = splitSourceRule(ruleStr); List<SourceRule> ruleList = splitSourceRule(ruleStr);
Object result = object; Object result = object;
@ -262,9 +288,9 @@ public class AnalyzeRule implements JsExtensions {
return result; return result;
} }
*//** /**
* 获取列表 * 获取列表
*//* */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Object> getElements(String ruleStr) throws Exception { public List<Object> getElements(String ruleStr) throws Exception {
List<SourceRule> ruleList = splitSourceRule(ruleStr); List<SourceRule> ruleList = splitSourceRule(ruleStr);
@ -294,9 +320,9 @@ public class AnalyzeRule implements JsExtensions {
return (List<Object>) result; return (List<Object>) result;
} }
*//** /**
* 保存变量 * 保存变量
*//* */
private void putRule(Map<String, String> map) throws Exception { private void putRule(Map<String, String> map) throws Exception {
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map.Entry<String, String> entry : map.entrySet()) {
if (book != null) { if (book != null) {
@ -305,9 +331,9 @@ public class AnalyzeRule implements JsExtensions {
} }
} }
*//** /**
* 分离并执行put规则 * 分离并执行put规则
*//* */
private String splitPutRule(String ruleStr) throws Exception { private String splitPutRule(String ruleStr) throws Exception {
Matcher putMatcher = putPattern.matcher(ruleStr); Matcher putMatcher = putPattern.matcher(ruleStr);
while (putMatcher.find()) { while (putMatcher.find()) {
@ -318,9 +344,9 @@ public class AnalyzeRule implements JsExtensions {
return ruleStr; return ruleStr;
} }
*//** /**
* 替换@get * 替换@get
*//* */
public String replaceGet(String ruleStr) { public String replaceGet(String ruleStr) {
Matcher getMatcher = getPattern.matcher(ruleStr); Matcher getMatcher = getPattern.matcher(ruleStr);
while (getMatcher.find()) { while (getMatcher.find()) {
@ -334,9 +360,9 @@ public class AnalyzeRule implements JsExtensions {
return ruleStr; return ruleStr;
} }
*//** /**
* 正则替换 * 正则替换
*//* */
private String replaceRegex(String result, SourceRule rule) { private String replaceRegex(String result, SourceRule rule) {
if (!isEmpty(rule.replaceRegex)) { if (!isEmpty(rule.replaceRegex)) {
if (rule.replaceFirst) { if (rule.replaceFirst) {
@ -354,9 +380,9 @@ public class AnalyzeRule implements JsExtensions {
return result; return result;
} }
*//** /**
* 替换JS * 替换JS
*//* */
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
private String replaceJs(String ruleStr) throws Exception { private String replaceJs(String ruleStr) throws Exception {
if (ruleStr.contains("{{") && ruleStr.contains("}}")) { if (ruleStr.contains("{{") && ruleStr.contains("}}")) {
@ -379,9 +405,9 @@ public class AnalyzeRule implements JsExtensions {
return ruleStr; return ruleStr;
} }
*//** /**
* 分解规则生成规则列表 * 分解规则生成规则列表
*//* */
public List<SourceRule> splitSourceRule(String ruleStr) throws Exception { public List<SourceRule> splitSourceRule(String ruleStr) throws Exception {
List<SourceRule> ruleList = new ArrayList<>(); List<SourceRule> ruleList = new ArrayList<>();
if (isEmpty(ruleStr)) return ruleList; if (isEmpty(ruleStr)) return ruleList;
@ -429,9 +455,9 @@ public class AnalyzeRule implements JsExtensions {
return ruleList; return ruleList;
} }
*//** /**
* 规则类 * 规则类
*//* */
public static class SourceRule { public static class SourceRule {
Mode mode; Mode mode;
String rule; String rule;
@ -501,15 +527,15 @@ public class AnalyzeRule implements JsExtensions {
return book.getVariableMap().get(key); return book.getVariableMap().get(key);
} }
*//** /**
* 执行JS * 执行JS
*//* */
private Object evalJS(String jsStr, Object result) throws Exception { private Object evalJS(String jsStr, Object result) throws Exception {
SimpleBindings bindings = new SimpleBindings(); SimpleBindings bindings = new SimpleBindings();
bindings.put("java", this); bindings.put("java", this);
bindings.put("result", result); bindings.put("result", result);
bindings.put("baseUrl", baseUrl); bindings.put("baseUrl", baseUrl);
return SCRIPT_ENGINE.eval(jsStr, bindings); return SCRIPT_ENGINE.eval(jsStr, bindings);
}*/ }
} }

@ -1,4 +1,4 @@
package xyz.fycz.myreader.model.source; package xyz.fycz.myreader.model.sourceAnalyzer;
import android.util.Log; import android.util.Log;

@ -1,4 +1,4 @@
package xyz.fycz.myreader.model.source; package xyz.fycz.myreader.model.sourceAnalyzer;
import android.database.Cursor; import android.database.Cursor;
import android.text.TextUtils; import android.text.TextUtils;
@ -6,7 +6,6 @@ import android.util.Log;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -19,16 +18,18 @@ import io.reactivex.annotations.NonNull;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.base.observer.MyObserver;
import xyz.fycz.myreader.entity.thirdsource.BookSource3Bean;
import xyz.fycz.myreader.entity.thirdsource.BookSourceBean;
import xyz.fycz.myreader.entity.thirdsource.ThirdSourceUtil;
import xyz.fycz.myreader.enums.LocalBookSource; import xyz.fycz.myreader.enums.LocalBookSource;
import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.GreenDaoManager;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.greendao.gen.BookSourceDao;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt;
import xyz.fycz.myreader.util.utils.GsonUtils; import xyz.fycz.myreader.util.utils.GsonUtils;
import xyz.fycz.myreader.util.utils.MeUtils;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.OkHttpUtils;
import xyz.fycz.myreader.util.utils.RxUtils; import xyz.fycz.myreader.util.utils.RxUtils;
@ -37,6 +38,7 @@ import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil;
public class BookSourceManager { public class BookSourceManager {
public static final int SOURCE_LENGTH = 500;
public static List<BookSource> getEnabledBookSource() { public static List<BookSource> getEnabledBookSource() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder()
@ -326,11 +328,10 @@ public class BookSourceManager {
} }
private static Observable<List<BookSource>> importBookSourceFromJson(String json) { private static Observable<List<BookSource>> importBookSourceFromJson(String json) {
return Observable.create(e -> { return Observable.create(emitter -> {
List<BookSource> successImportSources = new ArrayList<>(); List<BookSource> successImportSources = new ArrayList<>();
if (StringUtils.isJsonArray(json)) { List<BookSource> bookSources = importSources(json);
try { if (bookSources != null) {
List<BookSource> bookSources = GsonUtils.parseJArray(json, BookSource.class);
for (BookSource bookSource : bookSources) { for (BookSource bookSource : bookSources) {
if (bookSource.containsGroup("删除")) { if (bookSource.containsGroup("删除")) {
GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder()
@ -342,27 +343,66 @@ public class BookSourceManager {
} }
} }
} }
e.onNext(successImportSources); emitter.onNext(successImportSources);
e.onComplete(); emitter.onComplete();
return; return;
} catch (Exception ignored) {
} }
emitter.onError(new Throwable("格式不对"));
});
} }
if (StringUtils.isJsonObject(json)) {
private static List<BookSource> importSources(String json) {
if (StringUtils.isJsonArray(json)) {
try { try {
BookSource bookSource = GsonUtils.parseJObject(json, BookSource.class); List<BookSource> sources = GsonUtils.parseJArray(json, BookSource.class);
if (addBookSource(bookSource)) String sourcesJson = GsonExtensionsKt.getGSON().toJson(sources);
successImportSources.add(bookSource); if (sources.size() > 0 && sourcesJson.length() > sources.size() * SOURCE_LENGTH){
e.onNext(successImportSources); return sources;
e.onComplete();
return;
} catch (Exception ignored) {
} }
List<BookSourceBean> source2s = GsonUtils.parseJArray(json, BookSourceBean.class);
String source2sJson = GsonExtensionsKt.getGSON().toJson(source2s);
if (source2s.size() > 0 && source2sJson.length() > source2s.size() * SOURCE_LENGTH){
return ThirdSourceUtil.source2sToSources(source2s);
} }
e.onError(new Throwable("格式不对")); List<BookSource3Bean> source3s = GsonUtils.parseJArray(json, BookSource3Bean.class);
}); String source3sJson = GsonExtensionsKt.getGSON().toJson(source3s);
if (source3s.size() > 0 && source3sJson.length() > source3s.size() * SOURCE_LENGTH){
return ThirdSourceUtil.source3sToSources(source3s);
}
}catch (Exception e){
e.printStackTrace();
}
} else if (StringUtils.isJsonObject(json)) {
try {
List<BookSource> sources = new ArrayList<>();
BookSource source = GsonUtils.parseJObject(json, BookSource.class);
String sourceJson = GsonExtensionsKt.getGSON().toJson(source);
if (!StringHelper.isEmpty(sourceJson) && sourceJson.length() > SOURCE_LENGTH){
sources.add(source);
return sources;
} }
BookSourceBean source2 = GsonUtils.parseJObject(json, BookSourceBean.class);
String source2Json = GsonExtensionsKt.getGSON().toJson(source2);
if (!StringHelper.isEmpty(source2Json) && source2Json.length() > SOURCE_LENGTH){
sources.add(ThirdSourceUtil.source2ToSource(source2));
return sources;
}
BookSource3Bean source3 = GsonUtils.parseJObject(json, BookSource3Bean.class);
String source3Json = GsonExtensionsKt.getGSON().toJson(source3);
if (!StringHelper.isEmpty(source3Json) && source3Json.length() > SOURCE_LENGTH){
sources.add(ThirdSourceUtil.source3ToSource(source3));
return sources;
}
}catch (Exception e){
e.printStackTrace();
}
}
return null;
}
public static void initDefaultSources() { public static void initDefaultSources() {
Log.d("initDefaultSources", "execute"); Log.d("initDefaultSources", "execute");
@ -383,11 +423,6 @@ public class BookSourceManager {
String referenceSources = FileUtils.readAssertFile(App.getmContext(), String referenceSources = FileUtils.readAssertFile(App.getmContext(),
"ReferenceSources.json"); "ReferenceSources.json");
Observable<List<BookSource>> observable = BookSourceManager.importBookSourceFromJson(referenceSources); Observable<List<BookSource>> observable = BookSourceManager.importBookSourceFromJson(referenceSources);
observable.subscribe(new MyObserver<List<BookSource>>() { observable.subscribe();
@Override
public void onNext(@NonNull List<BookSource> sources) {
}
});
} }
} }

@ -1,4 +1,4 @@
package xyz.fycz.myreader.model.source; package xyz.fycz.myreader.model.sourceAnalyzer;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;

@ -1,4 +1,4 @@
package xyz.fycz.myreader.model.source; package xyz.fycz.myreader.model.sourceAnalyzer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

@ -0,0 +1,8 @@
package xyz.fycz.myreader.model.sourceAnalyzer;
/**
* @author fengyue
* @date 2021/5/14 9:13
*/
public class ThirdAnalyzer {
}

@ -1,4 +1,4 @@
package xyz.fycz.myreader.model.source; package xyz.fycz.myreader.model.sourceAnalyzer;
import org.seimicrawler.xpath.JXDocument; import org.seimicrawler.xpath.JXDocument;
import org.seimicrawler.xpath.JXNode; import org.seimicrawler.xpath.JXNode;

@ -58,7 +58,7 @@ import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.greendao.service.ChapterService; import xyz.fycz.myreader.greendao.service.ChapterService;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.ui.adapter.BookTagAdapter; import xyz.fycz.myreader.ui.adapter.BookTagAdapter;
import xyz.fycz.myreader.ui.adapter.DetailCatalogAdapter; import xyz.fycz.myreader.ui.adapter.DetailCatalogAdapter;
import xyz.fycz.myreader.ui.dialog.BookGroupDialog; import xyz.fycz.myreader.ui.dialog.BookGroupDialog;

@ -15,7 +15,6 @@ import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityBookInfoEditBinding; import xyz.fycz.myreader.databinding.ActivityBookInfoEditBinding;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.UriFileUtil; import xyz.fycz.myreader.util.UriFileUtil;

@ -20,21 +20,17 @@ import androidx.fragment.app.FragmentTransaction;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.BaseFragment;
import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityMoreSettingBinding; import xyz.fycz.myreader.databinding.ActivityMoreSettingBinding;
import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.entity.Setting;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog; import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;

@ -49,7 +49,7 @@ import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.service.SearchHistoryService; import xyz.fycz.myreader.greendao.service.SearchHistoryService;
import xyz.fycz.myreader.model.SearchEngine; import xyz.fycz.myreader.model.SearchEngine;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.ui.adapter.SearchBookAdapter; import xyz.fycz.myreader.ui.adapter.SearchBookAdapter;
import xyz.fycz.myreader.ui.adapter.SearchHistoryAdapter; import xyz.fycz.myreader.ui.adapter.SearchHistoryAdapter;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;

@ -5,8 +5,6 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
@ -18,7 +16,6 @@ import java.net.URLEncoder;
import java.util.List; import java.util.List;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.SysManager;
import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivitySourceEditBinding; import xyz.fycz.myreader.databinding.ActivitySourceEditBinding;
@ -26,8 +23,7 @@ import xyz.fycz.myreader.entity.sourcedebug.DebugEntity;
import xyz.fycz.myreader.entity.sourceedit.EditEntity; import xyz.fycz.myreader.entity.sourceedit.EditEntity;
import xyz.fycz.myreader.entity.sourceedit.EditEntityUtil; import xyz.fycz.myreader.entity.sourceedit.EditEntityUtil;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.entity.rule.SearchRule; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.adapter.SourceEditAdapter; import xyz.fycz.myreader.ui.adapter.SourceEditAdapter;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
@ -118,6 +114,9 @@ public class SourceEditActivity extends BaseActivity {
case APPCONST.JSON_PATH: case APPCONST.JSON_PATH:
sourceType = 2; sourceType = 2;
break; break;
case APPCONST.THIRD_SOURCE:
sourceType = 3;
break;
} }
binding.sSourceType.setSelection(sourceType); binding.sSourceType.setSelection(sourceType);
} }
@ -193,7 +192,7 @@ public class SourceEditActivity extends BaseActivity {
e.printStackTrace(); e.printStackTrace();
} }
debugEntity.setUrl(source.getSearchRule().getSearchUrl().replace("{key}", text)); debugEntity.setUrl(source.getSearchRule().getSearchUrl().replace("{key}", text));
}else { } else {
debugEntity.setUrl(text); debugEntity.setUrl(text);
} }
}, (dialog, which) -> { }, (dialog, which) -> {
@ -255,7 +254,7 @@ public class SourceEditActivity extends BaseActivity {
BookSource source = entityUtil.getSource(this.source, sourceEntities); BookSource source = entityUtil.getSource(this.source, sourceEntities);
source.setEnable(binding.cbSourceEnable.isChecked()); source.setEnable(binding.cbSourceEnable.isChecked());
String sourceType = APPCONST.MATCHER; String sourceType = APPCONST.MATCHER;
switch (binding.sSourceType.getSelectedItemPosition()){ switch (binding.sSourceType.getSelectedItemPosition()) {
case 0: case 0:
sourceType = APPCONST.MATCHER; sourceType = APPCONST.MATCHER;
break; break;
@ -265,6 +264,9 @@ public class SourceEditActivity extends BaseActivity {
case 2: case 2:
sourceType = APPCONST.JSON_PATH; sourceType = APPCONST.JSON_PATH;
break; break;
case 3:
sourceType = APPCONST.THIRD_SOURCE;
break;
} }
source.setSourceType(sourceType); source.setSourceType(sourceType);
source.setSearchRule(entityUtil.getSearchRule(searchEntities)); source.setSearchRule(entityUtil.getSearchRule(searchEntities));

@ -16,8 +16,6 @@ import java.util.ArrayList;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
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.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.activity.ReadActivity;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;

@ -14,8 +14,6 @@ import java.util.ArrayList;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
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.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.activity.ReadActivity;
import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.DialogCreator;
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog;

@ -8,13 +8,9 @@ import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe; import io.reactivex.ObservableOnSubscribe;
@ -26,13 +22,10 @@ import xyz.fycz.myreader.base.adapter.ViewHolderImpl;
import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.base.observer.MyObserver;
import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.ReplaceRuleManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.activity.SourceEditActivity; import xyz.fycz.myreader.ui.activity.SourceEditActivity;
import xyz.fycz.myreader.ui.adapter.BookSourceAdapter; import xyz.fycz.myreader.ui.adapter.BookSourceAdapter;
import xyz.fycz.myreader.ui.dialog.ReplaceDialog;
import xyz.fycz.myreader.util.ShareUtils; import xyz.fycz.myreader.util.ShareUtils;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;

@ -9,7 +9,7 @@ import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.base.adapter.ViewHolderImpl;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil;

@ -1,7 +1,6 @@
package xyz.fycz.myreader.ui.adapter.holder; package xyz.fycz.myreader.ui.adapter.holder;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import java.util.HashMap; import java.util.HashMap;
@ -10,8 +9,6 @@ import xyz.fycz.myreader.R;
import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.base.adapter.ViewHolderImpl;
import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.GreenDaoManager;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.source.BookSourceManager;
import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
/** /**

@ -2,16 +2,9 @@ package xyz.fycz.myreader.ui.adapter.holder;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout; import com.zhy.view.flowlayout.TagFlowLayout;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,17 +13,14 @@ import java.util.List;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.base.adapter.ViewHolderImpl;
import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.entity.SearchBookBean; import xyz.fycz.myreader.entity.SearchBookBean;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.SearchEngine; import xyz.fycz.myreader.model.SearchEngine;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.ui.activity.BookDetailedActivity;
import xyz.fycz.myreader.ui.adapter.BookTagAdapter; import xyz.fycz.myreader.ui.adapter.BookTagAdapter;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.KeyWordUtils; import xyz.fycz.myreader.util.utils.KeyWordUtils;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil;

@ -6,7 +6,7 @@ import android.widget.TextView;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.base.adapter.ViewHolderImpl;
import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
/** /**
* @author fengyue * @author fengyue

@ -26,7 +26,7 @@ import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.BookService;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.model.ReplaceRuleManager; import xyz.fycz.myreader.model.ReplaceRuleManager;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;

@ -8,7 +8,6 @@ import android.text.TextUtils;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,7 +23,6 @@ import java.util.List;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull; import io.reactivex.annotations.NonNull;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
@ -34,11 +32,9 @@ import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.FragmentImportSourceBinding; import xyz.fycz.myreader.databinding.FragmentImportSourceBinding;
import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.GreenDaoManager;
import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.greendao.gen.BookSourceDao;
import xyz.fycz.myreader.model.ReplaceRuleManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.model.source.BookSourceManager;
import xyz.fycz.myreader.ui.activity.BookSourceActivity; import xyz.fycz.myreader.ui.activity.BookSourceActivity;
import xyz.fycz.myreader.ui.activity.SourceEditActivity; import xyz.fycz.myreader.ui.activity.SourceEditActivity;
import xyz.fycz.myreader.ui.adapter.BookSourceAdapter; import xyz.fycz.myreader.ui.adapter.BookSourceAdapter;
@ -46,7 +42,6 @@ import xyz.fycz.myreader.ui.adapter.helper.ItemTouchCallback;
import xyz.fycz.myreader.ui.dialog.DialogCreator; 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.ShareUtils; import xyz.fycz.myreader.util.ShareUtils;
import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.ClipBoardUtil; import xyz.fycz.myreader.util.utils.ClipBoardUtil;
import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.FileUtils;

@ -10,7 +10,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import java.util.List; import java.util.List;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull; import io.reactivex.annotations.NonNull;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
@ -19,7 +18,7 @@ import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.databinding.FragmentLocalSourceBinding; import xyz.fycz.myreader.databinding.FragmentLocalSourceBinding;
import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.GreenDaoManager;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.ui.activity.BookSourceActivity; import xyz.fycz.myreader.ui.activity.BookSourceActivity;
import xyz.fycz.myreader.ui.adapter.LocalSourceAdapter; import xyz.fycz.myreader.ui.adapter.LocalSourceAdapter;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;

@ -9,7 +9,12 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import xyz.fycz.myreader.util.help.SSLSocketClient; import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import xyz.fycz.myreader.model.analyzeRule.AnalyzeUrl;
import xyz.fycz.myreader.util.utils.OkHttpUtils;
import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.util.utils.StringUtils;
@SuppressWarnings({"unused", "WeakerAccess"}) @SuppressWarnings({"unused", "WeakerAccess"})
@ -18,16 +23,40 @@ public interface JsExtensions {
/** /**
* js实现跨域访问,不能删 * js实现跨域访问,不能删
*/ */
/*default String ajax(String urlStr) { default String ajax(String urlStr) {
try { try {
AnalyzeUrl analyzeUrl = new AnalyzeUrl(urlStr); AnalyzeUrl analyzeUrl = new AnalyzeUrl(urlStr);
Response<String> response = BaseModelImpl.getInstance().getResponseO(analyzeUrl) String res = Observable.create((ObservableOnSubscribe<String>) emitter -> {
.blockingFirst(); StringBuilder sb = new StringBuilder();
return response.body(); for (String key : analyzeUrl.getQueryMap().keySet()){
sb.append(key).append("=").append(analyzeUrl.getQueryMap().get(key));
sb.append("&");
}
sb.deleteCharAt(sb.lastIndexOf("&"));
String body = sb.toString();
switch (analyzeUrl.getUrlMode()){
case GET:
String url = analyzeUrl.getUrl() + "?" + body;
emitter.onNext(OkHttpUtils.getHtml(url, analyzeUrl.getCharCode(),
analyzeUrl.getHeaderMap()));
break;
case POST:
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody requestBody = RequestBody.create(mediaType, body);
emitter.onNext(OkHttpUtils.getHtml(analyzeUrl.getUrl(), requestBody,
analyzeUrl.getCharCode(), analyzeUrl.getHeaderMap()));
break;
default:
emitter.onNext(OkHttpUtils.getHtml(analyzeUrl.getUrl(),
analyzeUrl.getCharCode(), analyzeUrl.getHeaderMap()));
break;
}
}).blockingFirst();
return res;
} catch (Exception e) { } catch (Exception e) {
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
}*/ }
/** /**
* js实现解码,不能删 * js实现解码,不能删

@ -7,7 +7,7 @@ import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.enums.LocalBookSource; import xyz.fycz.myreader.enums.LocalBookSource;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler;
@ -26,6 +26,7 @@ import java.util.ResourceBundle;
import static xyz.fycz.myreader.common.APPCONST.JSON_PATH; import static xyz.fycz.myreader.common.APPCONST.JSON_PATH;
import static xyz.fycz.myreader.common.APPCONST.MATCHER; import static xyz.fycz.myreader.common.APPCONST.MATCHER;
import static xyz.fycz.myreader.common.APPCONST.THIRD_SOURCE;
import static xyz.fycz.myreader.common.APPCONST.XPATH; import static xyz.fycz.myreader.common.APPCONST.XPATH;
/** /**
@ -192,6 +193,9 @@ public class ReadCrawlerUtil {
case JSON_PATH: case JSON_PATH:
crawler = new JsonPathCrawler(source); crawler = new JsonPathCrawler(source);
break; break;
case THIRD_SOURCE:
crawler = new JsonPathCrawler(source);
break;
} }
if (source.getSearchRule().isRelatedWithInfo() || isInfo) { if (source.getSearchRule().isRelatedWithInfo() || isInfo) {
return crawler; return crawler;

@ -20,8 +20,8 @@ import xyz.fycz.myreader.greendao.entity.rule.InfoRule;
import xyz.fycz.myreader.greendao.entity.rule.SearchRule; import xyz.fycz.myreader.greendao.entity.rule.SearchRule;
import xyz.fycz.myreader.greendao.entity.rule.TocRule; import xyz.fycz.myreader.greendao.entity.rule.TocRule;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.model.source.BaseAnalyzer; import xyz.fycz.myreader.model.sourceAnalyzer.BaseAnalyzer;
import xyz.fycz.myreader.model.source.MatcherAnalyzer; import xyz.fycz.myreader.model.sourceAnalyzer.MatcherAnalyzer;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.OkHttpUtils;

@ -3,7 +3,6 @@ package xyz.fycz.myreader.webapi.crawler.source;
import com.jayway.jsonpath.ReadContext; import com.jayway.jsonpath.ReadContext;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -12,13 +11,9 @@ 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.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.entity.rule.SearchRule; import xyz.fycz.myreader.greendao.entity.rule.SearchRule;
import xyz.fycz.myreader.greendao.entity.rule.TocRule;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.model.source.JsonPathAnalyzer; import xyz.fycz.myreader.model.sourceAnalyzer.JsonPathAnalyzer;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.OkHttpUtils;
import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler;
/** /**

@ -1,6 +1,5 @@
package xyz.fycz.myreader.webapi.crawler.source; package xyz.fycz.myreader.webapi.crawler.source;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -9,10 +8,9 @@ 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.entity.rule.BookSource;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.model.source.MatcherAnalyzer; import xyz.fycz.myreader.model.sourceAnalyzer.MatcherAnalyzer;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.OkHttpUtils;
import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler;
/** /**

@ -11,7 +11,7 @@ import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.entity.rule.SearchRule; import xyz.fycz.myreader.greendao.entity.rule.SearchRule;
import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap;
import xyz.fycz.myreader.model.source.XpathAnalyzer; import xyz.fycz.myreader.model.sourceAnalyzer.XpathAnalyzer;
import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.StringHelper;
import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler;

@ -563,5 +563,6 @@
<item>Matcher</item> <item>Matcher</item>
<item>Xpath</item> <item>Xpath</item>
<item>JsonPath</item> <item>JsonPath</item>
<item>第三方</item>
</string-array> </string-array>
</resources> </resources>

@ -1,9 +1,3 @@
import android.util.Log;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.FileDownloadLargeFileListener;
import com.liulishuo.filedownloader.FileDownloader;
import org.seimicrawler.xpath.JXDocument; import org.seimicrawler.xpath.JXDocument;
import java.io.File; import java.io.File;
@ -13,14 +7,10 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import xyz.fycz.myreader.ai.MatrixUtil; import xyz.fycz.myreader.ai.MatrixUtil;
import xyz.fycz.myreader.model.source.BaseAnalyzer; import xyz.fycz.myreader.model.sourceAnalyzer.BaseAnalyzer;
import xyz.fycz.myreader.model.source.MatcherAnalyzer;
import xyz.fycz.myreader.ui.dialog.UpdateDialog;
import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.GsonExtensionsKt;
import xyz.fycz.myreader.util.utils.GsonUtils; import xyz.fycz.myreader.util.utils.GsonUtils;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.webapi.CommonApi;
/** /**
* @author fengyue * @author fengyue

Loading…
Cancel
Save