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

Loading…
Cancel
Save