feat: add imageDecode Rule

pull/2283/head
Xwite 2 years ago
parent 1cd9aa3f7a
commit 25f80a6e91
  1. 6
      app/src/main/assets/help/ruleHelp.md
  2. 1
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  3. 21
      app/src/main/java/io/legado/app/help/BookHelp.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  5. 1
      app/src/main/res/values-es-rES/strings.xml
  6. 1
      app/src/main/res/values-ja-rJP/strings.xml
  7. 1
      app/src/main/res/values-pt-rBR/strings.xml
  8. 1
      app/src/main/res/values-zh-rHK/strings.xml
  9. 1
      app/src/main/res/values-zh-rTW/strings.xml
  10. 1
      app/src/main/res/values-zh/strings.xml
  11. 1
      app/src/main/res/values/strings.xml

@ -152,4 +152,8 @@ let options = {
```
* 购买操作
> 可直接填写链接或者JavaScript,如果执行结果是字符串链接将会自动打开浏览器
> 可直接填写链接或者JavaScript,如果执行结果是字符串链接将会自动打开浏览器
* 图片解密
> 适用于图片需要二次解密的情况,直接填写JavaScript,返回解密后的bytes
> 部分变量说明:java(仅支持[js扩展类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/JsExtensions.kt)),result为待解密图片的bytes,src为图片链接

@ -11,5 +11,6 @@ data class ContentRule(
var sourceRegex: String? = null,
var replaceRegex: String? = null, //替换规则
var imageStyle: String? = null, //默认大小居中,FULL最大宽度
var imageDecode: String? = null, //图片bytes二次解密js, 返回解密后的bytes
var payAction: String? = null, //购买操作,js或者包含{{js}}的url
) : Parcelable

@ -136,15 +136,28 @@ object BookHelp {
downloadImages.add(src)
val analyzeUrl = AnalyzeUrl(src, source = bookSource)
try {
analyzeUrl.getByteArrayAwait().let {
FileUtils.createFileIfNotExist(
var bytes = analyzeUrl.getByteArrayAwait()
//某些图片被加密,需要进一步解密
bookSource?.getContentRule()?.imageDecode?.let {
kotlin.runCatching {
bookSource?.evalJS(it) {
put("book", book)
put("result", bytes)
put("src", src)
} as ByteArray
}.onSuccess {
bytes = it
}.onFailure {
AppLog.putDebug("${src}解密bytes错误", it)
}
}
FileUtils.createFileIfNotExist(
downloadDir,
cacheFolderName,
book.getFolderName(),
cacheImageFolderName,
"${MD5Utils.md5Encode16(src)}.${getImageSuffix(src)}"
).writeBytes(it)
}
).writeBytes(bytes)
} catch (e: Exception) {
AppLog.putDebug("${src}下载错误", e)
} finally {

@ -297,6 +297,7 @@ class BookSourceEditActivity :
add(EditEntity("sourceRegex", cr?.sourceRegex, R.string.rule_source_regex))
add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex))
add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style))
add(EditEntity("imageDecode", cr?.imageDecode, R.string.rule_image_decode))
add(EditEntity("payAction", cr?.payAction, R.string.rule_pay_action))
}
// 段评
@ -451,6 +452,7 @@ class BookSourceEditActivity :
"sourceRegex" -> contentRule.sourceRegex = it.value
"replaceRegex" -> contentRule.replaceRegex = it.value
"imageStyle" -> contentRule.imageStyle = it.value
"imageDecode" -> contentRule.imageDecode = it.value
"payAction" -> contentRule.payAction = it.value
}
}

@ -1025,4 +1025,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
<string name="rule_image_decode">Decode Image(imageDecode)</string>
</resources>

@ -1028,4 +1028,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
<string name="rule_image_decode">Decode Image(imageDecode)</string>
</resources>

@ -1028,4 +1028,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
<string name="rule_image_decode">Decode Image(imageDecode)</string>
</resources>

@ -1025,4 +1025,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">展示顶部工具栏附加区域</string>
<string name="read_bar_style_follow_page">工具栏样式跟随页面</string>
<string name="rule_image_decode">图片解密(imageDecode)</string>
</resources>

@ -1027,4 +1027,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">展示顶部工具栏附加区域</string>
<string name="read_bar_style_follow_page">工具栏样式跟随页面</string>
<string name="rule_image_decode">图片解密(imageDecode)</string>
</resources>

@ -1027,4 +1027,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">展示顶部工具栏附加区域</string>
<string name="read_bar_style_follow_page">工具栏样式跟随页面</string>
<string name="rule_image_decode">图片解密(imageDecode)</string>
</resources>

@ -1028,4 +1028,5 @@
<string name="tag_explore_disabled">标志:发现已禁用</string>
<string name="show_read_title_addition">show read title addition area</string>
<string name="read_bar_style_follow_page">read bar style follow page</string>
<string name="rule_image_decode">Decode Image(imageDecode)</string>
</resources>

Loading…
Cancel
Save