搜书大师 v23.2版本的 MD5 值为:5ee433f6456b6278bd6e80a5d44df55e
以下内容为反编译后的 SourceModel.java 源代码,内容仅作参考
package com.flyersoft.source.manager;
import com.bykv.vk.openvk.preload.falconx.statistic.StatisticData;
import com.flyersoft.source.base.IHttpGetApi;
import com.flyersoft.source.bean.BookSource;
import com.flyersoft.source.bean.source3.BookInfoRule;
import com.flyersoft.source.bean.source3.BookSource3;
import com.flyersoft.source.bean.source3.ContentRule;
import com.flyersoft.source.bean.source3.ExploreRule;
import com.flyersoft.source.bean.source3.SearchRule;
import com.flyersoft.source.bean.source3.TocRule;
import com.flyersoft.source.manager.analyzeRule.AnalyzeHeaders;
import com.flyersoft.source.utils.JsonUtils;
import com.flyersoft.source.utils.NetworkUtils;
import com.flyersoft.source.utils.RxUtils;
import com.flyersoft.source.utils.StringUtils;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.Predicate;
import com.lygame.aaa.h1;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.functions.Function;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Marker;
import retrofit2.Response;
public class SourceModel extends BaseModel {
public class UrlOption {
String body;
String charset;
String headers;
String method;
String webView;
UrlOption() {
}
public String getBody() {
return this.body;
}
public String getCharset() {
return this.charset;
}
public String getHeaders() {
return this.headers;
}
public String getMethod() {
return this.method;
}
public String getWebView() {
return this.webView;
}
public void setBody(String body) {
this.body = body;
}
public void setCharset(String charset) {
this.charset = charset;
}
public void setHeaders(String headers) {
this.headers = headers;
}
public void setMethod(String method) {
this.method = method;
}
public void setWebView(String webView) {
this.webView = webView;
}
}
public static BookSource convertSource(String jsonItem) {
String jsonString;
String jsonString2;
String jsonString3;
String jsonString4;
String jsonString5;
if (jsonItem.isEmpty()) {
return null;
}
try {
BookSource3 bookSource3 = (BookSource3) JsonUtils.gsonToObject(jsonItem, BookSource3.class);
if ((bookSource3 == null || bookSource3.getRuleToc() == null) && !bookSource3.getBookSourceType().equals(StatisticData.ERROR_CODE_NOT_FOUND)) {
BookSource bookSource = (BookSource) JsonUtils.gsonToObject(jsonItem, BookSource.class);
if (!bookSource.getFlyersoft()) {
bookSource.setFrom(0);
}
return bookSource;
}
BookSource bookSource2 = new BookSource();
bookSource2.setFrom(1);
bookSource2.setBookSourceUrl(bookSource3.getBookSourceUrl());
bookSource2.setBookSourceName(bookSource3.getBookSourceName());
bookSource2.setBookSourceGroup(bookSource3.getBookSourceGroup());
bookSource2.setLoginUrl(bookSource3.getLoginUrl());
bookSource2.setRuleBookUrlPattern(bookSource3.getBookUrlPattern());
bookSource2.setSerialNumber(Integer.parseInt(bookSource3.getCustomOrder() == null ? "0" : bookSource3.getCustomOrder()));
bookSource2.setHttpUserAgent(bookSource3.getHeader());
bookSource2.setRuleSearchUrl(bookSource3.getSearchUrl());
bookSource2.setRuleFindUrl(bookSource3.getExploreUrl());
bookSource2.setBookSourceType(bookSource3.getBookSourceType() + "");
bookSource2.setEnable(bookSource3.isEnabled());
if (bookSource3.getRuleSearch() instanceof String) {
jsonString = JsonPath.parse(bookSource3.getRuleSearch().toString()).jsonString();
} else {
jsonString = JsonPath.parse(JsonUtils.objectToJson(bookSource3.getRuleSearch())).jsonString();
}
SearchRule searchRule = (SearchRule) JsonUtils.gsonToObject(jsonString, SearchRule.class);
bookSource2.setRuleSearchList(searchRule.getBookList());
bookSource2.setRuleSearchName(searchRule.getName());
bookSource2.setRuleSearchAuthor(searchRule.getAuthor());
bookSource2.setRuleSearchIntroduce(searchRule.getIntro());
bookSource2.setRuleSearchKind(searchRule.getKind());
bookSource2.setRuleSearchNoteUrl(searchRule.getBookUrl());
bookSource2.setRuleSearchCoverUrl(searchRule.getCoverUrl());
bookSource2.setRuleSearchLastChapter(searchRule.getLastChapter());
bookSource2.setRuleSearchUpdateTime(searchRule.getUpdateTime());
bookSource2.setRuleSearchWordCount(searchRule.getWordCount());
if (bookSource3.getRuleExplore() != null) {
if (bookSource3.getRuleExplore() instanceof String) {
jsonString5 = JsonPath.parse(bookSource3.getRuleExplore().toString()).jsonString();
} else {
jsonString5 = JsonPath.parse(JsonUtils.objectToJson(bookSource3.getRuleExplore())).jsonString();
}
ExploreRule exploreRule = (ExploreRule) JsonUtils.gsonToObject(jsonString5, ExploreRule.class);
bookSource2.setRuleFindList(exploreRule.getBookList());
bookSource2.setRuleFindName(exploreRule.getName());
bookSource2.setRuleFindAuthor(exploreRule.getAuthor());
bookSource2.setRuleFindIntroduce(exploreRule.getIntro());
bookSource2.setRuleFindKind(exploreRule.getKind());
bookSource2.setRuleFindNoteUrl(exploreRule.getBookUrl());
bookSource2.setRuleFindCoverUrl(exploreRule.getCoverUrl());
bookSource2.setRuleFindLastChapter(exploreRule.getLastChapter());
}
if (bookSource3.getRuleBookInfo() != null) {
if (bookSource3.getRuleBookInfo() instanceof String) {
jsonString4 = JsonPath.parse(bookSource3.getRuleBookInfo().toString()).jsonString();
} else {
jsonString4 = JsonPath.parse(JsonUtils.objectToJson(bookSource3.getRuleBookInfo())).jsonString();
}
BookInfoRule bookInfoRule = (BookInfoRule) JsonUtils.gsonToObject(jsonString4, BookInfoRule.class);
bookSource2.setRuleBookInfoInit(bookInfoRule.getInit());
bookSource2.setRuleBookName(bookInfoRule.getName());
bookSource2.setRuleBookAuthor(bookInfoRule.getAuthor());
bookSource2.setRuleIntroduce(bookInfoRule.getIntro());
bookSource2.setRuleBookKind(bookInfoRule.getKind());
bookSource2.setRuleCoverUrl(bookInfoRule.getCoverUrl());
bookSource2.setRuleBookLastChapter(bookInfoRule.getLastChapter());
bookSource2.setRuleChapterUrl(bookInfoRule.getTocUrl());
bookSource2.setRuleBookUpdateTime(bookInfoRule.getUpdateTime());
bookSource2.setRuleBookWordCount(bookInfoRule.getWordCount());
}
if (bookSource3.getRuleToc() != null) {
if (bookSource3.getRuleToc() instanceof String) {
jsonString3 = JsonPath.parse(bookSource3.getRuleToc().toString()).jsonString();
} else {
jsonString3 = JsonPath.parse(JsonUtils.objectToJson(bookSource3.getRuleToc())).jsonString();
}
TocRule tocRule = (TocRule) JsonUtils.gsonToObject(jsonString3, TocRule.class);
bookSource2.setRuleChapterList(tocRule.getChapterList());
bookSource2.setRuleChapterName(tocRule.getChapterName());
bookSource2.setRuleContentUrl(tocRule.getChapterUrl());
bookSource2.setRuleChapterUrlNext(tocRule.getNextTocUrl());
bookSource2.setRuleChapterUpdateTime(tocRule.getUpdateTime());
bookSource2.setIsVip(tocRule.getIsVip());
}
if (bookSource3.getRuleContent() != null) {
if (bookSource3.getRuleContent() instanceof String) {
jsonString2 = JsonPath.parse(bookSource3.getRuleContent().toString()).jsonString();
} else {
jsonString2 = JsonPath.parse(JsonUtils.objectToJson(bookSource3.getRuleContent())).jsonString();
}
ContentRule contentRule = (ContentRule) JsonUtils.gsonToObject(jsonString2, ContentRule.class);
bookSource2.setRuleBookContent(contentRule.getContent());
bookSource2.setRuleContentUrlNext(contentRule.getNextContentUrl());
bookSource2.setRuleBookContentSourceRegex(contentRule.getSourceRegex());
bookSource2.setRuleBookContentWebJs(contentRule.getWebJs());
bookSource2.setRuleBookContentReplaceRegex(contentRule.getReplaceRegex());
}
return bookSource2;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Observable<List<BookSource>> importBookSourceFromJson(final String json) {
return Observable.create(new ObservableOnSubscribe<List<BookSource>>() {
@Override
public void subscribe(ObservableEmitter<List<BookSource>> e) throws Exception {
ArrayList arrayList = new ArrayList();
new ArrayList();
String trim = json.trim();
if (StringUtils.isJsonObject(trim)) {
List list = (List) JsonPath.parse(trim).read("$.sourceUrls", new Predicate[0]);
if (list == null || list.size() < 1) {
BookSource convertSource = SourceModel.convertSource(trim);
if (convertSource != null) {
arrayList.add(convertSource);
e.onNext(arrayList);
e.onComplete();
return;
}
} else {
e.onNext(arrayList);
e.onComplete();
}
} else if (StringUtils.isJsonArray(json)) {
Iterator it = ((List) JsonPath.using(Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build()).parse(json).read("$", List.class, new Predicate[0])).iterator();
while (it.hasNext()) {
BookSource convertSource2 = SourceModel.convertSource(JsonPath.parse((Map) it.next()).jsonString());
if (convertSource2 != null) {
arrayList.add(convertSource2);
}
}
e.onNext(arrayList);
e.onComplete();
return;
}
e.onError(new Throwable("格式不对"));
}
});
}
public static Observable<List<BookSource>> importSource(String string) {
if (StringUtils.isTrimEmpty(string)) {
return null;
}
if (NetworkUtils.isIPv4Address(string)) {
string = String.format("http://%s:65501", string);
}
if (StringUtils.isJsonType(string)) {
return importBookSourceFromJson(string.trim()).compose(new ObservableTransformer<List<BookSource>, List<BookSource>>() {
@Override
public ObservableSource<List<BookSource>> apply(Observable<List<BookSource>> upstream) {
return RxUtils.toSimpleSingle(upstream);
}
});
}
if (NetworkUtils.isUrl(string)) {
return ((IHttpGetApi) BaseModel.getInstance().getRetrofitString(StringUtils.getBaseUrl(string), "utf-8").create(IHttpGetApi.class)).get(string, AnalyzeHeaders.getMap(null)).flatMap(new Function<Response<String>, ObservableSource<List<BookSource>>>() {
@Override
public ObservableSource<List<BookSource>> apply(Response<String> stringResponse) throws Exception {
return SourceModel.importBookSourceFromJson(stringResponse.body());
}
}).map(new Function<List<BookSource>, List<BookSource>>() {
@Override
public List<BookSource> apply(List<BookSource> bookSources) throws Exception {
for (BookSource bookSource : bookSources) {
bookSource.setBookSourceName(SourceModel.keepOnlyFilenameChars(bookSource.getBookSourceName()));
}
return bookSources;
}
}).compose(new ObservableTransformer<List<BookSource>, List<BookSource>>() {
@Override
public ObservableSource<List<BookSource>> apply(Observable<List<BookSource>> upstream) {
return RxUtils.toSimpleSingle(upstream);
}
});
}
return Observable.error(new Throwable("不是Json或Url格式"));
}
private static BookSource importSourceUrls(String url) {
return null;
}
public static String keepOnlyFilenameChars(String str) {
try {
return Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]").matcher(str).replaceAll("").trim().replaceAll("\n", "").replaceAll("#", "");
} catch (Exception unused) {
return str;
}
}
private static String toNewRule(String newRule) {
boolean z;
String str;
boolean z2;
if (newRule == null) {
return "";
}
if (newRule.startsWith("-")) {
str = newRule.substring(1);
z = true;
} else {
z = false;
str = newRule;
}
if (str.startsWith(Marker.ANY_NON_NULL_MARKER)) {
str = str.substring(1);
z2 = true;
} else {
z2 = false;
}
if (!StringUtils.startWithIgnoreCase(str, "@CSS:") && !StringUtils.startWithIgnoreCase(str, "@XPath:") && !str.startsWith("//") && !str.startsWith("##") && !str.startsWith(":") && !StringUtils.containWithIgnoreCase(str, "@js:") && !StringUtils.containWithIgnoreCase(str, "<js>")) {
if (str.contains("##")) {
str = newRule.replace("##", "#");
}
if (str.contains("||")) {
if (str.contains("#")) {
String[] split = str.split("#");
if (split[0].contains("||")) {
str = split[0].replace("||", "|");
for (int i = 1; i < split.length; i++) {
str = str + "#" + split[i];
}
}
} else {
str = str.replace("||", "|");
}
}
if (str.contains("&&")) {
str = str.replace("&&", h1.b);
}
}
if (z2) {
str = Marker.ANY_NON_NULL_MARKER + str;
}
if (!z) {
return str;
}
return "-" + str;
}
public static String toNewUrl(String oldUrl) {
if (oldUrl == null) {
return "";
}
if (StringUtils.startWithIgnoreCase(oldUrl, "<js>")) {
return oldUrl.replace("={{key}}", "=searchKey").replace("={{page}}", "=searchPage");
}
Matcher matcher = NetworkUtils.pagePattern.matcher(oldUrl);
while (matcher.find()) {
String group = matcher.group();
if (StringUtils.isNotEmpty(group)) {
oldUrl = oldUrl.replace(group, "");
}
}
String[] split = oldUrl.split(",[^\\{]*", 2);
String str = split[0];
UrlOption urlOption = null;
if (split.length > 1 && StringUtils.isNotEmpty(split[1])) {
urlOption = (UrlOption) JsonUtils.gsonToObject(split[1], UrlOption.class);
}
String replace = str.replace("{{key}}", "searchKey").replace("{{page}}", "searchPage").replace("{{page+1}}", "searchPage+1").replace("{{page-1}}", "searchPage-1");
if (urlOption == null) {
return replace;
}
if (urlOption.getBody() != null && !urlOption.getBody().isEmpty()) {
replace = replace + "@" + urlOption.getBody().replace("{{key}}", "searchKey").replace("{{page}}", "searchPage").replace("{{page+1}}", "searchPage+1").replace("{{page-1}}", "searchPage-1");
}
if (urlOption.getHeaders() != null && !urlOption.getHeaders().isEmpty()) {
String headers = urlOption.getHeaders();
StringBuilder sb = new StringBuilder();
sb.append("@Header:");
sb.append(headers.startsWith("{") ? "" : "{");
sb.append(headers);
sb.append(headers.endsWith("}") ? "" : "}");
sb.append(replace);
replace = sb.toString();
}
if (urlOption.getCharset() == null || urlOption.getCharset().isEmpty()) {
return replace;
}
return replace + "|char=" + urlOption.getCharset();
}
private static String toNewUrls(String oldUrls) {
if (oldUrls == null) {
return "";
}
String[] split = oldUrls.split("(&&|\r?\n)+");
StringBuilder sb = new StringBuilder();
for (String str : split) {
String newUrl = toNewUrl(str);
if (StringUtils.isNotEmpty(newUrl)) {
sb.append(newUrl);
sb.append("\n");
}
}
return sb.toString();
}
private static String uaToHeader(String ua) {
return (ua == null || ua.isEmpty()) ? "" : ua;
}
}