从文件名'书名 by 作者.txt'或.epub提取书名、作者

pull/931/head
no bk 4 years ago
parent c13dd1d371
commit 980c3e0b09
  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