Use new API endpoints in TaoSect. (#9233)

This commit is contained in:
Alessandro Jean 2021-09-25 18:57:58 -03:00 committed by GitHub
parent 1c0db3b7f3
commit 2676b70068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 38 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Tao Sect' extName = 'Tao Sect'
pkgNameSuffix = 'pt.taosect' pkgNameSuffix = 'pt.taosect'
extClass = '.TaoSect' extClass = '.TaoSect'
extVersionCode = 10 extVersionCode = 11
containsNsfw = true containsNsfw = true
} }

View File

@ -276,36 +276,38 @@ class TaoSect : HttpSource() {
.substringAfterLast("projeto/") .substringAfterLast("projeto/")
.substringBefore("/") .substringBefore("/")
val apiUrl = "$baseUrl/$API_BASE_PATH/projetos".toHttpUrl().newBuilder() val apiUrl = "$baseUrl/$API_BASE_PATH/capitulos".toHttpUrl().newBuilder()
.addQueryParameter("per_page", "1") .addQueryParameter("projeto", projectSlug)
.addQueryParameter("slug", projectSlug) .addQueryParameter("per_page", "1000")
.addQueryParameter("order_vol", "desc") .addQueryParameter("order", "desc")
.addQueryParameter("order_cap", "desc") .addQueryParameter("orderby", "date")
.addQueryParameter("_fields", "id,slug,capitulos") .addQueryParameter("_fields", "nome_capitulo,post_id,slug,data_insercao")
.toString() .toString()
return GET(apiUrl, apiHeaders) return GET(apiUrl, apiHeaders)
} }
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val result = response.parseAs<List<TaoSectProjectDto>>() val result = response.parseAs<List<TaoSectChapterDto>>()
if (result.isNullOrEmpty()) { if (result.isNullOrEmpty()) {
throw Exception(PROJECT_NOT_FOUND) throw Exception(PROJECT_NOT_FOUND)
} }
val project = result[0] // Count the project views, requested by the scanlator.
val countViewRequest = countProjectViewRequest(result[0].projectId!!)
runCatching { client.newCall(countViewRequest).execute().close() }
return project.volumes!! val projectSlug = response.request.url.queryParameter("projeto")!!
.flatMap { it.chapters }
.map { chapterFromObject(it, project) } return result.map { chapterFromObject(it, projectSlug) }
} }
private fun chapterFromObject(obj: TaoSectChapterDto, project: TaoSectProjectDto): SChapter = SChapter.create().apply { private fun chapterFromObject(obj: TaoSectChapterDto, projectSlug: String): SChapter = SChapter.create().apply {
name = obj.name name = obj.name
scanlator = this@TaoSect.name scanlator = this@TaoSect.name
date_upload = obj.date.toDate() date_upload = obj.date.toDate()
url = "/leitor-online/projeto/${project.slug!!}/${obj.slug}/" url = "/leitor-online/projeto/$projectSlug/${obj.slug}/"
} }
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
@ -316,38 +318,29 @@ class TaoSect : HttpSource() {
.removeSuffix("/") .removeSuffix("/")
.substringAfterLast("/") .substringAfterLast("/")
val apiUrl = "$baseUrl/$API_BASE_PATH/projetos".toHttpUrl().newBuilder() val apiUrl = "$baseUrl/$API_BASE_PATH/capitulos/".toHttpUrl().newBuilder()
.addQueryParameter("per_page", "1") .addPathSegment(projectSlug)
.addQueryParameter("slug", projectSlug) .addPathSegment(chapterSlug)
.addQueryParameter("chapter_slug", chapterSlug) .addQueryParameter("_fields", "paginas")
.addQueryParameter("_fields", "slug,capitulos")
.toString() .toString()
return GET(apiUrl, apiHeaders) return GET(apiUrl, apiHeaders)
} }
override fun pageListParse(response: Response): List<Page> { override fun pageListParse(response: Response): List<Page> {
val result = response.parseAs<List<TaoSectProjectDto>>() val result = response.parseAs<TaoSectChapterDto>()
if (result.isNullOrEmpty()) { if (result.pages.isNullOrEmpty()) {
throw Exception(PROJECT_NOT_FOUND) return emptyList()
} }
val project = result[0] val apiUrlPaths = response.request.url.pathSegments
val chapterSlug = response.request.url.queryParameter("chapter_slug")!! val projectSlug = apiUrlPaths[4]
val chapterSlug = apiUrlPaths[5]
val chapter = project.volumes!! val chapterUrl = "$baseUrl/leitor-online/projeto/$projectSlug/$chapterSlug"
.flatMap { it.chapters }
.firstOrNull { it.slug == chapterSlug }
?: throw Exception(CHAPTER_NOT_FOUND)
val chapterUrl = "$baseUrl/leitor-online/projeto/${project.slug!!}/${chapter.slug}" val pages = result.pages.mapIndexed { i, pageUrl ->
// Count the chapter views, requested by the scanlator.
val countViewRequest = countChapterViewRequest(chapter.id)
runCatching { client.newCall(countViewRequest).execute().close() }
val pages = chapter.pages.mapIndexed { i, pageUrl ->
Page(i, chapterUrl, pageUrl) Page(i, chapterUrl, pageUrl)
} }
@ -382,10 +375,10 @@ class TaoSect : HttpSource() {
return GET(page.imageUrl!!, newHeaders) return GET(page.imageUrl!!, newHeaders)
} }
private fun countChapterViewRequest(chapterId: String): Request { private fun countProjectViewRequest(projectId: String): Request {
val formBody = FormBody.Builder() val formBody = FormBody.Builder()
.add("action", "update_views_v2") .add("action", "update_views_v2")
.add("capitulo", chapterId) .add("projeto", projectId)
.build() .build()
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
@ -493,7 +486,6 @@ class TaoSect : HttpSource() {
private const val DEFAULT_ORDERBY = 3 private const val DEFAULT_ORDERBY = 3
private const val DEFAULT_FIELDS = "title,thumbnail,link" private const val DEFAULT_FIELDS = "title,thumbnail,link"
private const val PROJECT_NOT_FOUND = "Projeto não encontrado." private const val PROJECT_NOT_FOUND = "Projeto não encontrado."
private const val CHAPTER_NOT_FOUND = "Capítulo não encontrado."
private const val EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT = "Limite de visualizações atingido " + private const val EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT = "Limite de visualizações atingido " +
"no Google Drive. Aguarde com que o limite seja reestabelecido." "no Google Drive. Aguarde com que o limite seja reestabelecido."