MangAdventure: use the new API endpoints (#13165)

This commit is contained in:
ObserverOfTime 2022-08-24 23:44:39 +03:00 committed by GitHub
parent cef6535f6d
commit 09d8305b9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 48 deletions

View File

@ -38,15 +38,13 @@ abstract class MangAdventure(
"(Android ${VERSION.RELEASE}; Mobile) " + "(Android ${VERSION.RELEASE}; Mobile) " +
"Tachiyomi/${AppInfo.getVersionName()}" "Tachiyomi/${AppInfo.getVersionName()}"
/** The URI of the site's API. */ /** The URL of the site's API. */
private val apiUri by lazy { private val apiUrl by lazy { "$baseUrl/api/v2" }
Uri.parse("$baseUrl/api/v$versionId")!!
}
/** The JSON parser of the class. */ /** The JSON parser of the class. */
private val json by injectLazy<Json>() private val json by injectLazy<Json>()
override val versionId = 2 override val versionId = 3
override val supportsLatest = true override val supportsLatest = true
@ -54,21 +52,13 @@ abstract class MangAdventure(
super.headersBuilder().set("User-Agent", userAgent) super.headersBuilder().set("User-Agent", userAgent)
override fun latestUpdatesRequest(page: Int) = override fun latestUpdatesRequest(page: Int) =
apiUri.buildUpon().appendEncodedPath("series").run { GET("$apiUrl/series?page=$page&sort=-latest_upload", headers)
appendQueryParameter("page", page.toString())
appendQueryParameter("sort", "-latest_upload")
GET(toString(), headers)
}
override fun popularMangaRequest(page: Int) = override fun popularMangaRequest(page: Int) =
apiUri.buildUpon().appendEncodedPath("series").run { GET("$apiUrl/series?page=$page&sort=-views", headers)
appendQueryParameter("page", page.toString())
appendQueryParameter("sort", "-views")
GET(toString(), headers)
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = override fun searchMangaRequest(page: Int, query: String, filters: FilterList) =
apiUri.buildUpon().appendEncodedPath("series").run { Uri.parse(apiUrl).buildUpon().appendEncodedPath("series").run {
if (query.startsWith(SLUG_QUERY)) { if (query.startsWith(SLUG_QUERY)) {
appendQueryParameter("slug", query.substring(SLUG_QUERY.length)) appendQueryParameter("slug", query.substring(SLUG_QUERY.length))
} else { } else {
@ -82,21 +72,10 @@ abstract class MangAdventure(
} }
override fun chapterListRequest(manga: SManga) = override fun chapterListRequest(manga: SManga) =
apiUri.buildUpon().appendEncodedPath("chapters").run { GET("$apiUrl/series/${manga.url}/chapters?date_format=timestamp", headers)
appendQueryParameter("series", manga.slug)
appendQueryParameter("date_format", "timestamp")
GET(toString(), headers)
}
override fun pageListRequest(chapter: SChapter) = override fun pageListRequest(chapter: SChapter) =
apiUri.buildUpon().appendEncodedPath("pages").run { GET("$apiUrl/chapters/${chapter.url}/pages?track=true", headers)
val (slug, vol, num) = chapter.components
appendQueryParameter("track", "true")
appendQueryParameter("series", slug)
appendQueryParameter("volume", vol)
appendQueryParameter("number", num)
GET(toString(), headers)
}
override fun latestUpdatesParse(response: Response) = override fun latestUpdatesParse(response: Response) =
response.decode<Paginator<Series>>().let { response.decode<Paginator<Series>>().let {
@ -112,7 +91,7 @@ abstract class MangAdventure(
override fun chapterListParse(response: Response) = override fun chapterListParse(response: Response) =
response.decode<Results<Chapter>>().map { chapter -> response.decode<Results<Chapter>>().map { chapter ->
SChapter.create().apply { SChapter.create().apply {
url = chapter.url url = chapter.id.toString()
name = buildString { name = buildString {
append(chapter.full_title) append(chapter.full_title)
if (chapter.final) append(" [END]") if (chapter.final) append(" [END]")
@ -133,11 +112,11 @@ abstract class MangAdventure(
// Return the real URL for "Open in browser" // Return the real URL for "Open in browser"
override fun mangaDetailsRequest(manga: SManga) = override fun mangaDetailsRequest(manga: SManga) =
GET(baseUrl + manga.url, headers) GET("$baseUrl/reader/${manga.url}", headers)
// Workaround to allow "Open in browser" to use the real URL // Workaround to allow "Open in browser" to use the real URL
override fun fetchMangaDetails(manga: SManga) = override fun fetchMangaDetails(manga: SManga) =
client.newCall(GET("$apiUri/series/${manga.slug}", headers)) client.newCall(GET("$apiUrl/series/${manga.url}", headers))
.asObservableSuccess().map { .asObservableSuccess().map {
mangaDetailsParse(it).apply { initialized = true } mangaDetailsParse(it).apply { initialized = true }
}!! }!!
@ -154,14 +133,6 @@ abstract class MangAdventure(
CategoryList(categories) CategoryList(categories)
) )
/** The slug of the manga. */
private inline val SManga.slug
get() = url.split('/')[2]
/** The components (series, volume, number) of the chapter. */
private inline val SChapter.components
get() = url.split('/').slice(2..5)
/** Decodes the JSON response as an object. */ /** Decodes the JSON response as an object. */
private inline fun <reified T> Response.decode() = private inline fun <reified T> Response.decode() =
json.decodeFromJsonElement<T>(json.parseToJsonElement(body!!.string())) json.decodeFromJsonElement<T>(json.parseToJsonElement(body!!.string()))
@ -169,7 +140,7 @@ abstract class MangAdventure(
/** Converts a [Series] object to an [SManga]. */ /** Converts a [Series] object to an [SManga]. */
private fun mangaFromJSON(series: Series) = private fun mangaFromJSON(series: Series) =
SManga.create().apply { SManga.create().apply {
url = series.url url = series.slug
title = series.title title = series.title
thumbnail_url = series.cover thumbnail_url = series.cover
description = buildString { description = buildString {

View File

@ -30,7 +30,7 @@ internal data class Page(
/** Chapter model schema. */ /** Chapter model schema. */
@kotlinx.serialization.Serializable @kotlinx.serialization.Serializable
internal data class Chapter( internal data class Chapter(
private val id: Int, val id: Int,
val title: String, val title: String,
val number: Float, val number: Float,
val volume: Int?, val volume: Int?,
@ -38,8 +38,7 @@ internal data class Chapter(
val final: Boolean, val final: Boolean,
val series: String, val series: String,
val groups: List<String>, val groups: List<String>,
val full_title: String, val full_title: String
val url: String
) { ) {
override fun equals(other: Any?) = override fun equals(other: Any?) =
this === other || other is Chapter && id == other.id this === other || other is Chapter && id == other.id
@ -50,10 +49,9 @@ internal data class Chapter(
/** Series model schema. */ /** Series model schema. */
@kotlinx.serialization.Serializable @kotlinx.serialization.Serializable
internal data class Series( internal data class Series(
private val slug: String, val slug: String,
val title: String, val title: String,
val url: String, val cover: String,
val cover: String?,
val description: String? = null, val description: String? = null,
val completed: Boolean? = null, val completed: Boolean? = null,
val licensed: Boolean? = null, val licensed: Boolean? = null,

View File

@ -9,7 +9,7 @@ class MangAdventureGenerator : ThemeSourceGenerator {
override val themeClass = "MangAdventure" override val themeClass = "MangAdventure"
override val baseVersionCode = 9 override val baseVersionCode = 10
override val sources = listOf( override val sources = listOf(
SingleLang("Arc-Relight", "https://arc-relight.com", "en", className = "ArcRelight"), SingleLang("Arc-Relight", "https://arc-relight.com", "en", className = "ArcRelight"),