MD: Refresh URL suffix when required (#18459)
This commit is contained in:
parent
6e42bc0e51
commit
63fd5dd57d
|
@ -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
|
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'Manga Demon'
|
extName = 'Manga Demon'
|
||||||
pkgNameSuffix = 'en.mangademon'
|
pkgNameSuffix = 'en.mangademon'
|
||||||
extClass = '.MangaDemon'
|
extClass = '.MangaDemon'
|
||||||
extVersionCode = 5
|
extVersionCode = 6
|
||||||
isNsfw = false
|
isNsfw = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
import java.io.IOException
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
@ -34,16 +35,28 @@ class MangaDemon : ParsedHttpSource() {
|
||||||
.addInterceptor(::dynamicUrlInterceptor)
|
.addInterceptor(::dynamicUrlInterceptor)
|
||||||
.build()
|
.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 {
|
private fun dynamicUrlInterceptor(chain: Interceptor.Chain): Response {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
|
val timeNow = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
// Check if request requires an up-to-date suffix
|
// 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
|
val newPath = request.url
|
||||||
.encodedPath
|
.encodedPath
|
||||||
.replaceAfterLast("-", dynamicUrlSuffix!!)
|
.replaceAfterLast("-", dynamicUrlSuffix)
|
||||||
|
|
||||||
val newUrl = request.url.newBuilder()
|
val newUrl = request.url.newBuilder()
|
||||||
.encodedPath(newPath)
|
.encodedPath(newPath)
|
||||||
|
@ -56,12 +69,8 @@ class MangaDemon : ParsedHttpSource() {
|
||||||
return chain.proceed(newRequest)
|
return chain.proceed(newRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always update suffix
|
||||||
val response = chain.proceed(request)
|
val response = chain.proceed(request)
|
||||||
if (dynamicUrlSuffix != null) {
|
|
||||||
return response
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't have suffix, get it from the page
|
|
||||||
val document = Jsoup.parse(
|
val document = Jsoup.parse(
|
||||||
response.peekBody(Long.MAX_VALUE).string(),
|
response.peekBody(Long.MAX_VALUE).string(),
|
||||||
request.url.toString(),
|
request.url.toString(),
|
||||||
|
@ -77,6 +86,7 @@ class MangaDemon : ParsedHttpSource() {
|
||||||
|
|
||||||
if (suffix != null) {
|
if (suffix != null) {
|
||||||
dynamicUrlSuffix = suffix
|
dynamicUrlSuffix = suffix
|
||||||
|
dynamicUrlSuffixUpdated = timeNow
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
Loading…
Reference in New Issue