From 58f7a22aef67be03a63524dec62fbb31995d51bcc01492c2e7134c01b5bc522b Mon Sep 17 00:00:00 2001 From: yenru0 Date: Sat, 7 Mar 2026 03:56:19 +0900 Subject: [PATCH] Add okio deps & Create ScriptLineData --- composeApp/build.gradle.kts | 1 + .../kotlin/yenru0/yrkaier/nue/data/Info.kt | 14 +++++++++++- .../yenru0/yrkaier/nue/data/NpiaDownloader.kt | 22 ++++++++++++++++--- .../yenru0/yrkaier/nue/data/NpiaTest.kt | 18 ++++++++++----- gradle/libs.versions.toml | 3 ++- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 5df2dba..929f33e 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -38,6 +38,7 @@ kotlin { implementation(libs.ktor.serialization.kotlinx.json) implementation(libs.ksoup) implementation(libs.kotlinx.datetime) + implementation(libs.okio) } commonTest.dependencies { implementation(libs.kotlin.test) diff --git a/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/Info.kt b/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/Info.kt index 509393d..96f75c3 100644 --- a/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/Info.kt +++ b/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/Info.kt @@ -1,6 +1,8 @@ package yenru0.yrkaier.nue.data import kotlinx.datetime.LocalDate +import okio.Path + data class NovelInfo( val id: Int, @@ -17,4 +19,14 @@ data class EpisodeInfo( val episodeId: Int, val title: String, val uploadDate: LocalDate -) \ No newline at end of file +) + +sealed class ScriptLineData { + data class Html( + val html: String + ) : ScriptLineData() + + data class Image( + val path: String + ) : ScriptLineData() +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/NpiaDownloader.kt b/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/NpiaDownloader.kt index 7e50012..43449ee 100644 --- a/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/NpiaDownloader.kt +++ b/composeApp/src/commonMain/kotlin/yenru0/yrkaier/nue/data/NpiaDownloader.kt @@ -184,11 +184,27 @@ class NpiaDownloader { return episodeList } - suspend fun downloadEpisode(novelId: Int, episodeId: Int) { - client.request("https://novelpia.com/novel/$novelId") { + suspend fun downloadEpisode(episodeId: Int): List { + val res = client.request("https://novelpia.com/novel/viewer/$episodeId") { header(HttpHeaders.Cookie, "LOGINKEY=$loginkey") } + if (!res.status.isSuccess()) { + throw Exception("Failed to fetch episode content: ${res.status}") + } + println(res.bodyAsText()) + return listOf() + val document = Ksoup.parse(res.bodyAsText()) + val draw = document.select("#novel_drawing").first()!!; + val lines: List = draw.select(".line").map { + val imgsel = it.select("img") + if (imgsel.isNotEmpty()) { + val imageUrl = imgsel[0].attr("abs:src").ifEmpty { imgsel[0].attr("src") } + ScriptLineData.Image(imageUrl) + } else { + ScriptLineData.Html(it.html()) + } + } - + return lines } } \ No newline at end of file diff --git a/composeApp/src/commonTest/kotlin/yenru0/yrkaier/nue/data/NpiaTest.kt b/composeApp/src/commonTest/kotlin/yenru0/yrkaier/nue/data/NpiaTest.kt index e41be89..0cc8be6 100644 --- a/composeApp/src/commonTest/kotlin/yenru0/yrkaier/nue/data/NpiaTest.kt +++ b/composeApp/src/commonTest/kotlin/yenru0/yrkaier/nue/data/NpiaTest.kt @@ -4,12 +4,10 @@ import kotlinx.coroutines.runBlocking import kotlin.test.Test -const email = "" -const passwd = "" +const val email: String = "" +const val passwd: String = "" class NpiaTest { - - @Test fun testGetSession() { if (email.isEmpty() || passwd.isEmpty()) { @@ -25,6 +23,7 @@ class NpiaTest { println("Login failed") return@runBlocking } + /* val id = 396851 val info = downloader.getNovelInfo(id) val eps = downloader.getAllEpisodeList(id) @@ -38,9 +37,16 @@ class NpiaTest { for (ep in eps) { println("epid: ${ep.episodeId}, title: ${ep.title}, date: ${ep.uploadDate}") } + + */ + + val scripts = downloader.downloadEpisode(5221545) + + for (line in scripts) { + println(line) + } + downloader.logout() } - - } } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 98d87ad..58beac0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ material3 = "1.10.0-alpha05" ktor = "3.4.0" ksoup = "0.2.6" junitJupiter = "5.14.0" +okio = "3.16.2" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -46,7 +47,7 @@ ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negoti ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } ksoup = { module = "com.fleeksoft.ksoup:ksoup", version.ref = "ksoup" } junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junitJupiter" } - +okio = { module = "com.squareup.okio:okio", version.ref = "okio" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" }