From 4842b731a3bc115e3ff4baff809b0b694b216ea8 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Thu, 20 Jan 2022 15:48:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=8F=91=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExploreKind3.kt} | 4 +-- .../myreader/model/third3/webBook/BookList.kt | 2 +- .../ui/activity/FindBookActivity.java | 8 +++++- .../fycz/myreader/webapi/Third3SourceApi.kt | 26 +++++++++++++++++-- .../fycz/myreader/webapi/ThirdSourceApi.java | 4 +++ .../crawler/source/find/Third3FindCrawler.kt | 10 +++++++ .../crawler/source/find/ThirdFindCrawler.java | 7 +++-- 7 files changed, 51 insertions(+), 10 deletions(-) rename app/src/main/java/xyz/fycz/myreader/entity/thirdsource/{ExploreKind.kt => source3/ExploreKind3.kt} (91%) create mode 100644 app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/Third3FindCrawler.kt diff --git a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ExploreKind.kt b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/source3/ExploreKind3.kt similarity index 91% rename from app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ExploreKind.kt rename to app/src/main/java/xyz/fycz/myreader/entity/thirdsource/source3/ExploreKind3.kt index 3ce4dc5..c837ab1 100644 --- a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ExploreKind.kt +++ b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/source3/ExploreKind3.kt @@ -1,6 +1,6 @@ -package xyz.fycz.myreader.entity.thirdsource +package xyz.fycz.myreader.entity.thirdsource.source3 -data class ExploreKind( +data class ExploreKind3( val title: String, val url: String? = null, val style: Style? = null diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookList.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookList.kt index 5affcd9..4929f5b 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookList.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookList.kt @@ -58,7 +58,7 @@ object BookList { var reverse = false val bookListRule: BookListRule = when { isSearch -> bookSource.searchRule - bookSource.findRule.url.isNullOrBlank() -> bookSource.searchRule + bookSource.findRule.list.isNullOrBlank() -> bookSource.searchRule else -> bookSource.findRule } var ruleList: String = bookListRule.list ?: "" diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/FindBookActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/FindBookActivity.java index c2fb91a..5d62670 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/FindBookActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/FindBookActivity.java @@ -19,6 +19,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.base.observer.MyObserver; +import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivityFindBookBinding; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.ui.adapter.TabFragmentPageAdapter; @@ -27,6 +28,7 @@ import xyz.fycz.myreader.ui.fragment.FindBook1Fragment; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.RxUtils; import xyz.fycz.myreader.webapi.crawler.base.FindCrawler; +import xyz.fycz.myreader.webapi.crawler.source.find.Third3FindCrawler; import xyz.fycz.myreader.webapi.crawler.source.find.ThirdFindCrawler; /** @@ -60,7 +62,11 @@ public class FindBookActivity extends BaseActivity { Object obj = BitIntentDataManager.getInstance().getData(getIntent()); if (obj instanceof BookSource) { source = (BookSource) obj; - findCrawler = new ThirdFindCrawler(source); + if (APPCONST.THIRD_3_SOURCE.equals(source.getSourceType())) { + findCrawler = new Third3FindCrawler(source); + } else { + findCrawler = new ThirdFindCrawler(source); + } } else if (obj instanceof FindCrawler) { findCrawler = (FindCrawler) obj; } diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt b/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt index 0b33348..8522a11 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt +++ b/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt @@ -10,6 +10,7 @@ import xyz.fycz.myreader.greendao.entity.Chapter import xyz.fycz.myreader.model.mulvalmap.ConMVMap import xyz.fycz.myreader.model.third3.webBook.WebBook import xyz.fycz.myreader.webapi.crawler.source.Third3Crawler +import xyz.fycz.myreader.webapi.crawler.source.find.Third3FindCrawler /** * @author fengyue @@ -55,7 +56,7 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) { } } - fun getBookChaptersByT3C(book: Book, rc: Third3Crawler): Observable>{ + fun getBookChaptersByT3C(book: Book, rc: Third3Crawler): Observable> { return Observable.create { emitter -> WebBook.getChapterList( scope, @@ -71,7 +72,11 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) { } } - fun getChapterContentByT3C(chapter: Chapter, book: Book, rc: Third3Crawler): Observable{ + fun getChapterContentByT3C( + chapter: Chapter, + book: Book, + rc: Third3Crawler + ): Observable { return Observable.create { emitter -> WebBook.getContent( scope, @@ -87,4 +92,21 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) { } } } + + fun findBook(url: String, fc: Third3FindCrawler, page: Int): Observable> { + return Observable.create { emitter -> + WebBook.exploreBook( + scope, + fc.source, + url, + page + ).onSuccess { + emitter.onNext(it) + }.onError { + emitter.onError(it) + }.onFinally { + emitter.onComplete() + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java b/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java index c240157..358112b 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java @@ -25,6 +25,7 @@ import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler; import xyz.fycz.myreader.webapi.crawler.source.Third3Crawler; import xyz.fycz.myreader.webapi.crawler.source.ThirdCrawler; +import xyz.fycz.myreader.webapi.crawler.source.find.Third3FindCrawler; import xyz.fycz.myreader.webapi.crawler.source.find.ThirdFindCrawler; import static xyz.fycz.myreader.common.APPCONST.JS_PATTERN; @@ -165,6 +166,9 @@ public class ThirdSourceApi { * 发现 */ public static Observable> findBook(String url, ThirdFindCrawler fc, int page) { + if (fc instanceof Third3FindCrawler){ + return Third3SourceApi.INSTANCE.findBook(url, (Third3FindCrawler) fc, page); + } BookSource source = fc.getSource(); Map headers = getCookies(fc.getTag()); BookList bookList = new BookList(source.getSourceUrl(), source.getSourceName(), source, true); diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/Third3FindCrawler.kt b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/Third3FindCrawler.kt new file mode 100644 index 0000000..0915e21 --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/Third3FindCrawler.kt @@ -0,0 +1,10 @@ +package xyz.fycz.myreader.webapi.crawler.source.find + +import xyz.fycz.myreader.greendao.entity.rule.BookSource + +/** + * @author fengyue + * @date 2022/1/20 15:33 + */ +class Third3FindCrawler(source: BookSource) : ThirdFindCrawler(source) { +} \ No newline at end of file diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/ThirdFindCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/ThirdFindCrawler.java index 18ecf91..7fa2526 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/ThirdFindCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/find/ThirdFindCrawler.java @@ -8,10 +8,9 @@ import java.util.List; import javax.script.SimpleBindings; import io.reactivex.Observable; -import io.reactivex.disposables.Disposable; import xyz.fycz.myreader.entity.FindKind; import xyz.fycz.myreader.entity.StrResponse; -import xyz.fycz.myreader.entity.thirdsource.ExploreKind; +import xyz.fycz.myreader.entity.thirdsource.source3.ExploreKind3; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.FindRule; @@ -57,9 +56,9 @@ public class ThirdFindCrawler extends BaseFindCrawler { return Observable.create(emitter -> { try { if (StringUtils.isJsonArray(findRuleBean.getUrl())) { - List kinds = GsonUtils.parseJArray(findRuleBean.getUrl(), ExploreKind.class); + List kinds = GsonUtils.parseJArray(findRuleBean.getUrl(), ExploreKind3.class); StringBuilder sb = new StringBuilder(); - for (ExploreKind kind : kinds){ + for (ExploreKind3 kind : kinds){ String url = kind.getUrl() == null ? "" : kind.getUrl(); sb.append(kind.getTitle()).append("::").append(url).append("\n"); }