LocalBook.kt:analyzeNameAuthor 识别阅读默认导出的文件名;更新正则匹配

pull/1592/head
Xwite 3 years ago
parent 71ce2fe468
commit 3f723c88d3
  1. 12
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@ -128,9 +128,9 @@ object LocalBook {
val m1 = Pattern
.compile("(.*?)《([^《》]+)》(.*)")
.matcher(tempFileName)
//匹配 书名 by 作者名.txt
//匹配 书名 作者:作者名.txt
val m2 = Pattern
.compile("(^)(.+) by (.+)$")
.compile("(^)(.+) 作者:(.+)$")
.matcher(tempFileName)
(m1.takeIf { m1.find() } ?: m2.takeIf { m2.find() }).run {
@ -152,13 +152,13 @@ object LocalBook {
name = bookMess["name"] ?: tempFileName
author = bookMess["author"]?.takeIf { it.length != tempFileName.length } ?: ""
} catch (e: Exception) {
name = tempFileName.replace(AppPattern.nameRegex, "")
author = tempFileName.replace(AppPattern.authorRegex, "")
name = BookHelp.formatBookName(tempFileName)
author = BookHelp.formatBookAuthor(tempFileName.replace(name, ""))
.takeIf { it.length != tempFileName.length } ?: ""
}
} else {
name = tempFileName.replace(AppPattern.nameRegex, "")
author = tempFileName.replace(AppPattern.authorRegex, "")
name = BookHelp.formatBookName(tempFileName)
author = BookHelp.formatBookAuthor(tempFileName.replace(name, ""))
.takeIf { it.length != tempFileName.length } ?: ""
}

Loading…
Cancel
Save