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' | ||||
|     pkgNameSuffix = 'en.manta' | ||||
|     extClass = '.MantaComics' | ||||
|     extVersionCode = 3 | ||||
|     extVersionCode = 4 | ||||
| } | ||||
| 
 | ||||
| apply from: "$rootDir/common.gradle" | ||||
|  | ||||
| @ -3,7 +3,6 @@ package eu.kanade.tachiyomi.extension.en.manta | ||||
| import kotlinx.serialization.Serializable | ||||
| import java.text.SimpleDateFormat | ||||
| import java.util.Locale | ||||
| import java.util.concurrent.TimeUnit.MILLISECONDS as MS | ||||
| 
 | ||||
| private val isoDate by lazy { | ||||
|     SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT) | ||||
| @ -50,37 +49,28 @@ data class Episode( | ||||
|     val id: Int, | ||||
|     val ord: Int, | ||||
|     val data: Data?, | ||||
|     val lockData: LockData, | ||||
|     private val createdAt: String, | ||||
|     val cutImages: List<Image>? = null, | ||||
| ) { | ||||
|     val timestamp: Long | ||||
|         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 { | ||||
|         append(data?.title ?: "Episode $ord") | ||||
|         if (isLocked) append(" \uD83D\uDD12") | ||||
|         if (lockData.isLocked) append(" \uD83D\uDD12") | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Serializable | ||||
| data class Data( | ||||
|     val title: String? = null, | ||||
|     val freeAt: String? = null, | ||||
| ) | ||||
| data class Data(val title: 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 | ||||
| data class Creator( | ||||
| @ -99,6 +89,7 @@ data class Description( | ||||
| } | ||||
| 
 | ||||
| @Serializable | ||||
| @Suppress("PrivatePropertyName") | ||||
| data class Cover(private val `1280x1840_480`: Image) { | ||||
|     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.decodeFromJsonElement | ||||
| import kotlinx.serialization.json.jsonObject | ||||
| import okhttp3.Cookie | ||||
| import okhttp3.CookieJar | ||||
| import okhttp3.HttpUrl | ||||
| import okhttp3.Request | ||||
| import okhttp3.Response | ||||
| import uy.kohesive.injekt.injectLazy | ||||
| @ -24,10 +27,23 @@ class MantaComics : HttpSource() { | ||||
| 
 | ||||
|     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>() | ||||
| 
 | ||||
|     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) = | ||||
|         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) = | ||||
|         searchMangaRequest(page, query, filters).fetch(::searchMangaParse) | ||||
| 
 | ||||
|     // Request the actual manga URL for the webview | ||||
|     override fun mangaDetailsRequest(manga: SManga) = | ||||
|         GET("$baseUrl/series/${manga.url}") | ||||
|         GET("$baseUrl/front/v1/series/${manga.url}", headers) | ||||
| 
 | ||||
|     override fun mangaDetailsParse(response: Response) = | ||||
|         SManga.create().apply { | ||||
| @ -71,10 +86,10 @@ class MantaComics : HttpSource() { | ||||
|         } | ||||
| 
 | ||||
|     override fun fetchMangaDetails(manga: SManga) = | ||||
|         chapterListRequest(manga).fetch(::mangaDetailsParse) | ||||
|         mangaDetailsRequest(manga).fetch(::mangaDetailsParse) | ||||
| 
 | ||||
|     override fun chapterListRequest(manga: SManga) = | ||||
|         GET("$baseUrl/front/v1/series/${manga.url}", headers) | ||||
|         mangaDetailsRequest(manga) | ||||
| 
 | ||||
|     override fun chapterListParse(response: Response) = | ||||
|         response.parse<Series<Title>>().episodes!!.map { | ||||
| @ -93,14 +108,17 @@ class MantaComics : HttpSource() { | ||||
|         GET("$baseUrl/front/v1/episodes/${chapter.url}", headers) | ||||
| 
 | ||||
|     override fun pageListParse(response: Response) = | ||||
|         response.parse<Episode>().run { | ||||
|             if (!isLocked) return@run cutImages!! | ||||
|             error("This episode will be available $waitingTime.") | ||||
|         }.mapIndexed { idx, img -> Page(idx, "", img.toString()) } | ||||
|         response.parse<Episode>().cutImages?.mapIndexed { idx, img -> | ||||
|             Page(idx, "", img.toString()) | ||||
|         } ?: emptyList() | ||||
| 
 | ||||
|     override fun fetchPageList(chapter: SChapter) = | ||||
|         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 latestUpdatesParse(response: Response) = | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 ObserverOfTime
						ObserverOfTime