[MangaThemesia + ConstellarScans] Add trailing slashes to URLs; stricter checking for decoding keys (#15088)

* [MangaThemesia] Append a trailing slash to requests to avoid 301s

* [ConstellarScans] Don't trust their keys

* whoops

* this is just for you TheRunningRiot

* [MangaThemesia] Return proper URL when searching by URL
This commit is contained in:
beerpsi 2023-01-25 00:55:43 +07:00 committed by GitHub
parent 1fccdf3d28
commit dfcd66b3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 20 deletions

View File

@ -30,7 +30,7 @@ import java.security.MessageDigest
class ConstellarScans : MangaThemesia("Constellar Scans", "https://constellarscans.com", "en") {
override val client = super.client.newBuilder()
.rateLimit(1, 2)
.rateLimit(1, 3)
.addInterceptor { chain ->
val response = chain.proceed(chain.request())
@ -97,24 +97,22 @@ class ConstellarScans : MangaThemesia("Constellar Scans", "https://constellarsca
?: return super.pageListParse(document)
val descrambledData = descrambleString(tsData).trim()
val match = DESCRAMBLING_KEY_RE.find(descrambledData)?.value
if (match != null) {
Log.d("constellarscans", "device-limited chapter, key: $match")
return decodeDeviceLimitedChapter(match)
}
val imageListJson =
JSON_IMAGE_LIST_REGEX.find(descrambledData)?.groupValues?.get(1).orEmpty()
val imageList = try {
json.parseToJsonElement(imageListJson).jsonArray
// check if the object can be parsed with JSON, else assume it is encrypted
//
// done because constellarscans have shit code and would sometimes give us an invalid key
// for no reason
return try {
val parsedTsData = json.parseToJsonElement(descrambledData).jsonObject
val imageList = parsedTsData["sources"]!!.jsonArray[0].jsonObject["images"]!!.jsonArray
imageList.mapIndexed { idx, it ->
Page(idx, imageUrl = it.jsonPrimitive.content)
}
} catch (_: IllegalArgumentException) {
emptyList()
val match = DESCRAMBLING_KEY_RE.find(descrambledData)?.value
?: throw Exception("Did not receive valid decryption key. Try opening the chapter again.")
Log.d("constellarscans", "device-limited chapter: $match")
decodeDeviceLimitedChapter(match)
}
val scriptPages = imageList.mapIndexed { i, jsonEl ->
Page(i, imageUrl = jsonEl.jsonPrimitive.content)
}
return scriptPages
}
override fun imageRequest(page: Page): Request = super.imageRequest(page).newBuilder()

View File

@ -71,11 +71,11 @@ abstract class MangaThemesia(
return fetchMangaDetails(
SManga.create()
.apply { this.url = "$mangaUrlDirectory/$mangaPath" }
.apply { this.url = "$mangaUrlDirectory/$mangaPath/" }
)
.map {
// Isn't set in returned manga
it.url = "$mangaUrlDirectory/$id"
it.url = "$mangaUrlDirectory/$mangaPath/"
MangasPage(listOf(it), false)
}
}
@ -120,6 +120,7 @@ abstract class MangaThemesia(
else -> { /* Do Nothing */ }
}
}
url.addPathSegment("")
return GET(url.toString())
}

View File

@ -11,7 +11,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator {
override val themeClass = "MangaThemesia"
override val baseVersionCode: Int = 23
override val baseVersionCode: Int = 24
override val sources = listOf(
MultiLang("Asura Scans", "https://www.asurascans.com", listOf("en", "tr"), className = "AsuraScansFactory", pkgName = "asurascans", overrideVersionCode = 18),