Update manga and API endpoints at Tsuki. (#5053)

This commit is contained in:
Alessandro Jean 2020-12-07 14:16:00 -03:00 committed by GitHub
parent b95fb4cb91
commit a8d25e4ca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 18 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Tsuki Mangás'
pkgNameSuffix = 'pt.tsukimangas'
extClass = '.TsukiMangas'
extVersionCode = 6
extVersionCode = 7
libVersion = '1.2'
}

View File

@ -65,7 +65,7 @@ class TsukiMangas : HttpSource() {
private fun popularMangaItemParse(obj: JsonObject) = SManga.create().apply {
title = obj["TITULO"].string
thumbnail_url = baseUrl + "/imgs/" + obj["CAPA"].string.substringBefore("?")
url = "/manga/" + obj["URL"].string
url = "/obra/${obj["ID"].int}/${obj["URL"].string}"
}
override fun latestUpdatesRequest(page: Int): Request {
@ -90,7 +90,7 @@ class TsukiMangas : HttpSource() {
private fun latestMangaItemParse(obj: JsonObject) = SManga.create().apply {
title = obj["TITULO"].string
thumbnail_url = baseUrl + "/imgs/" + obj["CAPA"].string
url = "/manga/" + obj["URL"].string
url = "/obra/${obj["ID"].int}/${obj["URL"].string}"
}
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
@ -122,6 +122,7 @@ class TsukiMangas : HttpSource() {
.addEncodedPathSegment(genreQuery)
.addPathSegment(page.toString())
.addEncodedPathSegment(pathQuery)
.addPathSegment("all")
.toString()
return GET(url, newHeaders)
@ -135,10 +136,7 @@ class TsukiMangas : HttpSource() {
val searchMangas = result.map { searchMangaItemParse(it.obj) }
val currentPage = response.request().url().toString()
.substringBeforeLast("/")
.substringAfterLast("/")
.toInt()
val currentPage = response.request().url().pathSegments()[3].toInt()
val lastPage = result[0].obj["page"].array[0].int
val hasNextPage = currentPage < lastPage
@ -148,7 +146,7 @@ class TsukiMangas : HttpSource() {
private fun searchMangaItemParse(obj: JsonObject) = SManga.create().apply {
title = obj["TITULO"].string
thumbnail_url = baseUrl + "/imgs/" + obj["CAPA"].string.substringBefore("?")
url = "/manga/" + obj["URL"].string
url = "/obra/${obj["ID"].int}/${obj["URL"].string}"
}
// Workaround to allow "Open in browser" use the real URL.
@ -165,9 +163,9 @@ class TsukiMangas : HttpSource() {
.set("Referer", baseUrl + manga.url)
.build()
val mangaSlug = manga.url.substringAfterLast("/")
val mangaId = manga.url.substringAfter("obra/").substringBefore("/")
return GET("$baseUrl/api/mangas/$mangaSlug", newHeaders)
return GET("$baseUrl/api/mangas/$mangaId", newHeaders)
}
override fun mangaDetailsRequest(manga: SManga): Request {
@ -185,7 +183,7 @@ class TsukiMangas : HttpSource() {
title = result["TITULO"].string
thumbnail_url = baseUrl + "/imgs/" + result["CAPA"].string.substringBefore("?")
description = result["SINOPSE"].string
status = SManga.ONGOING
status = result["STATUS"].string.toStatus()
author = result["AUTOR"].string
artist = result["ARTISTA"].string
genre = result["GENEROS"].string
@ -195,13 +193,13 @@ class TsukiMangas : HttpSource() {
override fun chapterListRequest(manga: SManga): Request = chapterListRequestPaginated(manga.url, 1)
private fun chapterListRequestPaginated(mangaUrl: String, page: Int): Request {
val slug = mangaUrl.substringAfterLast("/")
val mangaId = mangaUrl.substringAfter("obra/").substringBefore("/")
val newHeaders = headersBuilder()
.set("Referer", baseUrl + mangaUrl)
.build()
return GET("$baseUrl/api/capitulospag/$slug/DESC/$page", newHeaders)
return GET("$baseUrl/api/capitulospag/$mangaId/DESC/$page", newHeaders)
}
override fun chapterListParse(response: Response): List<SChapter> {
@ -211,14 +209,13 @@ class TsukiMangas : HttpSource() {
return emptyList()
val mangaUrl = response.request().header("Referer")!!.substringAfter(baseUrl)
val mangaSlug = mangaUrl.substringAfterLast("/")
var page = 1
val chapters = mutableListOf<SChapter>()
while (result.size() != 0) {
chapters += result
.map { chapterListItemParse(it.obj, mangaSlug) }
.map { chapterListItemParse(it.obj, mangaUrl) }
.toMutableList()
val newRequest = chapterListRequestPaginated(mangaUrl, ++page)
@ -228,13 +225,16 @@ class TsukiMangas : HttpSource() {
return chapters
}
private fun chapterListItemParse(obj: JsonObject, slug: String): SChapter = SChapter.create().apply {
private fun chapterListItemParse(obj: JsonObject, mangaUrl: String): SChapter = SChapter.create().apply {
val mangaId = mangaUrl.substringAfter("obra/").substringBefore("/")
val mangaSlug = mangaUrl.substringAfterLast("/")
name = "Cap. " + obj["NUMERO"].string +
(if (obj["TITULO"].string.isNotEmpty()) " - " + obj["TITULO"].string else "")
chapter_number = obj["NUMERO"].string.toFloatOrNull() ?: -1f
scanlator = obj["scans"].array.joinToString { it.obj["NOME"].string }
date_upload = obj["DATA"].string.substringBefore("T").toDate()
url = "/leitor/$slug/" + obj["NUMERO"].string
url = "/leitor/$mangaId/${obj["ID"].int}/$mangaSlug/${obj["NUMERO"].string}"
}
override fun pageListRequest(chapter: SChapter): Request {
@ -242,7 +242,10 @@ class TsukiMangas : HttpSource() {
.set("Referer", baseUrl + chapter.url)
.build()
return GET("$baseUrl/api" + chapter.url, newHeaders)
val mangaId = chapter.url.substringAfter("leitor/").substringBefore("/")
val chapterId = chapter.url.substringAfter("$mangaId/").substringBefore("/")
return GET("$baseUrl/api/leitor/$mangaId/$chapterId", newHeaders)
}
override fun pageListParse(response: Response): List<Page> {
@ -333,6 +336,12 @@ class TsukiMangas : HttpSource() {
}
}
private fun String.toStatus() = when {
contains("Ativo") -> SManga.ONGOING
contains("Completo") -> SManga.COMPLETED
else -> SManga.UNKNOWN
}
private fun Response.asJson(): JsonElement = JSON_PARSER.parse(body()!!.string())
companion object {