Merge pull request #2283 from Xwite/master

feat: decode decrypted image bytes
This commit is contained in:
kunfei
2022-09-15 17:40:40 +08:00
committed by GitHub
12 changed files with 34 additions and 8 deletions
+2 -3
View File
@@ -55,9 +55,6 @@ java.getElements(ruleStr: String)
java.reGetBook()
java.refreshTocUrl()
```
### [js扩展类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/JsExtensions.kt) 部分函数
* 变量存取
```
@@ -65,6 +62,8 @@ java.get(key)
java.put(key, value)
```
### [js扩展类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/JsExtensions.kt) 部分函数
* 网络请求
```
+5 -1
View File
@@ -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>
+1
View File
@@ -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>
+1
View File
@@ -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>