Manta: update locked chapter logic (#15660)
* Manta: update for extensions-lib 1.4 * Manta: update locked chapter logic
This commit is contained in:
parent
4aeaba9548
commit
f31f9e9ba3
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'Manta Comics'
|
extName = 'Manta Comics'
|
||||||
pkgNameSuffix = 'en.manta'
|
pkgNameSuffix = 'en.manta'
|
||||||
extClass = '.MantaComics'
|
extClass = '.MantaComics'
|
||||||
extVersionCode = 3
|
extVersionCode = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.extension.en.manta
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.concurrent.TimeUnit.MILLISECONDS as MS
|
|
||||||
|
|
||||||
private val isoDate by lazy {
|
private val isoDate by lazy {
|
||||||
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT)
|
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT)
|
||||||
|
@ -50,37 +49,28 @@ data class Episode(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val ord: Int,
|
val ord: Int,
|
||||||
val data: Data?,
|
val data: Data?,
|
||||||
|
val lockData: LockData,
|
||||||
private val createdAt: String,
|
private val createdAt: String,
|
||||||
val cutImages: List<Image>? = null,
|
val cutImages: List<Image>? = null,
|
||||||
) {
|
) {
|
||||||
val timestamp: Long
|
val timestamp: Long
|
||||||
get() = createdAt.timestamp
|
get() = createdAt.timestamp
|
||||||
|
|
||||||
val isLocked: Boolean
|
|
||||||
get() = timeTillFree > 0
|
|
||||||
|
|
||||||
val waitingTime: String
|
|
||||||
get() = when (val days = MS.toDays(timeTillFree)) {
|
|
||||||
0L -> "later today"
|
|
||||||
1L -> "tomorrow"
|
|
||||||
else -> "in $days days"
|
|
||||||
}
|
|
||||||
|
|
||||||
private val timeTillFree by lazy {
|
|
||||||
data?.freeAt.timestamp - System.currentTimeMillis()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString() = buildString {
|
override fun toString() = buildString {
|
||||||
append(data?.title ?: "Episode $ord")
|
append(data?.title ?: "Episode $ord")
|
||||||
if (isLocked) append(" \uD83D\uDD12")
|
if (lockData.isLocked) append(" \uD83D\uDD12")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Data(
|
data class Data(val title: String? = null)
|
||||||
val title: String? = null,
|
|
||||||
val freeAt: String? = null,
|
@Serializable
|
||||||
)
|
data class LockData(private val state: Int) {
|
||||||
|
// TODO: check for more unlocked states
|
||||||
|
val isLocked: Boolean
|
||||||
|
get() = state !in arrayOf(110, 130)
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Creator(
|
data class Creator(
|
||||||
|
@ -99,6 +89,7 @@ data class Description(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@Suppress("PrivatePropertyName")
|
||||||
data class Cover(private val `1280x1840_480`: Image) {
|
data class Cover(private val `1280x1840_480`: Image) {
|
||||||
override fun toString() = `1280x1840_480`.toString()
|
override fun toString() = `1280x1840_480`.toString()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.decodeFromJsonElement
|
import kotlinx.serialization.json.decodeFromJsonElement
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.CookieJar
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
@ -24,10 +27,23 @@ class MantaComics : HttpSource() {
|
||||||
|
|
||||||
override val supportsLatest = false
|
override val supportsLatest = false
|
||||||
|
|
||||||
|
private var token: String? = null
|
||||||
|
|
||||||
|
override val client = network.client.newBuilder()
|
||||||
|
.cookieJar(
|
||||||
|
object : CookieJar {
|
||||||
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
|
token = cookies.find { it.matches(url) && it.name == "token" }?.value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun loadForRequest(url: HttpUrl) = emptyList<Cookie>()
|
||||||
|
},
|
||||||
|
).build()
|
||||||
|
|
||||||
private val json by injectLazy<Json>()
|
private val json by injectLazy<Json>()
|
||||||
|
|
||||||
override fun headersBuilder() = super.headersBuilder()
|
override fun headersBuilder() = super.headersBuilder()
|
||||||
.set("User-Agent", "Manta/167").set("Origin", baseUrl)
|
.set("Origin", baseUrl).set("Authorization", "Bearer $token")
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int) =
|
override fun latestUpdatesRequest(page: Int) =
|
||||||
GET("$baseUrl/manta/v1/search/series?cat=New", headers)
|
GET("$baseUrl/manta/v1/search/series?cat=New", headers)
|
||||||
|
@ -52,9 +68,8 @@ class MantaComics : HttpSource() {
|
||||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
|
override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
|
||||||
searchMangaRequest(page, query, filters).fetch(::searchMangaParse)
|
searchMangaRequest(page, query, filters).fetch(::searchMangaParse)
|
||||||
|
|
||||||
// Request the actual manga URL for the webview
|
|
||||||
override fun mangaDetailsRequest(manga: SManga) =
|
override fun mangaDetailsRequest(manga: SManga) =
|
||||||
GET("$baseUrl/series/${manga.url}")
|
GET("$baseUrl/front/v1/series/${manga.url}", headers)
|
||||||
|
|
||||||
override fun mangaDetailsParse(response: Response) =
|
override fun mangaDetailsParse(response: Response) =
|
||||||
SManga.create().apply {
|
SManga.create().apply {
|
||||||
|
@ -71,10 +86,10 @@ class MantaComics : HttpSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchMangaDetails(manga: SManga) =
|
override fun fetchMangaDetails(manga: SManga) =
|
||||||
chapterListRequest(manga).fetch(::mangaDetailsParse)
|
mangaDetailsRequest(manga).fetch(::mangaDetailsParse)
|
||||||
|
|
||||||
override fun chapterListRequest(manga: SManga) =
|
override fun chapterListRequest(manga: SManga) =
|
||||||
GET("$baseUrl/front/v1/series/${manga.url}", headers)
|
mangaDetailsRequest(manga)
|
||||||
|
|
||||||
override fun chapterListParse(response: Response) =
|
override fun chapterListParse(response: Response) =
|
||||||
response.parse<Series<Title>>().episodes!!.map {
|
response.parse<Series<Title>>().episodes!!.map {
|
||||||
|
@ -93,14 +108,17 @@ class MantaComics : HttpSource() {
|
||||||
GET("$baseUrl/front/v1/episodes/${chapter.url}", headers)
|
GET("$baseUrl/front/v1/episodes/${chapter.url}", headers)
|
||||||
|
|
||||||
override fun pageListParse(response: Response) =
|
override fun pageListParse(response: Response) =
|
||||||
response.parse<Episode>().run {
|
response.parse<Episode>().cutImages?.mapIndexed { idx, img ->
|
||||||
if (!isLocked) return@run cutImages!!
|
Page(idx, "", img.toString())
|
||||||
error("This episode will be available $waitingTime.")
|
} ?: emptyList()
|
||||||
}.mapIndexed { idx, img -> Page(idx, "", img.toString()) }
|
|
||||||
|
|
||||||
override fun fetchPageList(chapter: SChapter) =
|
override fun fetchPageList(chapter: SChapter) =
|
||||||
pageListRequest(chapter).fetch(::pageListParse)
|
pageListRequest(chapter).fetch(::pageListParse)
|
||||||
|
|
||||||
|
override fun getMangaUrl(manga: SManga) = "$baseUrl/series/${manga.url}"
|
||||||
|
|
||||||
|
override fun getChapterUrl(chapter: SChapter) = "$baseUrl/episodes/${chapter.url}"
|
||||||
|
|
||||||
override fun getFilterList() = FilterList(Category())
|
override fun getFilterList() = FilterList(Category())
|
||||||
|
|
||||||
override fun latestUpdatesParse(response: Response) =
|
override fun latestUpdatesParse(response: Response) =
|
||||||
|
|
Loading…
Reference in New Issue