Skip to content

Commit

Permalink
Merge pull request #144 from dmzz-yyhyy/bug_fix
Browse files Browse the repository at this point in the history
修复Bug,扩展数据结构
  • Loading branch information
dmzz-yyhyy authored Jan 14, 2025
2 parents 30c7ace + 794c8c7 commit c580b70
Show file tree
Hide file tree
Showing 21 changed files with 388 additions and 294 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
// 版本号为x.y.z则versionCode为x*1000000+y*10000+z*100+debug版本号(开发需要时迭代, 两位数)
versionCode = 1_00_00_021
versionCode = 1_00_00_022
versionName = "1.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.time.LocalDateTime
data class BookInformation(
val id: Int,
val title: String,
val subtitle: String,
val coverUrl: String,
val author: String,
val description: String,
Expand All @@ -20,6 +21,7 @@ data class BookInformation(
fun empty(): BookInformation = BookInformation(
-1,
"",
"",
"",
"",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package indi.dmzz_yyhyy.lightnovelreader.data.exploration
data class ExplorationDisplayBook(
val id: Int,
val title: String,
val author: String,
val coverUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import indi.dmzz_yyhyy.lightnovelreader.data.local.room.entity.VolumeEntity
BookshelfEntity::class,
BookshelfBookMetadataEntity::class,
],
version = 9,
version = 10,
exportSchema = false
)
abstract class LightNovelReaderDatabase : RoomDatabase() {
Expand All @@ -55,7 +55,7 @@ abstract class LightNovelReaderDatabase : RoomDatabase() {
context.applicationContext,
LightNovelReaderDatabase::class.java,
"light_novel_reader_database")
.addMigrations(MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9)
.addMigrations(MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9, MIGRATION_9_10)
.allowMainThreadQueries()
.build()
INSTANCE = instance
Expand Down Expand Up @@ -111,5 +111,24 @@ abstract class LightNovelReaderDatabase : RoomDatabase() {
"add read_completed_chapter_ids text default '' not null")
}
}

private val MIGRATION_9_10 = object : Migration(9, 10) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("drop table book_information")
db.execSQL( "create table book_information (" +
"id INTEGER NOT NULL," +
"title TEXT NOT NULL, " +
"subtitle TEXT NOT NULL, " +
"cover_url TEXT NOT NULL, " +
"author TEXT NOT NULL, " +
"description TEXT NOT NULL, " +
"tags TEXT NOT NULL, " +
"publishing_house TEXT NOT NULL, " +
"word_count INTEGER NOT NULL," +
"last_update TEXT NOT NULL, " +
"is_complete INTEGER NOT NULL, " +
"PRIMARY KEY(id))" )
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import java.time.LocalDateTime
@Dao
interface BookInformationDao {
@TypeConverters(LocalDataTimeConverter::class)
@Query("replace into book_information (id, title, cover_url, author, description, tags, publishing_house, word_count, last_update, is_complete) " +
"values (:id, :title, :coverUrl, :author, :description, :tags, :publishingHouse, :wordCount, :lastUpdated, :isComplete) ")
@Query("replace into book_information (id, title, subtitle, cover_url, author, description, tags, publishing_house, word_count, last_update, is_complete) " +
"values (:id, :title, :subtitle, :coverUrl, :author, :description, :tags, :publishingHouse, :wordCount, :lastUpdated, :isComplete) ")
fun update(id: Int,
title: String,
subtitle: String,
coverUrl: String,
author: String,
description: String,
Expand All @@ -31,6 +32,7 @@ interface BookInformationDao {
return update(
information.id,
information.title,
information.subtitle,
information.coverUrl,
information.author,
information.description,
Expand All @@ -51,6 +53,7 @@ interface BookInformationDao {
return BookInformation(
entity.id,
entity.title,
entity.subtitle,
entity.coverUrl,
entity.author,
entity.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class BookInformationEntity(
@PrimaryKey
val id: Int,
val title: String,
val subtitle: String,
@ColumnInfo(name = "cover_url")
val coverUrl: String,
val author: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sealed class UserDataPath(
data object IsUsingFlipPage : UserDataPath("isUsingFlipPage", Reader)
data object IsUsingClickFlipPage : UserDataPath("isUsingClickFlipPage", Reader)
data object IsUsingVolumeKeyFlip : UserDataPath("isUsingVolumeKeyFlip", Reader)
data object IsUsingFlipAnime : UserDataPath("isUsingFlipAnime", Reader)
data object FlipAnime : UserDataPath("flipAnime", Reader)
data object FastChapterChange : UserDataPath("fastChapterChange", Reader)
data object EnableBatteryIndicator : UserDataPath("enableBatteryIndicator", Reader)
data object EnableTimeIndicator : UserDataPath("enableTimeIndicator", Reader)
Expand Down Expand Up @@ -61,11 +61,3 @@ sealed class UserDataPath(
}
}

open class LinkUserData(
private val userDataPath: UserDataPath
): UserDataPath("") {
override val path: String
get() = userDataPath.path
override val groupChildrenPath = userDataPath.groupChildrenPath
override val groupChildren = userDataPath.groupChildren
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import indi.dmzz_yyhyy.lightnovelreader.data.web.wenku8.exploration.expanedpage.
import indi.dmzz_yyhyy.lightnovelreader.data.web.wenku8.exploration.expanedpage.filter.FirstLetterSingleChoiceFilter
import indi.dmzz_yyhyy.lightnovelreader.data.web.wenku8.exploration.expanedpage.filter.PublishingHouseSingleChoiceFilter
import indi.dmzz_yyhyy.lightnovelreader.utils.update
import java.net.URLEncoder
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand All @@ -34,13 +30,18 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.jsoup.Jsoup
import org.jsoup.select.Elements
import java.net.URLEncoder
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

object Wenku8Api: WebBookDataSource {
private var allBookChapterListCacheId: Int = -1
private var allBookChapterListCache: List<ChapterInformation> = emptyList()
private val DATA_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd")
private val explorationExpandedPageDataSourceMap = mutableMapOf<String, ExplorationExpandedPageDataSource>()
private var coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
private val titleRegex = Regex("(.*) ?[((](.*)[))] ?$")

override val isOffLineFlow = flow {
while(true) {
Expand Down Expand Up @@ -72,9 +73,12 @@ object Wenku8Api: WebBookDataSource {
override fun getBookInformation(id: Int): BookInformation {
if (isAppDataSourceOffLine()) return BookInformation.empty()
return wenku8Api("action=book&do=meta&aid=$id&t=0")?.let {
val titleGroup = it.selectFirst("[name=Title]")?.text()
?.let { it1 -> titleRegex.find(it1)?.groups }
BookInformation(
id = id,
title = it.selectFirst("[name=Title]")?.text() ?: "",
title = titleGroup?.get(1)?.value ?: it.selectFirst("[name=Title]")?.text() ?: "",
subtitle = titleGroup?.get(2)?.value ?: "",
coverUrl = "https://img.wenku8.com/image/${id/1000}/$id/${id}s.jpg",
author = it.selectFirst("[name=Author]")?.attr("value") ?: "",
description = wenku8Api("action=book&do=intro&aid=$id&t=0")?.text() ?: "",
Expand Down Expand Up @@ -226,15 +230,19 @@ object Wenku8Api: WebBookDataSource {
?.replace(".htm", "")
?.toInt() ?: -1
)
else
else {
val titleGroup = element.selectFirst("div > div:nth-child(1) > a")
?.attr("title")
?.let { it1 -> titleRegex.find(it1)?.groups }
BookInformation(
id = element.selectFirst("div > div:nth-child(1) > a")
?.attr("href")
?.replace("/book/", "")
?.replace(".htm", "")
?.toInt() ?: -1,
title = element.selectFirst("div > div:nth-child(1) > a")
title = titleGroup?.get(1)?.value ?: element.selectFirst("div > div:nth-child(1) > a")
?.attr("title") ?: "",
subtitle = titleGroup?.get(2)?.value ?: "",
coverUrl = element.selectFirst("div > div:nth-child(1) > a > img")
?.attr("src") ?: "",
author = element.selectFirst("div > div:nth-child(2) > p:nth-child(2)")
Expand All @@ -261,6 +269,7 @@ object Wenku8Api: WebBookDataSource {
isComplete = element.selectFirst("div > div:nth-child(2) > p:nth-child(3)")
?.text()?.split("/")?.getOrNull(2) == "已完结"
)
}
}

private fun registerExplorationExpandedPageDataSource(id: String, expandedPageDataSource: ExplorationExpandedPageDataSource) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ object Wenku8AllExplorationPage: ExplorationPageDataSource {
val titleList = soup?.select("#content > table.grid > tbody > tr > td > div > div:nth-child(2) > b > a")
?.slice(0..5)
?.map { it.text().split("(").getOrNull(0) ?: "" } ?: emptyList()
val authorList = soup?.select("#content > table.grid > tbody > tr > td > div > div:nth-child(2) > p:nth-child(2)")
?.slice(0..5)
?.map { it.text().split("/").getOrNull(0)?.split(":")?.get(1) ?: ""} ?: emptyList()
val coverUrlList = soup?.select("#content > table.grid > tbody > tr > td > div > div:nth-child(1) > a > img")
?.slice(0..5)
?.map { it.attr("src") } ?: emptyList()
Expand All @@ -91,6 +94,7 @@ object Wenku8AllExplorationPage: ExplorationPageDataSource {
ExplorationDisplayBook(
id = idlList[it],
title = titleList[it],
author = authorList[it],
coverUrl = coverUrlList[it],
)
} ?: emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object Wenku8HomeExplorationPage: ExplorationPageDataSource {
ExplorationDisplayBook(
id = idlList[it],
title = titleList[it],
author = "",
coverUrl = coverUrlList[it],
)
} ?: emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import indi.dmzz_yyhyy.lightnovelreader.data.exploration.ExplorationBooksRow
import indi.dmzz_yyhyy.lightnovelreader.data.exploration.ExplorationDisplayBook
import indi.dmzz_yyhyy.lightnovelreader.data.exploration.ExplorationPage
import indi.dmzz_yyhyy.lightnovelreader.data.web.exploration.ExplorationPageDataSource
import indi.dmzz_yyhyy.lightnovelreader.utils.autoReconnectionGet
import indi.dmzz_yyhyy.lightnovelreader.data.web.wenku8.wenku8Cookie
import java.net.URLEncoder
import indi.dmzz_yyhyy.lightnovelreader.utils.autoReconnectionGet
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import java.net.URLEncoder

object Wenku8TagsExplorationPage: ExplorationPageDataSource {
private var lock = false
Expand Down Expand Up @@ -60,6 +60,9 @@ object Wenku8TagsExplorationPage: ExplorationPageDataSource {
.map { it.attr("href").replace("/book/", "").replace(".htm", "").toInt() }
val titleList = soup.select("#content > table > tbody > tr:nth-child(2) > td > div > div:nth-child(2) > b > a")
.map { it.text().split("(").getOrNull(0) ?: "" }
val authorList = soup.select("#content > table > tbody > tr:nth-child(2) > td > div > div:nth-child(2) > p:nth-child(2)")
.slice(0..5)
.map { it.text().split("/").getOrNull(0)?.split(":")?.get(1) ?: ""}
val coverUrlList = soup.select("#content > table > tbody > tr:nth-child(2) > td > div > div:nth-child(1) > a > img")
.map { it.attr("src") }
return ExplorationBooksRow(
Expand All @@ -68,6 +71,7 @@ object Wenku8TagsExplorationPage: ExplorationPageDataSource {
ExplorationDisplayBook(
id = idlList[it],
title = titleList[it],
author = authorList[it],
coverUrl = coverUrlList[it],
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ object RecommendExplorationPageDataSource : ExplorationPageDataSource {
val books = recommendData.data.mapNotNull {
if (it.type != 1) return@mapNotNull null
val coverSize = getImageSize(it.cover) ?: return@mapNotNull null
if (coverSize.width > coverSize.height )
return@mapNotNull ExplorationDisplayBook(it.id, it.title, getBookInformation(it.id)?.coverUrl ?: return@mapNotNull null)
ExplorationDisplayBook(it.id, it.title, it.cover)
if (coverSize.width > coverSize.height ) {
val bookInformation = getBookInformation(it.id) ?: return@mapNotNull null
return@mapNotNull ExplorationDisplayBook(
it.id,
it.title,
"",
bookInformation.coverUrl
)
}
ExplorationDisplayBook(it.id, it.title, "", it.cover)
}
if (books.isEmpty()) return@forEach
explorationBooksRows.update {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import indi.dmzz_yyhyy.lightnovelreader.data.exploration.ExplorationPage
import indi.dmzz_yyhyy.lightnovelreader.data.web.exploration.ExplorationPageDataSource
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.ZaiComic
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.ZaiComic.HOST
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.DataContent
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.TagTypeItem
import indi.dmzz_yyhyy.lightnovelreader.utils.autoReconnectionGetJsonText
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.DataContent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -65,7 +65,7 @@ object TypesExplorationPageDataSource : ExplorationPageDataSource {
}
.data
.comicList
.map { ExplorationDisplayBook(it.id, it.title, it.cover) }
.map { ExplorationDisplayBook(it.id, it.title, "", it.cover) }

private data class ComicList<T> (@SerializedName("comicList") val comicList: List<T>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import indi.dmzz_yyhyy.lightnovelreader.data.exploration.ExplorationPage
import indi.dmzz_yyhyy.lightnovelreader.data.web.exploration.ExplorationPageDataSource
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.ZaiComic
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.ZaiComic.HOST
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.DataContent
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.UpdatePageItem
import indi.dmzz_yyhyy.lightnovelreader.utils.autoReconnectionGetJsonText
import indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.DataContent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -64,6 +64,6 @@ object UpdateExplorationPageDataSource : ExplorationPageDataSource {
}
.data
.map {
ExplorationDisplayBook(it.id, it.title, it.cover)
ExplorationDisplayBook(it.id, it.title, "", it.cover)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import indi.dmzz_yyhyy.lightnovelreader.data.book.ChapterInformation
import indi.dmzz_yyhyy.lightnovelreader.data.book.Volume
import java.time.Instant
import java.time.LocalDateTime
import java.util.*
import java.util.TimeZone

data class DetailData(
@SerializedName("id")
Expand Down Expand Up @@ -41,6 +41,7 @@ data class DetailData(
BookInformation(
id = id,
title = title,
subtitle = "",
coverUrl = cover,
author = try { authors.joinToString(" ") { it.name } } catch (e: NullPointerException) { "" },
description = description,
Expand Down
Loading

0 comments on commit c580b70

Please sign in to comment.