Add okio deps & Create ScriptLineData
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package yenru0.yrkaier.nue.data
|
||||
|
||||
import kotlinx.datetime.LocalDate
|
||||
import okio.Path
|
||||
|
||||
|
||||
data class NovelInfo(
|
||||
val id: Int,
|
||||
@@ -18,3 +20,13 @@ data class EpisodeInfo(
|
||||
val title: String,
|
||||
val uploadDate: LocalDate
|
||||
)
|
||||
|
||||
sealed class ScriptLineData {
|
||||
data class Html(
|
||||
val html: String
|
||||
) : ScriptLineData()
|
||||
|
||||
data class Image(
|
||||
val path: String
|
||||
) : ScriptLineData()
|
||||
}
|
||||
@@ -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<ScriptLineData> {
|
||||
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<ScriptLineData> = 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
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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" }
|
||||
|
||||
Reference in New Issue
Block a user