use dex covers for everything (#7291)
This commit is contained in:
parent
5adc6f44cc
commit
6822315dfd
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'MangaDex'
|
extName = 'MangaDex'
|
||||||
pkgNameSuffix = 'all.mangadex'
|
pkgNameSuffix = 'all.mangadex'
|
||||||
extClass = '.MangaDexFactory'
|
extClass = '.MangaDexFactory'
|
||||||
extVersionCode = 114
|
extVersionCode = 115
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
containsNsfw = true
|
containsNsfw = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,15 @@ object MDConstants {
|
||||||
val uuidRegex =
|
val uuidRegex =
|
||||||
Regex("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")
|
Regex("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")
|
||||||
|
|
||||||
val mangaLimit = 25
|
const val mangaLimit = 20
|
||||||
val cdnUrl = "https://uploads.mangadex.org"
|
const val cdnUrl = "https://uploads.mangadex.org"
|
||||||
|
|
||||||
val apiUrl = "https://api.mangadex.org"
|
const val apiUrl = "https://api.mangadex.org"
|
||||||
val apiMangaUrl = "$apiUrl/manga"
|
const val apiMangaUrl = "$apiUrl/manga"
|
||||||
val atHomePostUrl = "https://api.mangadex.network/report"
|
const val apiCoverUrl = "$apiUrl/cover"
|
||||||
|
const val atHomePostUrl = "https://api.mangadex.network/report"
|
||||||
val whitespaceRegex = "\\s".toRegex()
|
val whitespaceRegex = "\\s".toRegex()
|
||||||
|
|
||||||
const val coverApi = "https://coverapi.orell.dev/api/v1/mdaltimage/manga/{uuid}/cover"
|
|
||||||
|
|
||||||
const val mdAtHomeTokenLifespan = 5 * 60 * 1000
|
const val mdAtHomeTokenLifespan = 5 * 60 * 1000
|
||||||
|
|
||||||
val dateFormatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+SSS", Locale.US)
|
val dateFormatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+SSS", Locale.US)
|
||||||
|
|
|
@ -108,8 +108,22 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
|
||||||
val hasMoreResults =
|
val hasMoreResults =
|
||||||
(mangaListResponse["limit"].int + mangaListResponse["offset"].int) < mangaListResponse["total"].int
|
(mangaListResponse["limit"].int + mangaListResponse["offset"].int) < mangaListResponse["total"].int
|
||||||
|
|
||||||
|
val idsAndCoverIds = mangaListResponse["results"].array.map { mangaJson ->
|
||||||
|
val mangaId = mangaJson["data"].obj["id"].string
|
||||||
|
val coverId = mangaJson["relationships"].array.filter { relationship ->
|
||||||
|
relationship["type"].string.equals("cover_art", true)
|
||||||
|
}.map { relationship -> relationship["id"].string }.first()
|
||||||
|
Pair(mangaId, coverId)
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
val results = runCatching {
|
||||||
|
helper.getBatchCoversUrl(idsAndCoverIds, client)
|
||||||
|
}.getOrNull()!!
|
||||||
|
|
||||||
val mangaList = mangaListResponse["results"].array.map {
|
val mangaList = mangaListResponse["results"].array.map {
|
||||||
helper.createBasicManga(it, client)
|
helper.createBasicManga(it, client).apply {
|
||||||
|
thumbnail_url = results[url.substringAfter("/manga/")]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MangasPage(mangaList, hasMoreResults)
|
return MangasPage(mangaList, hasMoreResults)
|
||||||
|
|
|
@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import okhttp3.CacheControl
|
import okhttp3.CacheControl
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.jsoup.parser.Parser
|
import org.jsoup.parser.Parser
|
||||||
|
@ -128,14 +129,9 @@ class MangaDexHelper() {
|
||||||
val dexId = data["id"].string
|
val dexId = data["id"].string
|
||||||
val attr = data["attributes"].obj
|
val attr = data["attributes"].obj
|
||||||
|
|
||||||
val coverId = mangaJson["relationships"].array.filter { relationship ->
|
|
||||||
relationship["type"].string.equals("cover_art", true)
|
|
||||||
}.map { relationship -> relationship["id"].string }.firstOrNull()
|
|
||||||
|
|
||||||
return SManga.create().apply {
|
return SManga.create().apply {
|
||||||
url = "/manga/$dexId"
|
url = "/manga/$dexId"
|
||||||
title = cleanString(attr["title"]["en"].string)
|
title = cleanString(attr["title"]["en"].string)
|
||||||
thumbnail_url = createCoverUrl(dexId, coverId, client)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +183,7 @@ class MangaDexHelper() {
|
||||||
|
|
||||||
val coverId = mangaJson["relationships"].array.filter { relationship ->
|
val coverId = mangaJson["relationships"].array.filter { relationship ->
|
||||||
relationship["type"].string.equals("cover_art", true)
|
relationship["type"].string.equals("cover_art", true)
|
||||||
}.map { relationship -> relationship["id"].string }.firstOrNull()
|
}.map { relationship -> relationship["id"].string }.firstOrNull()!!
|
||||||
|
|
||||||
// get tag list
|
// get tag list
|
||||||
val tags = mdFilters.getTags()
|
val tags = mdFilters.getTags()
|
||||||
|
@ -210,7 +206,7 @@ class MangaDexHelper() {
|
||||||
author = authorIds.mapNotNull { authorMap[it] }.joinToString(", ")
|
author = authorIds.mapNotNull { authorMap[it] }.joinToString(", ")
|
||||||
artist = artistIds.mapNotNull { authorMap[it] }.joinToString(", ")
|
artist = artistIds.mapNotNull { authorMap[it] }.joinToString(", ")
|
||||||
status = getPublicationStatus(attr["publicationDemographic"].nullString)
|
status = getPublicationStatus(attr["publicationDemographic"].nullString)
|
||||||
thumbnail_url = createCoverUrl(dexId, coverId, client)
|
thumbnail_url = getCoverUrl(dexId, coverId, client)
|
||||||
genre = genreList.joinToString(", ")
|
genre = genreList.joinToString(", ")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -304,19 +300,33 @@ class MangaDexHelper() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCoverUrl(dexId: String, coverId: String?, client: OkHttpClient): String {
|
private fun getCoverUrl(dexId: String, coverId: String, client: OkHttpClient): String {
|
||||||
var coverUrl = MDConstants.coverApi.replace("{uuid}", dexId)
|
|
||||||
/* try {
|
|
||||||
if (coverId != null) {
|
|
||||||
val response =
|
val response =
|
||||||
client.newCall(GET("${MDConstants.apiMangaUrl}/$dexId/cover?ids[]=$coverId"))
|
client.newCall(GET("${MDConstants.apiCoverUrl}/$coverId"))
|
||||||
.execute()
|
.execute()
|
||||||
val coverJson = JsonParser.parseString(response.body!!.string()).obj
|
val coverJson = JsonParser.parseString(response.body!!.string()).obj
|
||||||
val firstRelationship =
|
val fileName =
|
||||||
coverJson.obj["results"].array.firstOrNull()!!.obj["data"]
|
coverJson.obj["data"].obj["attributes"].obj["fileName"]?.nullString!!
|
||||||
.obj["attributes"].obj["fileName"]?.nullString?.let { fileName ->
|
return "${MDConstants.cdnUrl}/covers/$dexId/$fileName"
|
||||||
coverUrl = "${MDConstants.cdnUrl}/covers/$dexId/$fileName"
|
}
|
||||||
*/
|
|
||||||
return coverUrl
|
fun getBatchCoversUrl(ids: Map<String, String>, client: OkHttpClient): Map<String, String> {
|
||||||
|
|
||||||
|
val url = MDConstants.apiCoverUrl.toHttpUrl().newBuilder().apply {
|
||||||
|
ids.values.forEach { coverArtId ->
|
||||||
|
addQueryParameter("ids[]", coverArtId)
|
||||||
|
}
|
||||||
|
addQueryParameter("limit", ids.size.toString())
|
||||||
|
}.build().toString()
|
||||||
|
|
||||||
|
val response = client.newCall(GET(url)).execute()
|
||||||
|
val coverJson = JsonParser.parseString(response.body!!.string()).obj
|
||||||
|
|
||||||
|
return coverJson.obj["results"].array.map { coverResult ->
|
||||||
|
val fileName = coverResult.obj["data"].obj["attributes"].obj["fileName"].string
|
||||||
|
val mangaId = coverResult.obj["relationships"].array.first { it["type"].string.equals("manga", true) }["id"].string
|
||||||
|
val url = "${MDConstants.cdnUrl}/covers/$mangaId/$fileName"
|
||||||
|
Pair(mangaId, url)
|
||||||
|
}.toMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue