网络导入支持使用蓝奏云链接

pull/21/head
fengyuecanzhu 3 years ago
parent c248544a89
commit 6e77f4ae72
  1. 15
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java
  2. 12
      app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
  3. 2
      app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java
  4. 6
      app/src/main/java/xyz/fycz/myreader/util/utils/ClipBoardUtil.java
  5. 17
      app/src/main/java/xyz/fycz/myreader/webapi/LanZouApi.kt
  6. 2
      app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt

@ -4,6 +4,8 @@ import android.database.Cursor;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -11,8 +13,10 @@ import java.util.List;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.ObservableEmitter; import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableSource;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import io.reactivex.functions.Function;
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.entity.thirdsource.BookSource3Bean; import xyz.fycz.myreader.entity.thirdsource.BookSource3Bean;
@ -34,6 +38,7 @@ 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;
import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.webapi.LanZouApi;
import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil;
@ -192,7 +197,7 @@ public class BookSourceManager {
DbManager.getDaoSession().getBookSourceDao().deleteInTx(sources); DbManager.getDaoSession().getBookSourceDao().deleteInTx(sources);
} }
public static boolean isBookSourceExist(BookSource source){ public static boolean isBookSourceExist(BookSource source) {
if (source == null) return false; if (source == null) return false;
return DbManager.getDaoSession().getBookSourceDao().load(source.getSourceUrl()) != null; return DbManager.getDaoSession().getBookSourceDao().load(source.getSourceUrl()) != null;
} }
@ -320,6 +325,14 @@ public class BookSourceManager {
} else if (new File(string).isFile()) { } else if (new File(string).isFile()) {
return importSource(FileUtils.readText(string)); return importSource(FileUtils.readText(string));
} }
if (string.contains("lanzou")) {
return LanZouApi.INSTANCE.getUrl(string)
.flatMap((Function<String, ObservableSource<String>>) s -> Observable.create(emitter -> {
emitter.onNext(OkHttpUtils.getHtml(s));
emitter.onComplete();
})).flatMap(BookSourceManager::importBookSourceFromJson)
.compose(RxUtils::toSimpleSingle);
}
if (NetworkUtils.isUrl(string)) { if (NetworkUtils.isUrl(string)) {
String finalString = string; String finalString = string;
return Observable.create((ObservableEmitter<String> e) -> e.onNext(OkHttpUtils.getHtml(finalString))) return Observable.create((ObservableEmitter<String> e) -> e.onNext(OkHttpUtils.getHtml(finalString)))

@ -119,16 +119,8 @@ public class AboutActivity extends BaseActivity {
String[] str = new String[1]; String[] str = new String[1];
MyAlertDialog.createInputDia(this, getString(R.string.lan_zou_parse), MyAlertDialog.createInputDia(this, getString(R.string.lan_zou_parse),
"格式:链接+逗号+密码(没有密码就不用填)", "", true, "格式:链接+逗号+密码(没有密码就不用填)", "", true,
100, text -> str[0] = text.replaceAll("\\s", ""), (dialog, which) -> { 100, text -> str[0] = text, (dialog, which) -> {
String url, pwd = ""; LanZouApi.INSTANCE.getUrl(str[0])
if (str[0].contains(",") || str[0].contains(",") || str[0].contains("密码:")) {
String[] strs = str[0].split(",|,|密码:");
url = strs[0];
pwd = strs[1];
} else {
url = str[0];
}
LanZouApi.INSTANCE.getUrl(url, pwd)
.compose(RxUtils::toSimpleSingle) .compose(RxUtils::toSimpleSingle)
.subscribe(new MyObserver<String>() { .subscribe(new MyObserver<String>() {
@Override @Override

@ -257,7 +257,7 @@ public class DIYSourceFragment extends BaseFragment {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
ToastUtils.showError("书源格式错误,请导入正确的书源"); ToastUtils.showError("书源格式错误,请导入正确的书源\n" + e.getLocalizedMessage());
dialog.dismiss(); dialog.dismiss();
} }
}); });

@ -10,6 +10,8 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import xyz.fycz.myreader.util.ToastUtils;
/** /**
* 剪切板读写工具 * 剪切板读写工具
*/ */
@ -20,6 +22,7 @@ public class ClipBoardUtil {
* @return * @return
*/ */
public static String paste(Context context) { public static String paste(Context context) {
try {
ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (manager != null) { if (manager != null) {
if (manager.hasPrimaryClip() && manager.getPrimaryClip().getItemCount() > 0) { if (manager.hasPrimaryClip() && manager.getPrimaryClip().getItemCount() > 0) {
@ -30,6 +33,9 @@ public class ClipBoardUtil {
} }
} }
} }
} catch (Exception e) {
ToastUtils.showError("" + e.getLocalizedMessage());
}
return ""; return "";
} }

@ -10,6 +10,7 @@ import xyz.fycz.myreader.util.help.StringHelper
import xyz.fycz.myreader.util.utils.GSON import xyz.fycz.myreader.util.utils.GSON
import xyz.fycz.myreader.util.utils.OkHttpUtils import xyz.fycz.myreader.util.utils.OkHttpUtils
import xyz.fycz.myreader.util.utils.fromJsonObject import xyz.fycz.myreader.util.utils.fromJsonObject
import xyz.fycz.myreader.util.utils.splitNotBlank
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
import java.util.* import java.util.*
@ -19,13 +20,27 @@ import java.util.*
* @date 2022/1/22 18:50 * @date 2022/1/22 18:50
*/ */
object LanZouApi { object LanZouApi {
fun getUrl(url: String): Observable<String> {
url.replace("\\s".toRegex(), "").let {
val regex = ",|,|密码:".toRegex()
if (it.contains(regex)) {
it.split(regex).let { arr ->
return getUrl(arr[0], arr[1])
}
} else {
return getUrl(it, "")
}
}
}
/** /**
* 通过api获取蓝奏云可下载直链 * 通过api获取蓝奏云可下载直链
* *
* @param url * @param url
* @param password * @param password
*/ */
fun getUrl(url: String, password: String = ""): Observable<String> { private fun getUrl(url: String, password: String = ""): Observable<String> {
return Observable.create { return Observable.create {
val html = OkHttpUtils.getHtml(url) val html = OkHttpUtils.getHtml(url)
val url2 = if (password.isEmpty()) { val url2 = if (password.isEmpty()) {

@ -101,7 +101,7 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) {
fun findBook(url: String, fc: Third3FindCrawler, page: Int): Observable<List<Book>> { fun findBook(url: String, fc: Third3FindCrawler, page: Int): Observable<List<Book>> {
return Observable.create { emitter -> return Observable.create { emitter ->
if (!url.contains("{{page}}") && page > 1){ if (!url.contains("page") && page > 1){
emitter.onError(NoStackTraceException("没有下一页")) emitter.onError(NoStackTraceException("没有下一页"))
return@create return@create
} }

Loading…
Cancel
Save