MangaDex use translatedLanguage and an alt cover source(#7180)

* fix locales, add back bone for covers, use alt cover url

* dont change url

* update gradle
This commit is contained in:
Carlos 2021-05-22 11:16:31 -04:00 committed by GitHub
parent 20d4513149
commit 5f10f155d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 12 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 113
extVersionCode = 114
libVersion = '1.2'
containsNsfw = true
}

View File

@ -10,12 +10,14 @@ object MDConstants {
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
val cdnUrl = "https://uploads.mangadex.org"
val apiUrl = "https://api.mangadex.org"
val apiMangaUrl = "$apiUrl/manga"
val atHomePostUrl = "https://api.mangadex.network/report"
val whitespaceRegex = "\\s".toRegex()
val tempCover = "https://i.imgur.com/6TrIues.jpg"
const val coverApi = "https://coverapi.orell.dev/api/v1/mdaltimage/manga/{uuid}/cover"
const val mdAtHomeTokenLifespan = 5 * 60 * 1000

View File

@ -108,7 +108,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val hasMoreResults =
(mangaListResponse["limit"].int + mangaListResponse["offset"].int) < mangaListResponse["total"].int
val mangaList = mangaListResponse["results"].array.map { helper.createManga(it) }
val mangaList = mangaListResponse["results"].array.map {
helper.createBasicManga(it, client)
}
return MangasPage(mangaList, hasMoreResults)
}

View File

@ -33,7 +33,7 @@ class MangaDexHelper() {
* get chapters for manga (aka manga/$id/feed endpoint)
*/
fun getChapterEndpoint(mangaId: String, offset: Int, langCode: String) =
"${MDConstants.apiMangaUrl}/$mangaId/feed?limit=500&offset=$offset&locales[]=$langCode&order[volume]=desc&order[chapter]=desc"
"${MDConstants.apiMangaUrl}/$mangaId/feed?limit=500&offset=$offset&translatedLanguage[]=$langCode&order[volume]=desc&order[chapter]=desc"
/**
* Check if the manga url is a valid uuid
@ -123,15 +123,19 @@ class MangaDexHelper() {
/**
* create an SManga from json element only basic elements
*/
fun createManga(mangaJson: JsonElement): SManga {
fun createBasicManga(mangaJson: JsonElement, client: OkHttpClient): SManga {
val data = mangaJson["data"].obj
val dexId = data["id"].string
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 {
url = "/manga/$dexId"
title = cleanString(attr["title"]["en"].string)
thumbnail_url = MDConstants.tempCover
thumbnail_url = createCoverUrl(dexId, coverId, client)
}
}
@ -147,11 +151,12 @@ class MangaDexHelper() {
// things that will go with the genre tags but aren't actually genre
val tempContentRating = attr["contentRating"].nullString
val contentRating = if (tempContentRating == null || tempContentRating.equals("safe", true)) {
null
} else {
"Content rating: " + tempContentRating.capitalize(Locale.US)
}
val contentRating =
if (tempContentRating == null || tempContentRating.equals("safe", true)) {
null
} else {
"Content rating: " + tempContentRating.capitalize(Locale.US)
}
val nonGenres = listOf(
(attr["publicationDemographic"]?.nullString ?: "").capitalize(Locale.US),
@ -180,6 +185,10 @@ class MangaDexHelper() {
}.toMap()
}.getOrNull() ?: emptyMap()
val coverId = mangaJson["relationships"].array.filter { relationship ->
relationship["type"].string.equals("cover_art", true)
}.map { relationship -> relationship["id"].string }.firstOrNull()
// get tag list
val tags = mdFilters.getTags()
@ -201,7 +210,7 @@ class MangaDexHelper() {
author = authorIds.mapNotNull { authorMap[it] }.joinToString(", ")
artist = artistIds.mapNotNull { authorMap[it] }.joinToString(", ")
status = getPublicationStatus(attr["publicationDemographic"].nullString)
thumbnail_url = MDConstants.tempCover
thumbnail_url = createCoverUrl(dexId, coverId, client)
genre = genreList.joinToString(", ")
}
} catch (e: Exception) {
@ -294,4 +303,20 @@ class MangaDexHelper() {
throw(e)
}
}
fun createCoverUrl(dexId: String, coverId: String?, client: OkHttpClient): String {
var coverUrl = MDConstants.coverApi.replace("{uuid}", dexId)
/* try {
if (coverId != null) {
val response =
client.newCall(GET("${MDConstants.apiMangaUrl}/$dexId/cover?ids[]=$coverId"))
.execute()
val coverJson = JsonParser.parseString(response.body!!.string()).obj
val firstRelationship =
coverJson.obj["results"].array.firstOrNull()!!.obj["data"]
.obj["attributes"].obj["fileName"]?.nullString?.let { fileName ->
coverUrl = "${MDConstants.cdnUrl}/covers/$dexId/$fileName"
*/
return coverUrl
}
}