Update deeplink for mangadex to v2 api
This commit is contained in:
parent
650e27722d
commit
b4d97516a2
@ -34,7 +34,7 @@ class MangaDex : DelegatedHttpSource() {
|
|||||||
|
|
||||||
override fun chapterUrl(uri: Uri): String? {
|
override fun chapterUrl(uri: Uri): String? {
|
||||||
val chapterNumber = uri.pathSegments.getOrNull(1) ?: return null
|
val chapterNumber = uri.pathSegments.getOrNull(1) ?: return null
|
||||||
return "/api/chapter/$chapterNumber"
|
return "/chapter/$chapterNumber"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageNumber(uri: Uri): Int? {
|
override fun pageNumber(uri: Uri): Int? {
|
||||||
@ -44,7 +44,7 @@ class MangaDex : DelegatedHttpSource() {
|
|||||||
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>? {
|
override suspend fun fetchMangaFromChapterUrl(uri: Uri): Triple<Chapter, Manga, List<SChapter>>? {
|
||||||
val url = chapterUrl(uri) ?: return null
|
val url = chapterUrl(uri) ?: return null
|
||||||
val request =
|
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()
|
val response = network.client.newCall(request).await()
|
||||||
if (response.code != 200) throw Exception("HTTP error ${response.code}")
|
if (response.code != 200) throw Exception("HTTP error ${response.code}")
|
||||||
val body = response.body?.string().orEmpty()
|
val body = response.body?.string().orEmpty()
|
||||||
@ -53,10 +53,11 @@ class MangaDex : DelegatedHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val jsonObject = JsonParser.parseString(body).obj
|
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"
|
"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
|
// Use the correct MangaDex source based on the language code, or the api will not return
|
||||||
// the correct chapter list
|
// the correct chapter list
|
||||||
delegate = sourceManager.getOnlineSources().find { it.toString() == "MangaDex ($langCode)" }
|
delegate = sourceManager.getOnlineSources().find { it.toString() == "MangaDex ($langCode)" }
|
||||||
@ -70,7 +71,7 @@ class MangaDex : DelegatedHttpSource() {
|
|||||||
val manga = deferredManga.await()
|
val manga = deferredManga.await()
|
||||||
val chapters = deferredChapters.await()
|
val chapters = deferredChapters.await()
|
||||||
val context = Injekt.get<PreferencesHelper>().context
|
val context = Injekt.get<PreferencesHelper>().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)
|
context.getString(R.string.chapter_not_found)
|
||||||
)
|
)
|
||||||
if (manga != null) {
|
if (manga != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user