第三方书源兼容

pull/21/head
fengyuecanzhu 3 years ago
parent 618afc3249
commit acaed246cc
  1. 3
      .idea/gradle.xml
  2. 12
      app/build.gradle
  3. 1
      app/src/main/java/xyz/fycz/myreader/common/APPCONST.java
  4. 1
      app/src/main/java/xyz/fycz/myreader/model/third2/analyzeRule/AnalyzeRule.java
  5. 1
      app/src/main/java/xyz/fycz/myreader/model/third2/analyzeRule/AnalyzeUrl.java
  6. 5
      app/src/main/java/xyz/fycz/myreader/model/third2/analyzeRule/JsExtensions.java
  7. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/Exceptions.kt
  8. 12
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeByJSonPath.kt
  9. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeByJSoup.kt
  10. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeByRegex.kt
  11. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeByXPath.kt
  12. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt
  13. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt
  14. 67
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt
  15. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/QueryTTF.java
  16. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/RuleAnalyzer.kt
  17. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/RuleData.kt
  18. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/RuleDataInterface.kt
  19. 16
      app/src/main/java/xyz/fycz/myreader/model/third3/http/BackstageWebView.kt
  20. 12
      app/src/main/java/xyz/fycz/myreader/model/third3/http/SSLHelper.kt
  21. 8
      app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookChapterList.kt
  22. 6
      app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookContent.kt
  23. 4
      app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookInfo.kt
  24. 6
      app/src/main/java/xyz/fycz/myreader/model/third3/webBook/BookList.kt
  25. 2
      app/src/main/java/xyz/fycz/myreader/model/third3/webBook/SearchModel.kt
  26. 4
      app/src/main/java/xyz/fycz/myreader/model/third3/webBook/WebBook.kt

@ -4,7 +4,7 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
@ -15,7 +15,6 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

