|
|
|
@ -7,21 +7,17 @@ import com.script.SimpleBindings |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
|
import io.legado.app.data.appDb |
|
|
|
|
import io.legado.app.data.entities.BaseSource |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
|
import io.legado.app.data.entities.BaseSource |
|
|
|
|
import io.legado.app.exception.TocEmptyException |
|
|
|
|
import io.legado.app.exception.NoStackTraceException |
|
|
|
|
import io.legado.app.exception.TocEmptyException |
|
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
|
import io.legado.app.help.config.AppConfig |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import splitties.init.appCtx |
|
|
|
|
import java.io.File |
|
|
|
|
import java.io.FileInputStream |
|
|
|
|
import java.io.FileOutputStream |
|
|
|
|
import java.io.FileNotFoundException |
|
|
|
|
import java.io.InputStream |
|
|
|
|
import java.io.* |
|
|
|
|
import java.util.regex.Pattern |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -50,6 +46,20 @@ object LocalBook { |
|
|
|
|
throw FileNotFoundException("${uri.path} 文件不存在") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getLastModified(book: Book): Result<Long> { |
|
|
|
|
return kotlin.runCatching { |
|
|
|
|
val uri = Uri.parse(book.bookUrl) |
|
|
|
|
if (uri.isContentScheme()) { |
|
|
|
|
return@runCatching DocumentFile.fromSingleUri(appCtx, uri)!!.lastModified() |
|
|
|
|
} |
|
|
|
|
val file = File(uri.path!!) |
|
|
|
|
if (file.exists()) { |
|
|
|
|
return@runCatching File(uri.path!!).lastModified() |
|
|
|
|
} |
|
|
|
|
throw FileNotFoundException("${uri.path} 文件不存在") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
|
fun getChapterList(book: Book): ArrayList<BookChapter> { |
|
|
|
|
val chapters = when { |
|
|
|
@ -228,7 +238,7 @@ object LocalBook { |
|
|
|
|
val lastPath = urlNoOption.substringAfterLast("/") |
|
|
|
|
val fileType = lastPath.substringAfterLast(".") |
|
|
|
|
val type = analyzeUrl.type |
|
|
|
|
return type ?: fileType ?: "unknown" |
|
|
|
|
return type ?: fileType |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun saveBookFile( |
|
|
|
@ -262,13 +272,13 @@ object LocalBook { |
|
|
|
|
//文件类书源 合并在线书籍信息 在线 > 本地 |
|
|
|
|
fun mergeBook(localBook: Book, onLineBook: Book?): Book { |
|
|
|
|
onLineBook ?: return localBook |
|
|
|
|
val mergeBook = localBook |
|
|
|
|
mergeBook.name = if (onLineBook.name.isBlank()) localBook.name else onLineBook.name |
|
|
|
|
mergeBook.author = if (onLineBook.author.isBlank()) localBook.author else onLineBook.author |
|
|
|
|
mergeBook.coverUrl = onLineBook.coverUrl |
|
|
|
|
mergeBook.intro = if (onLineBook.intro.isNullOrBlank()) localBook.intro else onLineBook.intro |
|
|
|
|
mergeBook.save() |
|
|
|
|
return mergeBook |
|
|
|
|
localBook.name = onLineBook.name.ifBlank { localBook.name } |
|
|
|
|
localBook.author = onLineBook.author.ifBlank { localBook.author } |
|
|
|
|
localBook.coverUrl = onLineBook.coverUrl |
|
|
|
|
localBook.intro = |
|
|
|
|
if (onLineBook.intro.isNullOrBlank()) localBook.intro else onLineBook.intro |
|
|
|
|
localBook.save() |
|
|
|
|
return localBook |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|