diff --git a/src/en/mangademon/CHANGELOG.md b/src/en/mangademon/CHANGELOG.md new file mode 100644 index 000000000..30ef52390 --- /dev/null +++ b/src/en/mangademon/CHANGELOG.md @@ -0,0 +1,40 @@ +# 1.4.6 + +### Fix + +* Refresh URL suffix when required + +# 1.4.5 + +### Features + +* Dynamically update URL suffix + +# 1.4.4 + +### Features + +* Filters + +### Fix + +* Update base URL + +# 1.4.3 + +### Fix + +* Update selector + +# 1.4.2 + +### Fix + +* Fetch all chapter images +* Use GET on search, same as site + +# 1.4.1 + +### Features + +* First version diff --git a/src/en/mangademon/build.gradle b/src/en/mangademon/build.gradle index f57fedf23..1098a1eac 100644 --- a/src/en/mangademon/build.gradle +++ b/src/en/mangademon/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Manga Demon' pkgNameSuffix = 'en.mangademon' extClass = '.MangaDemon' - extVersionCode = 5 + extVersionCode = 6 isNsfw = false } diff --git a/src/en/mangademon/src/eu/kanade/tachiyomi/extension/en/mangademon/MangaDemon.kt b/src/en/mangademon/src/eu/kanade/tachiyomi/extension/en/mangademon/MangaDemon.kt index 7c1b9777f..dd674ac17 100644 --- a/src/en/mangademon/src/eu/kanade/tachiyomi/extension/en/mangademon/MangaDemon.kt +++ b/src/en/mangademon/src/eu/kanade/tachiyomi/extension/en/mangademon/MangaDemon.kt @@ -18,6 +18,7 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable +import java.io.IOException import java.net.URLEncoder import java.text.SimpleDateFormat import java.util.Locale @@ -34,16 +35,28 @@ class MangaDemon : ParsedHttpSource() { .addInterceptor(::dynamicUrlInterceptor) .build() - private var dynamicUrlSuffix: String? = null + // Cache suffix + private var dynamicUrlSuffix = "" + private var dynamicUrlSuffixUpdated: Long = 0 + private val dynamicUrlSuffixValidity: Long = 10 * 60 // 10 minutes private fun dynamicUrlInterceptor(chain: Interceptor.Chain): Response { val request = chain.request() + val timeNow = System.currentTimeMillis() / 1000 // Check if request requires an up-to-date suffix - if (request.url.pathSegments[0] == "manga" && dynamicUrlSuffix != null) { + if (request.url.pathSegments[0] == "manga") { + // Force update suffix if required + if (timeNow - dynamicUrlSuffixUpdated > dynamicUrlSuffixValidity) { + client.newCall(GET(baseUrl)).execute() + if (timeNow - dynamicUrlSuffixUpdated > dynamicUrlSuffixValidity) { + throw IOException("Failed to update dynamic url suffix") + } + } + val newPath = request.url .encodedPath - .replaceAfterLast("-", dynamicUrlSuffix!!) + .replaceAfterLast("-", dynamicUrlSuffix) val newUrl = request.url.newBuilder() .encodedPath(newPath) @@ -56,12 +69,8 @@ class MangaDemon : ParsedHttpSource() { return chain.proceed(newRequest) } + // Always update suffix val response = chain.proceed(request) - if (dynamicUrlSuffix != null) { - return response - } - - // Don't have suffix, get it from the page val document = Jsoup.parse( response.peekBody(Long.MAX_VALUE).string(), request.url.toString(), @@ -77,6 +86,7 @@ class MangaDemon : ParsedHttpSource() { if (suffix != null) { dynamicUrlSuffix = suffix + dynamicUrlSuffixUpdated = timeNow } return response