Skip to content

Commit

Permalink
kind 改位String
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Aug 2, 2019
1 parent 6a9952a commit 66abc04
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public Observable<List<BookChapterBean>> analyzeChapterList(final String s, fina
e.onError(new Throwable(MApplication.getInstance().getString(R.string.get_chapter_list_error) + bookShelfBean.getBookInfoBean().getChapterUrl()));
return;
} else {
Debug.printLog(tag, "┌成功获取目录页", analyzeNextUrl);
Debug.printLog(tag, "└" + bookShelfBean.getBookInfoBean().getChapterUrl(), analyzeNextUrl);
Debug.printLog(tag, 1, "┌成功获取目录页", analyzeNextUrl);
Debug.printLog(tag, 1, "└" + bookShelfBean.getBookInfoBean().getChapterUrl(), analyzeNextUrl);
}
bookShelfBean.setTag(tag);
AnalyzeRule analyzer = new AnalyzeRule(bookShelfBean);
Expand Down Expand Up @@ -157,7 +157,7 @@ private void finish(List<BookChapterBean> chapterList, Emitter<List<BookChapterB
LinkedHashSet<BookChapterBean> lh = new LinkedHashSet<>(chapterList);
chapterList = new ArrayList<>(lh);
Collections.reverse(chapterList);
Debug.printLog(tag, "-目录解析完成", analyzeNextUrl);
Debug.printLog(tag, 1, "-目录解析完成", analyzeNextUrl);
emitter.onNext(chapterList);
emitter.onComplete();
}
Expand All @@ -167,23 +167,23 @@ private WebChapterBean analyzeChapterList(String s, String chapterUrl, String ru
List<String> nextUrlList = new ArrayList<>();
analyzer.setContent(s, chapterUrl);
if (!TextUtils.isEmpty(bookSourceBean.getRuleChapterUrlNext()) && analyzeNextUrl) {
Debug.printLog(tag, "┌获取目录下一页网址", printLog);
Debug.printLog(tag, 1, "┌获取目录下一页网址", printLog);
nextUrlList = analyzer.getStringList(bookSourceBean.getRuleChapterUrlNext(), true);
int thisUrlIndex = nextUrlList.indexOf(chapterUrl);
if (thisUrlIndex != -1) {
nextUrlList.remove(thisUrlIndex);
}
Debug.printLog(tag, "└" + nextUrlList.toString(), printLog);
Debug.printLog(tag, 1, "└" + nextUrlList.toString(), printLog);
}

List<BookChapterBean> chapterBeans = new ArrayList<>();
Debug.printLog(tag, "┌解析目录列表", printLog);
Debug.printLog(tag, 1, "┌解析目录列表", printLog);
// 仅使用java正则表达式提取目录列表
if (ruleChapterList.startsWith(":")) {
ruleChapterList = ruleChapterList.substring(1);
regexChapter(s, ruleChapterList.split("&&"), 0, analyzer, chapterBeans);
if (chapterBeans.size() == 0) {
Debug.printLog(tag, "└找到 0 个章节", printLog);
Debug.printLog(tag, 1, "└找到 0 个章节", printLog);
return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList));
}
}
Expand All @@ -192,7 +192,7 @@ else if (ruleChapterList.startsWith("+")) {
ruleChapterList = ruleChapterList.substring(1);
List<Object> collections = analyzer.getElements(ruleChapterList);
if (collections.size() == 0) {
Debug.printLog(tag, "└找到 0 个章节", printLog);
Debug.printLog(tag, 1, "└找到 0 个章节", printLog);
return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList));
}
String nameRule = bookSourceBean.getRuleChapterName();
Expand All @@ -214,7 +214,7 @@ else if (ruleChapterList.startsWith("+")) {
else {
List<Object> collections = analyzer.getElements(ruleChapterList);
if (collections.size() == 0) {
Debug.printLog(tag, "└找到 0 个章节", printLog);
Debug.printLog(tag, 1, "└找到 0 个章节", printLog);
return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList));
}
List<AnalyzeRule.SourceRule> nameRule = analyzer.splitSourceRule(bookSourceBean.getRuleChapterName());
Expand All @@ -224,18 +224,18 @@ else if (ruleChapterList.startsWith("+")) {
addChapter(chapterBeans, analyzer.getString(nameRule), analyzer.getString(linkRule));
}
}
Debug.printLog(tag, "└找到 " + chapterBeans.size() + " 个章节", printLog);
Debug.printLog(tag, 1, "└找到 " + chapterBeans.size() + " 个章节", printLog);
BookChapterBean firstChapter;
if (dx) {
Debug.printLog(tag, "-倒序", printLog);
Debug.printLog(tag, 1, "-倒序", printLog);
firstChapter = chapterBeans.get(chapterBeans.size() - 1);
} else {
firstChapter = chapterBeans.get(0);
}
Debug.printLog(tag, "┌获取章节名称", printLog);
Debug.printLog(tag, "└" + firstChapter.getDurChapterName(), printLog);
Debug.printLog(tag, "┌获取章节网址", printLog);
Debug.printLog(tag, "└" + firstChapter.getDurChapterUrl(), printLog);
Debug.printLog(tag, 1, "┌获取章节名称", printLog);
Debug.printLog(tag, 1, "└" + firstChapter.getDurChapterName(), printLog);
Debug.printLog(tag, 1, "┌获取章节网址", printLog);
Debug.printLog(tag, 1, "└" + firstChapter.getDurChapterUrl(), printLog);
return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ private WebContentBean analyzeBookContent(AnalyzeRule analyzer, final String s,
WebContentBean webContentBean = new WebContentBean();

analyzer.setContent(s, NetworkUtils.getAbsoluteURL(baseUrl, chapterUrl));
Debug.printLog(tag, "┌解析正文内容", printLog);
Debug.printLog(tag, 1, "┌解析正文内容", printLog);
webContentBean.content = StringUtils.formatHtml(analyzer.getString(ruleBookContent));
Debug.printLog(tag, "└" + webContentBean.content, printLog);
Debug.printLog(tag, 1, "└" + webContentBean.content, printLog);
String nextUrlRule = bookSourceBean.getRuleContentUrlNext();
if (!TextUtils.isEmpty(nextUrlRule)) {
Debug.printLog(tag, "┌解析下一页url", printLog);
Debug.printLog(tag, 1, "┌解析下一页url", printLog);
webContentBean.nextUrl = analyzer.getString(nextUrlRule, true);
Debug.printLog(tag, "└" + webContentBean.nextUrl, printLog);
Debug.printLog(tag, 1, "└" + webContentBean.nextUrl, printLog);
}

return webContentBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Observable<BookShelfBean> analyzeBookInfo(String s, final BookShelfBean bookShel

Debug.printLog(tag, "┌获取分类");
String bookKind = analyzer.getString(bookSourceBean.getRuleBookKind());
Debug.printLog(tag, "└" + bookKind);
Debug.printLog(tag, 111, "└" + bookKind);

Debug.printLog(tag, "┌获取最新章节");
String bookLastChapter = analyzer.getString(bookSourceBean.getRuleBookLastChapter());
Expand All @@ -93,7 +93,7 @@ Observable<BookShelfBean> analyzeBookInfo(String s, final BookShelfBean bookShel
Debug.printLog(tag, "┌获取简介");
String bookIntroduce = analyzer.getString(bookSourceBean.getRuleIntroduce());
if (!isEmpty(bookIntroduce)) bookInfoBean.setIntroduce(bookIntroduce);
Debug.printLog(tag, "└" + bookIntroduce, true, true);
Debug.printLog(tag, 1, "└" + bookIntroduce, true, true);

Debug.printLog(tag, "┌获取封面");
String bookCoverUrl = analyzer.getString(bookSourceBean.getRuleCoverUrl(), true);
Expand Down
64 changes: 32 additions & 32 deletions app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ private SearchBookBean getItem(AnalyzeRule analyzer, String baseUrl) throws Exce
Debug.printLog(tag, "└" + item.getCoverUrl());
Debug.printLog(tag, "┌获取分类");
item.setKind(analyzer.getString(bookSourceBean.getRuleBookKind()));
Debug.printLog(tag, "└" + item.getKind());
Debug.printLog(tag, 111, "└" + item.getKind());
Debug.printLog(tag, "┌获取最新章节");
item.setLastChapter(analyzer.getString(bookSourceBean.getRuleBookLastChapter()));
Debug.printLog(tag, "└最新章节:" + item.getLastChapter());
Debug.printLog(tag, "┌获取简介");
item.setIntroduce(analyzer.getString(bookSourceBean.getRuleIntroduce()));
Debug.printLog(tag, "└" + item.getIntroduce(), true, true);
Debug.printLog(tag, 1, "└" + item.getIntroduce(), true, true);
return item;
}
return null;
Expand All @@ -231,34 +231,34 @@ private SearchBookBean getItemAllInOne(AnalyzeRule analyzer, Object object, Stri
SearchBookBean item = new SearchBookBean();
analyzer.setBook(item);
NativeObject nativeObject = (NativeObject) object;
Debug.printLog(tag, "┌获取书名", printLog);
Debug.printLog(tag, 1, "┌获取书名", printLog);
String bookName = StringUtils.formatHtml(String.valueOf(nativeObject.get(ruleName)));
Debug.printLog(tag, "└" + bookName, printLog);
Debug.printLog(tag, 1, "└" + bookName, printLog);
if (!isEmpty(bookName)) {
item.setTag(tag);
item.setOrigin(sourceName);
item.setName(bookName);
Debug.printLog(tag, "┌获取作者", printLog);
Debug.printLog(tag, 1, "┌获取作者", printLog);
item.setAuthor(StringUtils.formatHtml(String.valueOf(nativeObject.get(ruleAuthor))));
Debug.printLog(tag, "└" + item.getAuthor(), printLog);
Debug.printLog(tag, "┌获取分类", printLog);
Debug.printLog(tag, 1, "└" + item.getAuthor(), printLog);
Debug.printLog(tag, 1, "┌获取分类", printLog);
item.setKind(String.valueOf(nativeObject.get(ruleKind)));
Debug.printLog(tag, "└" + item.getKind(), printLog);
Debug.printLog(tag, "┌获取最新章节", printLog);
Debug.printLog(tag, 111, "└" + item.getKind(), printLog);
Debug.printLog(tag, 1, "┌获取最新章节", printLog);
item.setLastChapter(String.valueOf(nativeObject.get(ruleLastChapter)));
Debug.printLog(tag, "└" + item.getLastChapter(), printLog);
Debug.printLog(tag, "┌获取简介", printLog);
Debug.printLog(tag, 1, "└" + item.getLastChapter(), printLog);
Debug.printLog(tag, 1, "┌获取简介", printLog);
item.setIntroduce(String.valueOf(nativeObject.get(ruleIntroduce)));
Debug.printLog(tag, "└" + item.getIntroduce(), printLog, true);
Debug.printLog(tag, "┌获取封面", printLog);
Debug.printLog(tag, 1, "└" + item.getIntroduce(), printLog, true);
Debug.printLog(tag, 1, "┌获取封面", printLog);
if (!isEmpty(ruleCoverUrl))
item.setCoverUrl(NetworkUtils.getAbsoluteURL(baseUrl, String.valueOf(nativeObject.get(ruleCoverUrl))));
Debug.printLog(tag, "└" + item.getCoverUrl(), printLog);
Debug.printLog(tag, "┌获取书籍网址", printLog);
Debug.printLog(tag, 1, "└" + item.getCoverUrl(), printLog);
Debug.printLog(tag, 1, "┌获取书籍网址", printLog);
String resultUrl = String.valueOf(nativeObject.get(ruleNoteUrl));
if (isEmpty(resultUrl)) resultUrl = baseUrl;
item.setNoteUrl(resultUrl);
Debug.printLog(tag, "└" + item.getNoteUrl(), printLog);
Debug.printLog(tag, 1, "└" + item.getNoteUrl(), printLog);
return item;
}
return null;
Expand All @@ -268,33 +268,33 @@ private SearchBookBean getItemInList(AnalyzeRule analyzer, String baseUrl, boole
Exception {
SearchBookBean item = new SearchBookBean();
analyzer.setBook(item);
Debug.printLog(tag, "┌获取书名", printLog);
Debug.printLog(tag, 1, "┌获取书名", printLog);
String bookName = StringUtils.formatHtml(analyzer.getString(ruleName));
Debug.printLog(tag, "└" + bookName, printLog);
Debug.printLog(tag, 1, "└" + bookName, printLog);
if (!TextUtils.isEmpty(bookName)) {
item.setTag(tag);
item.setOrigin(sourceName);
item.setName(bookName);
Debug.printLog(tag, "┌获取作者", printLog);
Debug.printLog(tag, 1, "┌获取作者", printLog);
item.setAuthor(StringUtils.formatHtml(analyzer.getString(ruleAuthor)));
Debug.printLog(tag, "└" + item.getAuthor(), printLog);
Debug.printLog(tag, "┌获取分类", printLog);
Debug.printLog(tag, 1, "└" + item.getAuthor(), printLog);
Debug.printLog(tag, 1, "┌获取分类", printLog);
item.setKind(analyzer.getString(ruleKind));
Debug.printLog(tag, "└" + item.getKind(), printLog);
Debug.printLog(tag, "┌获取最新章节", printLog);
Debug.printLog(tag, 111, "└" + item.getKind(), printLog);
Debug.printLog(tag, 1, "┌获取最新章节", printLog);
item.setLastChapter(analyzer.getString(ruleLastChapter));
Debug.printLog(tag, "└" + item.getLastChapter(), printLog);
Debug.printLog(tag, "┌获取简介", printLog);
Debug.printLog(tag, 1, "└" + item.getLastChapter(), printLog);
Debug.printLog(tag, 1, "┌获取简介", printLog);
item.setIntroduce(analyzer.getString(ruleIntroduce));
Debug.printLog(tag, "└" + item.getIntroduce(), printLog, true);
Debug.printLog(tag, "┌获取封面", printLog);
Debug.printLog(tag, 1, "└" + item.getIntroduce(), printLog, true);
Debug.printLog(tag, 1, "┌获取封面", printLog);
item.setCoverUrl(analyzer.getString(ruleCoverUrl, true));
Debug.printLog(tag, "└" + item.getCoverUrl(), printLog);
Debug.printLog(tag, "┌获取书籍网址", printLog);
Debug.printLog(tag, 1, "└" + item.getCoverUrl(), printLog);
Debug.printLog(tag, 1, "┌获取书籍网址", printLog);
String resultUrl = analyzer.getString(ruleNoteUrl, true);
if (isEmpty(resultUrl)) resultUrl = baseUrl;
item.setNoteUrl(resultUrl);
Debug.printLog(tag, "└" + item.getNoteUrl(), printLog);
Debug.printLog(tag, 1, "└" + item.getNoteUrl(), printLog);
return item;
}
return null;
Expand Down Expand Up @@ -385,11 +385,11 @@ private void getBooksOfRegex(String res, String[] regs,
Debug.printLog(tag, "┌获取作者名称");
Debug.printLog(tag, "└" + books.get(0).getAuthor());
Debug.printLog(tag, "┌获取分类信息");
Debug.printLog(tag, "└" + books.get(0).getKind());
Debug.printLog(tag, 111, "└" + books.get(0).getKind());
Debug.printLog(tag, "┌获取最新章节");
Debug.printLog(tag, "└" + books.get(0).getLastChapter());
Debug.printLog(tag, "┌获取简介内容");
Debug.printLog(tag, "└" + books.get(0).getIntroduce(), true, true);
Debug.printLog(tag, 1, "└" + books.get(0).getIntroduce(), true, true);
Debug.printLog(tag, "┌获取封面网址");
Debug.printLog(tag, "└" + books.get(0).getCoverUrl());
Debug.printLog(tag, "┌获取书籍网址");
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/com/kunfei/bookshelf/model/content/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,25 @@ private static String getDoTime() {
}

public static void printLog(String tag, String msg) {
printLog(tag, msg, true);
printLog(tag, 1, msg, true);
}

static void printLog(String tag, String msg, boolean print) {
printLog(tag, msg, print, false);
public static void printLog(String tag, int state, String msg) {
printLog(tag, state, msg, true);
}

static void printLog(String tag, String msg, boolean print, boolean formatHtml) {
static void printLog(String tag, int state, String msg, boolean print) {
printLog(tag, state, msg, print, false);
}

static void printLog(String tag, int state, String msg, boolean print, boolean formatHtml) {
if (print && Objects.equals(SOURCE_DEBUG_TAG, tag)) {
if (formatHtml) {
msg = StringUtils.formatHtml(msg);
}
if (state == 111) {
msg = msg.replace("\n", ",");
}
msg = String.format("%s %s", getDoTime(), msg);
RxBus.get().post(RxBusTag.PRINT_DEBUG_LOG, msg);
}
Expand Down

0 comments on commit 66abc04

Please sign in to comment.