Terra Historicus source (#11842)

* Terra Historicus source

* Terra Historicus: use English for extension name
This commit is contained in:
kasperskier 2022-05-14 02:53:02 +08:00 committed by GitHub
parent e679306cd7
commit 819108ff03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 170 additions and 0 deletions

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="eu.kanade.tachiyomi.extension" />

View File

@ -0,0 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
ext {
extName = 'Terra Historicus'
pkgNameSuffix = 'zh.terrahistoricus'
extClass = '.TerraHistoricus'
extVersionCode = 1
}
apply from: "$rootDir/common.gradle"

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -0,0 +1,63 @@
package eu.kanade.tachiyomi.extension.zh.terrahistoricus
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.injectLazy
class TerraHistoricus : HttpSource() {
override val name = "泰拉记事社"
override val lang = "zh"
override val baseUrl = "https://terra-historicus.hypergryph.com"
override val supportsLatest = true
private val json: Json by injectLazy()
override fun popularMangaRequest(page: Int) = GET("$baseUrl/api/comic")
override fun popularMangaParse(response: Response) = MangasPage(
json.decodeFromString<THResult<List<THComic>>>(response.body!!.string()).data.map(THComic::toSManga),
false
)
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/api/recentUpdate")
override fun latestUpdatesParse(response: Response) = MangasPage(
json.decodeFromString<THResult<List<THRecentUpdate>>>(response.body!!.string()).data.map(THRecentUpdate::toSManga),
false
)
override fun searchMangaRequest(page: Int, query: String, filters: FilterList) =
throw UnsupportedOperationException("没有搜索功能")
override fun searchMangaParse(response: Response) = throw UnsupportedOperationException("没有搜索功能")
override fun mangaDetailsParse(response: Response) =
json.decodeFromString<THResult<THComic>>(response.body!!.string()).data.toSManga()
override fun chapterListParse(response: Response) =
json.decodeFromString<THResult<THComic>>(response.body!!.string()).data.toSChapterList().orEmpty()
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
return client.newCall(pageListRequest(chapter))
.asObservableSuccess()
.map { response ->
(0 until json.decodeFromString<THResult<THEpisode>>(response.body!!.string()).data.pageInfos!!.size).map {
Page(it, "$baseUrl${chapter.url}/page?pageNum=${it + 1}")
}
}
}
override fun pageListParse(response: Response) = throw UnsupportedOperationException("Not used.")
override fun imageUrlParse(response: Response) =
json.decodeFromString<THResult<THPage>>(response.body!!.string()).data.url
}

View File

@ -0,0 +1,93 @@
package eu.kanade.tachiyomi.extension.zh.terrahistoricus
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.serialization.Serializable
@Serializable
data class THResult<T>(val code: Int, val msg: String, val data: T)
@Serializable
data class THComic(
val cid: String,
// val type: Int,
val cover: String,
val title: String,
val subtitle: String,
val authors: List<String>,
val keywords: List<String>? = null,
val introduction: String? = null,
// val direction: String? = null,
val episodes: List<THEpisode>? = null,
val updateTime: Long? = null, // timestamp in seconds
) {
private fun getDescription(): String? {
var result = ""
if (subtitle.isNotEmpty()) result += "$subtitle"
if (introduction != null) result += introduction
return result.ifEmpty { null }
}
fun toSManga() = SManga.create().apply {
url = "/api/comic/$cid"
title = this@THComic.title
author = authors.joinToString("")
thumbnail_url = cover
description = getDescription()
genre = keywords?.joinToString("")?.replace("", ", ")
}
fun toSChapterList() = episodes?.map { episode ->
SChapter.create().apply {
url = "/api/comic/$cid/episode/${episode.cid!!}"
try {
chapter_number = episode.shortTitle?.toFloat() ?: chapter_number
name = episode.title
} catch (e: NumberFormatException) {
name = "${episode.shortTitle} ${episode.title}"
}
date_upload = (updateTime ?: 0L) * 1000
}
}
}
@Serializable
data class THRecentUpdate(
val coverUrl: String,
val comicCid: String,
val title: String,
// val subtitle: String,
// val episodeCid: String,
// val episodeType: Int,
// val episodeShortTitle: String,
// val updateTime: Long
) {
fun toSManga() = SManga.create().apply {
url = "/api/comic/$comicCid"
title = this@THRecentUpdate.title
thumbnail_url = coverUrl
}
}
@Serializable
data class THEpisode(
val cid: String? = null,
// val type: Int,
val shortTitle: String?,
val title: String, // 作品信息中
// val likes: Int? = null,
val pageInfos: List<THPageInfo>? = null, // 章节详情中
)
@Serializable
data class THPageInfo(
// val width: Int,
// val height: Int,
val doublePage: Boolean,
)
@Serializable
data class THPage(
// val pageNum: Int,
val url: String,
)