From b4d97516a24c34cf1981dcbd6cdcb40dafe1ac92 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 19 Mar 2021 14:20:03 -0400 Subject: [PATCH] Update deeplink for mangadex to v2 api --- .../eu/kanade/tachiyomi/source/online/all/MangaDex.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt index 3185549fa2..c28a26e3e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt @@ -34,7 +34,7 @@ class MangaDex : DelegatedHttpSource() { override fun chapterUrl(uri: Uri): String? { val chapterNumber = uri.pathSegments.getOrNull(1) ?: return null - return "/api/chapter/$chapterNumber" + return "/chapter/$chapterNumber" } override fun pageNumber(uri: Uri): Int? { @@ -44,7 +44,7 @@ class MangaDex : DelegatedHttpSource() { override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple>? { val url = chapterUrl(uri) ?: return null val request = - GET("https://mangadex.org$url", delegate!!.headers, CacheControl.FORCE_NETWORK) + GET("https:///api.mangadex.org/v2$url", delegate!!.headers, CacheControl.FORCE_NETWORK) val response = network.client.newCall(request).await() if (response.code != 200) throw Exception("HTTP error ${response.code}") val body = response.body?.string().orEmpty() @@ -53,10 +53,11 @@ class MangaDex : DelegatedHttpSource() { } val jsonObject = JsonParser.parseString(body).obj - val mangaId = jsonObject["manga_id"]?.nullInt ?: throw Exception( + val dataObject = jsonObject["data"].asJsonObject ?: throw Exception("Chapter not found") + val mangaId = dataObject["mangaId"]?.nullInt ?: throw Exception( "No manga associated with chapter" ) - val langCode = getRealLangCode(jsonObject["lang_code"]?.nullString ?: "en").toUpperCase() + val langCode = getRealLangCode(dataObject["language"]?.nullString ?: "en").toUpperCase() // Use the correct MangaDex source based on the language code, or the api will not return // the correct chapter list delegate = sourceManager.getOnlineSources().find { it.toString() == "MangaDex ($langCode)" } @@ -70,7 +71,7 @@ class MangaDex : DelegatedHttpSource() { val manga = deferredManga.await() val chapters = deferredChapters.await() val context = Injekt.get().context - val trueChapter = chapters?.find { it.url == url }?.toChapter() ?: error( + val trueChapter = chapters?.find { it.url == "/api$url" }?.toChapter() ?: error( context.getString(R.string.chapter_not_found) ) if (manga != null) {