Merge pull request #931 from nobk/fn-split-1

从文件名'书名 by 作者.txt'或.epub提取书名、作者
pull/933/head
kunfei 4 years ago committed by GitHub
commit ea15014a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@ -72,6 +72,16 @@ object LocalBook {
if (smhStart != -1 && smhEnd != -1) {
name = (name.substring(smhStart + 1, smhEnd))
}
if (author == "" && fileName.contains(" by ")) {
val rstr = fileName.reversed()
// find last ' by ' near '.txt' or '.epub' using reversed string
val pattern = """^(txt|bupe)\.(.*) yb (.*)$""".toRegex()
val matches = pattern.findAll(input = rstr)
matches.forEach { matchResult ->
name = matchResult.groupValues[3].reversed()
author = matchResult.groupValues[2].reversed()
}
}
val book = Book(
bookUrl = path,
name = name,

Loading…
Cancel
Save