@ -124,6 +124,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
productFlavors {
}
packagingOptions {
@ -242,6 +246,14 @@ dependencies {
// https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j
implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '2.9.1'
//
def coroutines_version = '1.5.1'
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version")
//apache
implementation('org.apache.commons:commons-text:1.9')
}
greendao {

@ -132,4 +132,5 @@ public class APPCONST {
public static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.3 Safari/537.36";
public static final String UA_NAME = "User-Agent";
}

@ -20,7 +20,6 @@ import javax.script.SimpleBindings;
import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.service.CookieStore;
import xyz.fycz.myreader.util.help.StringHelper;
import xyz.fycz.myreader.util.help.JsExtensions;
import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.StringUtils;

@ -20,7 +20,6 @@ import java.util.regex.Pattern;
import javax.script.SimpleBindings;
import xyz.fycz.myreader.util.help.StringHelper;
import xyz.fycz.myreader.util.help.JsExtensions;
import xyz.fycz.myreader.util.utils.NetworkUtils;
import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.util.utils.UrlEncoderUtils;

@ -1,4 +1,4 @@
package xyz.fycz.myreader.util.help;
package xyz.fycz.myreader.model.third2.analyzeRule;
import android.text.TextUtils;
@ -23,10 +23,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import xyz.fycz.myreader.greendao.service.CookieStore;
import xyz.fycz.myreader.model.third2.analyzeRule.AnalyzeUrl;
import xyz.fycz.myreader.util.ZipUtils;
import xyz.fycz.myreader.util.help.SSLSocketClient;
import xyz.fycz.myreader.util.utils.EncoderUtils;
import xyz.fycz.myreader.util.utils.EncodingDetect;
import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.MD5Utils;
import xyz.fycz.myreader.util.utils.OkHttpUtils;

@ -1,6 +1,6 @@
@file:Suppress("unused")
package io.legado.app.model
package xyz.fycz.myreader.model.third3
class AppException(msg: String) : Exception(msg)

@ -1,16 +1,18 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
import android.util.Log
import androidx.annotation.Keep
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.ReadContext
import timber.log.Timber
import java.util.*
@Suppress("RegExpRedundantEscape")
@Keep
class AnalyzeByJSonPath(json: Any) {
private val TAG = AnalyzeByJSonPath::class.simpleName
companion object {
fun parse(json: Any): ReadContext {
@ -50,7 +52,7 @@ class AnalyzeByJSonPath(json: Any) {
ob.toString()
}
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
}
}
return result
@ -87,7 +89,7 @@ class AnalyzeByJSonPath(json: Any) {
result.add(obj.toString())
}
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
}
} else {
result.add(st)
@ -137,7 +139,7 @@ class AnalyzeByJSonPath(json: Any) {
try {
return it.read<ArrayList<Any>>(rules[0])
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
}
}
} else {

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
import androidx.annotation.Keep
import org.jsoup.Jsoup

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
import androidx.annotation.Keep
import java.util.*

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
import android.text.TextUtils
import androidx.annotation.Keep

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
import android.text.TextUtils
import androidx.annotation.Keep

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
import android.annotation.SuppressLint
import androidx.annotation.Keep

@ -1,24 +1,20 @@
package io.legado.app.help
package xyz.fycz.myreader.model.third3.analyzeRule
import android.net.Uri
import android.util.Base64
import android.util.Log
import androidx.annotation.Keep
import io.legado.app.BuildConfig
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.dateFormat
import io.legado.app.data.entities.BaseSource
import io.legado.app.help.http.*
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.QueryTTF
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import nl.siegmann.epublib.epub.PackageDocumentBase.dateFormat
import org.jsoup.Connection
import org.jsoup.Jsoup
import splitties.init.appCtx
import timber.log.Timber
import xyz.fycz.myreader.greendao.entity.rule.BookSource
import xyz.fycz.myreader.greendao.service.CookieStore
import xyz.fycz.myreader.util.ZipUtils
import xyz.fycz.myreader.util.utils.*
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
@ -38,7 +34,10 @@ import java.util.zip.ZipInputStream
@Suppress("unused")
interface JsExtensions {
fun getSource(): BaseSource?
private val TAG: String?
get() = JsExtensions::class.simpleName
fun getSource(): BookSource?
/**
* 访问网络,返回String
@ -50,9 +49,9 @@ interface JsExtensions {
analyzeUrl.getStrResponseAwait().body
}.onFailure {
log("ajax(${urlStr}) error\n${it.stackTraceToString()}")
Timber.e(it)
Log.e(TAG, it.toString())
}.getOrElse {
it.msg
it.message
}
}
}
@ -86,7 +85,7 @@ interface JsExtensions {
analyzeUrl.getStrResponseAwait()
}.onFailure {
log("connect(${urlStr}) error\n${it.stackTraceToString()}")
Timber.e(it)
Log.e(TAG, it.toString())
}.getOrElse {
StrResponse(analyzeUrl.url, it.localizedMessage)
}
@ -101,7 +100,7 @@ interface JsExtensions {
analyzeUrl.getStrResponseAwait()
}.onFailure {
log("ajax($urlStr,$header) error\n${it.stackTraceToString()}")
Timber.e(it)
Log.e(TAG, it.toString())
}.getOrElse {
StrResponse(analyzeUrl.url, it.localizedMessage)
}
@ -134,11 +133,11 @@ interface JsExtensions {
fun downloadFile(content: String, url: String): String {
val type = AnalyzeUrl(url, source = getSource()).type ?: return ""
val zipPath = FileUtils.getPath(
FileUtils.createFolderIfNotExist(FileUtils.getCachePath()),
FileUtils.getFile(FileUtils.getCachePath()),
"${MD5Utils.md5Encode16(url)}.${type}"
)
FileUtils.deleteFile(zipPath)
val zipFile = FileUtils.createFileIfNotExist(zipPath)
val zipFile = FileUtils.getFile(zipPath)
StringUtils.hexStringToByte(content).let {
if (it.isNotEmpty()) {
zipFile.writeBytes(it)
@ -303,7 +302,7 @@ interface JsExtensions {
fun readTxtFile(path: String): String {
val file = getFile(path)
if (file.exists()) {
val charsetName = EncodingDetect.getEncode(file)
val charsetName = EncodingDetect.getJavaEncode(file)
return String(file.readBytes(), charset(charsetName))
}
return ""
@ -321,8 +320,7 @@ interface JsExtensions {
* 删除本地文件
*/
fun deleteFile(path: String) {
val file = getFile(path)
FileUtils.delete(file, true)
FileUtils.deleteFile(path)
}
/**
@ -332,16 +330,13 @@ interface JsExtensions {
*/
fun unzipFile(zipPath: String): String {
if (zipPath.isEmpty()) return ""
val unzipPath = FileUtils.getPath(
FileUtils.createFolderIfNotExist(FileUtils.getCachePath()),
FileUtils.getNameExcludeExtension(zipPath)
)
val unzipPath = FileUtils.getCachePath() + File.separator + FileUtils.getNameExcludeExtension(zipPath)
FileUtils.deleteFile(unzipPath)
val zipFile = getFile(zipPath)
val unzipFolder = FileUtils.createFolderIfNotExist(unzipPath)
val zipFile = FileUtils.getFile(zipPath)
val unzipFolder = FileUtils.getFolder(unzipPath)
ZipUtils.unzipFile(zipFile, unzipFolder)
FileUtils.deleteFile(zipFile.absolutePath)
return unzipPath.substring(FileUtils.getCachePath().length)
FileUtils.deleteFile(zipPath)
return unzipPath
}
/**
@ -354,7 +349,7 @@ interface JsExtensions {
unzipFolder.listFiles().let {
if (it != null) {
for (f in it) {
val charsetName = EncodingDetect.getEncode(f)
val charsetName = EncodingDetect.getJavaEncode(f)
contents.append(String(f.readBytes(), charset(charsetName)))
.append("\n")
}
@ -373,7 +368,7 @@ interface JsExtensions {
*/
fun getZipStringContent(url: String, path: String): String {
val byteArray = getZipByteArrayContent(url, path) ?: return ""
val charsetName = EncodingDetect.getEncode(byteArray)
val charsetName = EncodingDetect.getJavaEncode(byteArray)
return String(byteArray, Charset.forName(charsetName))
}
@ -485,7 +480,7 @@ interface JsExtensions {
Debug.log(it.getKey(), msg)
} ?: Debug.log(msg)
if (BuildConfig.DEBUG) {
Timber.d(msg)
Log.e(TAG, msg)
}
return msg
}
@ -515,7 +510,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
log(e.localizedMessage ?: "aesDecodeToByteArrayERROR")
null
}
@ -554,7 +549,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, r.toString())
log(e.localizedMessage ?: "aesDecodeToByteArrayERROR")
null
}
@ -592,7 +587,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
log(e.localizedMessage ?: "aesEncodeToByteArrayERROR")
null
}
@ -629,7 +624,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
log(e.localizedMessage ?: "aesEncodeToBase64ByteArrayERROR")
null
}

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule;
package xyz.fycz.myreader.model.third3.analyzeRule;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
//通用的规则切分处理
class RuleAnalyzer(data: String, code: Boolean = false) {

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
class RuleData : RuleDataInterface {

@ -1,4 +1,4 @@
package io.legado.app.model.analyzeRule
package xyz.fycz.myreader.model.third3.analyzeRule
interface RuleDataInterface {

@ -8,12 +8,12 @@ import android.webkit.CookieManager
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import io.legado.app.constant.AppConst
import io.legado.app.model.NoStackTraceException
import io.legado.app.utils.runOnUI
import kotlinx.coroutines.*
import org.apache.commons.text.StringEscapeUtils
import splitties.init.appCtx
import xyz.fycz.myreader.application.App
import xyz.fycz.myreader.common.APPCONST
import xyz.fycz.myreader.greendao.service.CookieStore
import xyz.fycz.myreader.model.third3.NoStackTraceException
import java.lang.ref.WeakReference
import kotlin.coroutines.resume
@ -36,7 +36,7 @@ class BackstageWebView(
suspend fun getStrResponse(): StrResponse = suspendCancellableCoroutine { block ->
block.invokeOnCancellation {
runOnUI {
App.getHandler().post {
destroy()
}
}
@ -51,7 +51,7 @@ class BackstageWebView(
block.cancel(error)
}
}
runOnUI {
App.getHandler().post {
try {
load()
} catch (error: Throwable) {
@ -88,12 +88,12 @@ class BackstageWebView(
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
private fun createWebView(): WebView {
val webView = WebView(appCtx)
val webView = WebView(App.getmContext())
val settings = webView.settings
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
settings.blockNetworkImage = true
settings.userAgentString = headerMap?.get(AppConst.UA_NAME)
settings.userAgentString = headerMap?.get(APPCONST.UA_NAME)
settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
if (sourceRegex.isNullOrEmpty()) {
webView.webViewClient = HtmlWebViewClient()

@ -1,8 +1,8 @@
package io.legado.app.help.http
import android.annotation.SuppressLint
import android.util.Log
import timber.log.Timber
import java.io.IOException
import java.io.InputStream
import java.security.KeyManagementException
@ -16,7 +16,7 @@ import javax.net.ssl.*
@Suppress("unused")
object SSLHelper {
private val TAG = SSLHelper::class.simpleName
/**
* 为了解决客户端不信任服务器数字证书的问题
* 网络上大部分的解决方案都是让客户端不对证书做任何检查
@ -127,9 +127,9 @@ object SSLHelper {
sslParams.trustManager = manager
return sslParams
} catch (e: NoSuchAlgorithmException) {
Timber.e(e)
Log.e(TAG, e.toString())
} catch (e: KeyManagementException) {
Timber.e(e)
Log.e(TAG, e.toString())
}
return null
}
@ -143,7 +143,7 @@ object SSLHelper {
kmf.init(clientKeyStore, password.toCharArray())
return kmf.keyManagers
} catch (e: Exception) {
Timber.e(e)
Log.e(TAG, e.toString())
}
return null
}
@ -162,7 +162,7 @@ object SSLHelper {
try {
certStream.close()
} catch (e: IOException) {
Timber.e(e)
Log.e(TAG, e.toString())
}
}
//我们创建一个默认类型的TrustManagerFactory

@ -1,16 +1,16 @@
package io.legado.app.model.webBook
package xyz.fycz.myreader.model.third3.webBook
import android.text.TextUtils
import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.TocRule
import xyz.fycz.myreader.model.third3.rule.TocRule
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.TocEmptyException
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeRule
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.async

@ -1,4 +1,4 @@
package io.legado.app.model.webBook
package xyz.fycz.myreader.model.third3.webBook
import io.legado.app.R
import io.legado.app.data.appDb
@ -10,8 +10,8 @@ import io.legado.app.help.BookHelp
import io.legado.app.model.ContentEmptyException
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeRule
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeUrl
import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope

@ -1,4 +1,4 @@
package io.legado.app.model.webBook
package xyz.fycz.myreader.model.third3.webBook
import io.legado.app.R
import io.legado.app.data.entities.Book
@ -6,7 +6,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeRule
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeRule
import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.StringUtils.wordCountFormat

@ -1,4 +1,4 @@
package io.legado.app.model.webBook
package xyz.fycz.myreader.model.third3.webBook
import io.legado.app.R
import io.legado.app.data.entities.Book
@ -8,8 +8,8 @@ import io.legado.app.data.entities.rule.BookListRule
import io.legado.app.help.BookHelp
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeRule
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeUrl
import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.StringUtils.wordCountFormat

@ -1,4 +1,4 @@
package io.legado.app.model.webBook
package xyz.fycz.myreader.model.third3.webBook
import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey

@ -1,4 +1,4 @@
package io.legado.app.model.webBook
package xyz.fycz.myreader.model.third3.webBook
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
@ -8,7 +8,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeUrl
import xyz.fycz.myreader.model.third3.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive

Loading…
Cancel
Save