From 5f10f155d90531dff3820d2482db0a7b01363cdd Mon Sep 17 00:00:00 2001 From: Carlos <2092019+CarlosEsco@users.noreply.github.com> Date: Sat, 22 May 2021 11:16:31 -0400 Subject: [PATCH] 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 --- src/all/mangadex/build.gradle | 2 +- .../extension/all/mangadex/MDConstants.kt | 4 +- .../extension/all/mangadex/MangaDex.kt | 5 ++- .../extension/all/mangadex/MangaDexHelper.kt | 43 +++++++++++++++---- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index 7aaf9c7fa..66e1e95cd 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangaDexFactory' - extVersionCode = 113 + extVersionCode = 114 libVersion = '1.2' containsNsfw = true } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt index 8dee31f41..17b5e4318 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt @@ -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 diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt index e012a8787..50780cdbd 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt @@ -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) } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt index e7e7bcf6f..aa5912708 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt @@ -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 + } }