diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index a736a0e98..997346db3 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangaDexFactory' - extVersionCode = 147 + extVersionCode = 148 isNsfw = true } 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 eaa7ed4de..2615e2bab 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 @@ -8,6 +8,7 @@ import androidx.preference.MultiSelectListPreference import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.extension.all.mangadex.dto.AggregateDto +import eu.kanade.tachiyomi.extension.all.mangadex.dto.AtHomeDto import eu.kanade.tachiyomi.extension.all.mangadex.dto.ChapterDto import eu.kanade.tachiyomi.extension.all.mangadex.dto.ChapterListDto import eu.kanade.tachiyomi.extension.all.mangadex.dto.MangaDto @@ -231,8 +232,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : tempUrl.apply { addQueryParameter("group", groupID) } - } - else { + } else { tempUrl.apply { val actualQuery = query.replace(MDConstants.whitespaceRegex, " ") if (actualQuery.isNotBlank()) { @@ -375,40 +375,33 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : if (!helper.containsUuid(chapter.url)) { throw Exception("Migrate this manga from MangaDex to MangaDex to update it") } - return GET(MDConstants.apiUrl + chapter.url, headers, CacheControl.FORCE_NETWORK) + val chapterId = chapter.url.substringAfter("/chapter/") + val usingStandardHTTPS = + preferences.getBoolean(MDConstants.getStandardHttpsPreferenceKey(dexLang), false) + val atHomeRequestUrl = if (usingStandardHTTPS) { + "${MDConstants.apiUrl}/at-home/server/$chapterId?forcePort443=true" + } else { + "${MDConstants.apiUrl}/at-home/server/$chapterId" + } + + return helper.mdAtHomeRequest(atHomeRequestUrl, headers, CacheControl.FORCE_NETWORK) } override fun pageListParse(response: Response): List { - if (response.isSuccessful.not()) { - throw Exception("HTTP ${response.code}") - } - if (response.code == 204) { - return emptyList() - } - val chapterDto = helper.json.decodeFromString(response.body!!.string()).data - val usingStandardHTTPS = - preferences.getBoolean(MDConstants.getStandardHttpsPreferenceKey(dexLang), false) - - val atHomeRequestUrl = if (usingStandardHTTPS) { - "${MDConstants.apiUrl}/at-home/server/${chapterDto.id}?forcePort443=true" - } else { - "${MDConstants.apiUrl}/at-home/server/${chapterDto.id}" - } - - val host = - helper.getMdAtHomeUrl(atHomeRequestUrl, client, headers, CacheControl.FORCE_NETWORK) - + val atHomeRequestUrl = response.request.url + val atHomeDto = helper.json.decodeFromString(response.body!!.string()) + val host = atHomeDto.baseUrl val usingDataSaver = preferences.getBoolean(MDConstants.getDataSaverPreferenceKey(dexLang), false) // have to add the time, and url to the page because pages timeout within 30mins now val now = Date().time - val hash = chapterDto.attributes.hash + val hash = atHomeDto.chapter.hash val pageSuffix = if (usingDataSaver) { - chapterDto.attributes.dataSaver.map { "/data-saver/$hash/$it" } + atHomeDto.chapter.dataSaver.map { "/data-saver/$hash/$it" } } else { - chapterDto.attributes.data.map { "/data/$hash/$it" } + atHomeDto.chapter.data.map { "/data/$hash/$it" } } return pageSuffix.mapIndexed { index, imgUrl -> 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 a7b0876f9..36e4f31cc 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 @@ -142,17 +142,14 @@ class MangaDexHelper() { /** * get the md@home url */ - fun getMdAtHomeUrl( + private fun getMdAtHomeUrl( tokenRequestUrl: String, client: OkHttpClient, headers: Headers, cacheControl: CacheControl, ): String { - if (cacheControl == CacheControl.FORCE_NETWORK) { - tokenTracker[tokenRequestUrl] = Date().time - } val response = - client.newCall(GET(tokenRequestUrl, headers, cacheControl)).execute() + client.newCall(mdAtHomeRequest(tokenRequestUrl, headers, cacheControl)).execute() // This check is for the error that causes pages to fail to load. // It should never be entered, but in case it is, we retry the request. @@ -164,6 +161,21 @@ class MangaDexHelper() { return json.decodeFromString(response.body!!.string()).baseUrl } + /** + * create an md at home Request + */ + fun mdAtHomeRequest( + tokenRequestUrl: String, + headers: Headers, + cacheControl: CacheControl + ): Request { + if (cacheControl == CacheControl.FORCE_NETWORK) { + tokenTracker[tokenRequestUrl] = Date().time + } + + return GET(tokenRequestUrl, headers, cacheControl) + } + /** * create an SManga from json element only basic elements */ @@ -314,7 +326,7 @@ class MangaDexHelper() { } } - if (attr.externalUrl != null && attr.data.isEmpty()) { + if (attr.externalUrl != null) { return null } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/AtHomeDto.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/AtHomeDto.kt index 49f141218..e41df8971 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/AtHomeDto.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/AtHomeDto.kt @@ -4,7 +4,15 @@ import kotlinx.serialization.Serializable @Serializable data class AtHomeDto( - val baseUrl: String + val baseUrl: String, + val chapter: AtHomeChapterDto, +) + +@Serializable +data class AtHomeChapterDto( + val hash: String, + val data: List, + val dataSaver: List, ) @Serializable diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/ChapterDto.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/ChapterDto.kt index 05aebaa9c..35826bda2 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/ChapterDto.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/dto/ChapterDto.kt @@ -30,8 +30,5 @@ data class ChapterAttributesDto( val volume: String?, val chapter: String?, val publishAt: String, - val data: List, - val dataSaver: List, - val hash: String, val externalUrl: String?, )