From 4851bad1d67e802f4ee92b782359ece65d680449 Mon Sep 17 00:00:00 2001 From: Promchai Chooseang Date: Mon, 10 Jan 2022 23:58:35 +0700 Subject: [PATCH] Nekopost fix (#10423) * Add Cat300 Source * Fix Nekopost after old Api is Outdated --- .../extension/th/nekopost/Nekopost.kt | 61 ++++++++++++------- .../th/nekopost/model/RawChapterInfo.kt | 1 - .../th/nekopost/model/RawPageItem.kt | 4 +- .../th/nekopost/model/RawProjectCategory.kt | 8 +-- .../th/nekopost/model/RawProjectChapter.kt | 24 +++----- .../th/nekopost/model/RawProjectInfo.kt | 11 +++- .../th/nekopost/model/RawProjectInfoData.kt | 48 ++++++--------- .../th/nekopost/model/RawProjectSummary.kt | 30 +++------ .../nekopost/model/RawProjectSummaryList.kt | 4 +- 9 files changed, 87 insertions(+), 104 deletions(-) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt index 325293c8e..94b28341a 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt @@ -27,12 +27,12 @@ import java.util.Locale class Nekopost : ParsedHttpSource() { private val json: Json by injectLazy() - override val baseUrl: String = "https://www.nekopost.net/project" + override val baseUrl: String = "https://www.nekopost.net/manga/" private val latestMangaEndpoint: String = - "https://tuner.nekopost.net/ApiTest/getLatestChapterOffset/m" + "https://uatapi.nekopost.net/frontAPI/getLatestChapter/m" private val projectDataEndpoint: String = - "https://tuner.nekopost.net/ApiTest/getProjectDetailFull" + "https://uatapi.nekopost.net/frontAPI/getProjectInfo" private val fileHost: String = "https://fs.nekopost.net" override val client: OkHttpClient = network.cloudflareClient @@ -87,17 +87,20 @@ class Nekopost : ParsedHttpSource() { manga.apply { projectInfo.projectInfo.let { - url = it.npProjectId - title = it.npName + url = it.projectId + title = it.projectName artist = it.artistName author = it.authorName - description = it.npInfo - status = getStatus(it.npStatus) + description = it.info + status = getStatus(it.status) initialized = true } - genre = - projectInfo.projectCategoryUsed.joinToString(", ") { it.npcName } + genre = if (projectInfo.projectCategoryUsed != null) { + projectInfo.projectCategoryUsed.joinToString(", ") { it.categoryName } + } else { + "" + } } } } @@ -112,17 +115,24 @@ class Nekopost : ParsedHttpSource() { ?: throw Error("Unable to fetch manga detail of ${manga.title}") val projectInfo: RawProjectInfo = json.decodeFromString(responseBody.string()) - projectInfo.projectChapterList.map { chapter -> + manga.status = getStatus(projectInfo.projectInfo.status) + + if (manga.status == SManga.LICENSED) { + throw Exception("Licensed - No chapter to show") + } + + projectInfo.projectChapterList!!.map { chapter -> SChapter.create().apply { - url = "${manga.url}/${chapter.ncChapterId}/${chapter.ncDataFile}" - name = chapter.ncChapterName + url = + "${manga.url}/${chapter.chapterId}/${manga.url}_${chapter.chapterId}.json" + name = chapter.chapterName date_upload = SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale("th") - ).parse(chapter.ncCreatedDate)?.time + ).parse(chapter.createDate)?.time ?: 0L - chapter_number = chapter.ncChapterNo.toFloat() - scanlator = chapter.cuDisplayname + chapter_number = chapter.chapterNo.toFloat() + scanlator = chapter.providerName } } } @@ -141,10 +151,14 @@ class Nekopost : ParsedHttpSource() { val chapterInfo: RawChapterInfo = json.decodeFromString(responseBody.string()) chapterInfo.pageItem.map { page -> - val fileName = page.fileName ?: page.pageName + val imgUrl: String = if (page.pageName != null) { + "$fileHost/collectManga/${chapterInfo.projectId}/${chapterInfo.chapterId}/${page.pageName}" + } else { + "$fileHost/collectManga/${chapterInfo.projectId}/${chapterInfo.chapterId}/${page.fileName}" + } Page( index = page.pageNo, - imageUrl = "$fileHost/collectManga/${chapterInfo.projectId}/${chapterInfo.chapterId}/$fileName", + imageUrl = imgUrl ) } } @@ -163,14 +177,14 @@ class Nekopost : ParsedHttpSource() { val projectList: RawProjectSummaryList = json.decodeFromString(responseBody.string()) val mangaList: List = - projectList.listItem - ?.filter { !existingProject.contains(it.npProjectId) } + projectList.listChapter + ?.filter { !existingProject.contains(it.projectId) } ?.map { SManga.create().apply { - url = it.npProjectId - title = it.npName + url = it.projectId + title = it.projectName thumbnail_url = - "$fileHost/collectManga/${it.npProjectId}/${it.npProjectId}_cover.jpg" + "$fileHost/collectManga/${it.projectId}/${it.projectId}_cover.jpg" initialized = false status = 0 } @@ -201,7 +215,8 @@ class Nekopost : ParsedHttpSource() { .asObservableSuccess() .map { response -> val responseBody = response.body ?: throw Error("Unable to fetch title list") - val projectList: List = json.decodeFromString(responseBody.string()) + val projectList: List = + json.decodeFromString(responseBody.string()) val mangaList: List = projectList.filter { project -> Regex( diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt index 64f2b54dd..762f0ccc1 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt @@ -6,7 +6,6 @@ import kotlinx.serialization.Serializable data class RawChapterInfo( val chapterId: Int, val chapterNo: String, - val pageCount: Int, val pageItem: List, val projectId: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt index a126e120d..11c029642 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt @@ -4,10 +4,8 @@ import kotlinx.serialization.Serializable @Serializable data class RawPageItem( - val id: Int? = null, - // workaround for https://github.com/Kotlin/kotlinx.serialization/pull/1473 - val fileName: String? = null, val pageName: String? = null, + val fileName: String? = null, val height: Int, val pageNo: Int, val width: Int diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt index ad228f5bb..f7005bdf9 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt @@ -5,8 +5,8 @@ import kotlinx.serialization.Serializable @Serializable data class RawProjectCategory( - @SerialName("npc_name") - val npcName: String, - @SerialName("npc_name_link") - val npcNameLink: String + @SerialName("cateName") + val categoryName: String, + @SerialName("cateLink") + val categoryLink: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt index fcaeb1823..fd4919f96 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt @@ -1,24 +1,14 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class RawProjectChapter( - @SerialName("cu_displayname") - val cuDisplayname: String, - @SerialName("nc_chapter_id") - val ncChapterId: String, - @SerialName("nc_chapter_name") - val ncChapterName: String, - @SerialName("nc_chapter_no") - val ncChapterNo: String, - @SerialName("nc_created_date") - val ncCreatedDate: String, - @SerialName("nc_data_file") - val ncDataFile: String, - @SerialName("nc_owner_id") - val ncOwnerId: String, - @SerialName("nc_provider") - val ncProvider: String + val chapterId: String?, + val chapterNo: String, + val chapterName: String, + val status: String, + val publishDate: String, + val createDate: String, + val providerName: String, ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt index 5649231e9..85730eaa4 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt @@ -1,11 +1,16 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class RawProjectInfo( - val code: String, - val projectCategoryUsed: List, - val projectChapterList: List, + @SerialName("code") + val code: Int, + @SerialName("listCate") + val projectCategoryUsed: List?, + @SerialName("listChapter") + val projectChapterList: List?, + @SerialName("projectInfo") val projectInfo: RawProjectInfoData ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt index e83720ac4..b7be57d52 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt @@ -5,34 +5,24 @@ import kotlinx.serialization.Serializable @Serializable data class RawProjectInfoData( - @SerialName("artist_name") - val artistName: String, - @SerialName("author_name") + @SerialName("projectId") + val projectId: String, + @SerialName("projectName") + val projectName: String, + @SerialName("aliasName") + val aliasName: String, + @SerialName("website") + val website: String, + @SerialName("authorName") val authorName: String, - @SerialName("np_comment") - val npComment: String, - @SerialName("np_created_date") - val npCreatedDate: String, - @SerialName("np_flag_mature") - val npFlagMature: String, - @SerialName("np_info") - val npInfo: String, - @SerialName("np_licenced_by") - val npLicencedBy: String, - @SerialName("np_name") - val npName: String, - @SerialName("np_name_link") - val npNameLink: String, - @SerialName("np_project_id") - val npProjectId: String, - @SerialName("np_status") - val npStatus: String, - @SerialName("np_type") - val npType: String, - @SerialName("np_updated_date") - val npUpdatedDate: String, - @SerialName("np_view") - val npView: String, - @SerialName("np_web") - val npWeb: String + @SerialName("artistName") + val artistName: String, + @SerialName("info") + val info: String, + @SerialName("status") + val status: String, + @SerialName("flgMature") + val flgMature: String, + @SerialName("releaseDate") + val releaseDate: String, ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt index d69feaa88..ec04afbf0 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt @@ -1,30 +1,16 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class RawProjectSummary( - @SerialName("nc_chapter_cover") - val ncChapterCover: String, - @SerialName("nc_chapter_id") - val ncChapterId: String, - @SerialName("nc_chapter_name") - val ncChapterName: String, - @SerialName("nc_chapter_no") - val ncChapterNo: String, - @SerialName("nc_created_date") - val ncCreatedDate: String, - @SerialName("nc_provider") - val ncProvider: String, - @SerialName("no_new_chapter") + val cover: String, + val chapterId: String, + val chapterName: String, + val chapterNo: String, + val createDate: String, + val providerName: String, val noNewChapter: String, - @SerialName("np_group_dir") - val npGroupDir: String, - @SerialName("np_name") - val npName: String, - @SerialName("np_name_link") - val npNameLink: String, - @SerialName("np_project_id") - val npProjectId: String + val projectName: String, + val projectId: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt index eb4d58d4f..5c1500c61 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable @Serializable data class RawProjectSummaryList( - val code: String, - val listItem: List? + val code: Int, + val listChapter: List? )