加入书名和作者处理

pull/300/head
gedoor 4 years ago
parent 39b111f94c
commit 4def397ab0
  1. 14
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 2
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  3. 4
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  4. 8
      app/src/main/java/io/legado/app/model/webBook/BookList.kt

@ -110,12 +110,16 @@ object BookHelp {
return folderName.replace("[\\\\/:*?\"<>|.]".toRegex(), "") return folderName.replace("[\\\\/:*?\"<>|.]".toRegex(), "")
} }
fun formatAuthor(author: String?): String { fun formatBookName(name: String): String {
return name
.replace("(.*?)\\s*作\\s*者.*".toRegex(), "$1")
.trim { it <= ' ' }
}
fun formatBookAuthor(author: String): String {
return author return author
?.replace("\\s*者\\s*[::]\n*".toRegex(), "") .replace(".*?作\\s*?者[::](.+)".toRegex(), "$1")
?.replace("\\s+".toRegex(), " ") .trim { it <= ' ' }
?.trim { it <= ' ' }
?: ""
} }
/** /**

@ -48,7 +48,7 @@ object LocalBook {
} else { } else {
name = str.substring(0, authorIndex) name = str.substring(0, authorIndex)
author = str.substring(authorIndex) author = str.substring(authorIndex)
author = BookHelp.formatAuthor(author) author = BookHelp.formatBookAuthor(author)
} }
val smhStart = name.indexOf("") val smhStart = name.indexOf("")
val smhEnd = name.indexOf("") val smhEnd = name.indexOf("")

@ -34,12 +34,12 @@ object BookInfo {
} }
} }
Debug.log(bookSource.bookSourceUrl, "┌获取书名") Debug.log(bookSource.bookSourceUrl, "┌获取书名")
analyzeRule.getString(infoRule.name).trim { it <= ' ' }.let { BookHelp.formatBookName(analyzeRule.getString(infoRule.name)).trim { it <= ' ' }.let {
if (it.isNotEmpty()) book.name = it if (it.isNotEmpty()) book.name = it
} }
Debug.log(bookSource.bookSourceUrl, "${book.name}") Debug.log(bookSource.bookSourceUrl, "${book.name}")
Debug.log(bookSource.bookSourceUrl, "┌获取作者") Debug.log(bookSource.bookSourceUrl, "┌获取作者")
BookHelp.formatAuthor(analyzeRule.getString(infoRule.author)).let { BookHelp.formatBookAuthor(analyzeRule.getString(infoRule.author)).let {
if (it.isNotEmpty()) book.author = it.replace(AppPattern.authorRegex, "") if (it.isNotEmpty()) book.author = it.replace(AppPattern.authorRegex, "")
} }
Debug.log(bookSource.bookSourceUrl, "${book.author}") Debug.log(bookSource.bookSourceUrl, "${book.author}")

@ -139,12 +139,12 @@ object BookList {
} }
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取书名") Debug.log(bookSource.bookSourceUrl, "┌获取书名")
searchBook.name = analyzeRule.getString(name).trim { it <= ' ' } searchBook.name = BookHelp.formatBookName(analyzeRule.getString(name))
Debug.log(bookSource.bookSourceUrl, "${searchBook.name}") Debug.log(bookSource.bookSourceUrl, "${searchBook.name}")
if (searchBook.name.isNotEmpty()) { if (searchBook.name.isNotEmpty()) {
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取作者") Debug.log(bookSource.bookSourceUrl, "┌获取作者")
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author)) searchBook.author = BookHelp.formatBookAuthor(analyzeRule.getString(author))
Debug.log(bookSource.bookSourceUrl, "${searchBook.author}") Debug.log(bookSource.bookSourceUrl, "${searchBook.author}")
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取分类") Debug.log(bookSource.bookSourceUrl, "┌获取分类")
@ -199,12 +199,12 @@ object BookList {
analyzeRule.setContent(item) analyzeRule.setContent(item)
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取书名", log) Debug.log(bookSource.bookSourceUrl, "┌获取书名", log)
searchBook.name = analyzeRule.getString(ruleName).trim { it <= ' ' } searchBook.name = BookHelp.formatBookName(analyzeRule.getString(ruleName))
Debug.log(bookSource.bookSourceUrl, "${searchBook.name}", log) Debug.log(bookSource.bookSourceUrl, "${searchBook.name}", log)
if (searchBook.name.isNotEmpty()) { if (searchBook.name.isNotEmpty()) {
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取作者", log) Debug.log(bookSource.bookSourceUrl, "┌获取作者", log)
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor)) searchBook.author = BookHelp.formatBookAuthor(analyzeRule.getString(ruleAuthor))
Debug.log(bookSource.bookSourceUrl, "${searchBook.author}", log) Debug.log(bookSource.bookSourceUrl, "${searchBook.author}", log)
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取分类", log) Debug.log(bookSource.bookSourceUrl, "┌获取分类", log)

Loading…
Cancel
Save