[Manhuagui] Fix UA and parse errors (#1834)
This commit is contained in:
@@ -47,7 +47,7 @@ internal class ManhuaguiParser(context: MangaLoaderContext) :
|
|||||||
LegacyPagedMangaParser(context, MangaParserSource.MANHUAGUI, pageSize = 42) {
|
LegacyPagedMangaParser(context, MangaParserSource.MANHUAGUI, pageSize = 42) {
|
||||||
|
|
||||||
override val configKeyDomain = ConfigKey.Domain("www.manhuagui.com")
|
override val configKeyDomain = ConfigKey.Domain("www.manhuagui.com")
|
||||||
override val userAgentKey = ConfigKey.UserAgent(UserAgents.CHROME_MOBILE)
|
override val userAgentKey = ConfigKey.UserAgent(UserAgents.CHROME_DESKTOP)
|
||||||
|
|
||||||
val configKeyImgServer = ConfigKey.PreferredImageServer(
|
val configKeyImgServer = ConfigKey.PreferredImageServer(
|
||||||
presetValues = arrayOf("us", "us2", "us3", "eu", "eu2", "eu3").associateWith { it },
|
presetValues = arrayOf("us", "us2", "us3", "eu", "eu2", "eu3").associateWith { it },
|
||||||
@@ -64,6 +64,7 @@ internal class ManhuaguiParser(context: MangaLoaderContext) :
|
|||||||
|
|
||||||
override fun getRequestHeaders(): Headers = super.getRequestHeaders().newBuilder()
|
override fun getRequestHeaders(): Headers = super.getRequestHeaders().newBuilder()
|
||||||
.add("Referer", "https://$domain")
|
.add("Referer", "https://$domain")
|
||||||
|
.add("Accept-Encoding", "identity")
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
override val defaultSortOrder: SortOrder
|
override val defaultSortOrder: SortOrder
|
||||||
@@ -355,18 +356,18 @@ internal class ManhuaguiParser(context: MangaLoaderContext) :
|
|||||||
if (input.isBlank()) return null
|
if (input.isBlank()) return null
|
||||||
|
|
||||||
data class Data(var value: Char = '0', var position: Int = 0, var index: Int = 1)
|
data class Data(var value: Char = '0', var position: Int = 0, var index: Int = 1)
|
||||||
|
|
||||||
|
fun Int.power() = 1 shl this
|
||||||
|
fun Int.string() = this.toChar().toString()
|
||||||
|
|
||||||
val keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
val keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||||
val getNextValue = { it: Int -> keyStr.indexOf(input[it]).toChar() }
|
val getNextValue = { it: Int -> keyStr.indexOf(input[it]).toChar() }
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
val dictionary = mutableListOf("0", "1", "2")
|
val dictionary = mutableListOf(0.string(), 1.string(), 2.string())
|
||||||
val data = Data(getNextValue(0), 32, 1)
|
val data = Data(getNextValue(0), 32, 1)
|
||||||
var (bits, numBits, enlargeIn, dictSize) = listOf(0, 3, 4, 4)
|
var (next, bits, numBits, enlargeIn, dictSize) = listOf(0, 0, 3, 4, 4)
|
||||||
var (c, w, entry) = listOf("", "", "")
|
var (c, w, entry) = listOf("", "", "")
|
||||||
|
|
||||||
fun Int.power() = 1 shl this
|
|
||||||
fun Int.string() = this.toChar().toString()
|
|
||||||
|
|
||||||
fun doPower(initBits: Int, initPower: Int, initMaxPower: Int, mode: Int = 0) {
|
fun doPower(initBits: Int, initPower: Int, initMaxPower: Int, mode: Int = 0) {
|
||||||
bits = initBits
|
bits = initBits
|
||||||
var power = initPower
|
var power = initPower
|
||||||
@@ -383,19 +384,23 @@ internal class ManhuaguiParser(context: MangaLoaderContext) :
|
|||||||
}
|
}
|
||||||
when (mode) {
|
when (mode) {
|
||||||
1 -> c = bits.string()
|
1 -> c = bits.string()
|
||||||
2 -> dictionary.add(dictSize++.also { enlargeIn-- }, bits.string())
|
2 -> dictionary.add(dictSize++.also {
|
||||||
|
enlargeIn--
|
||||||
|
next = dictSize - 1
|
||||||
|
}, bits.string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkEnlargeIn() {
|
fun checkEnlargeIn() {
|
||||||
if (enlargeIn-- == 0) {
|
if (enlargeIn == 0) {
|
||||||
enlargeIn = numBits.power()
|
enlargeIn = numBits.power()
|
||||||
numBits++
|
numBits++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doPower(bits, 1, 2)
|
doPower(bits, 1, 2)
|
||||||
when (bits) {
|
next = bits
|
||||||
|
when (next) {
|
||||||
0 -> doPower(0, 1, 8, 1)
|
0 -> doPower(0, 1, 8, 1)
|
||||||
1 -> doPower(0, 1, 16, 1)
|
1 -> doPower(0, 1, 16, 1)
|
||||||
2 -> return ""
|
2 -> return ""
|
||||||
@@ -408,18 +413,19 @@ internal class ManhuaguiParser(context: MangaLoaderContext) :
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (data.index > input.length) return ""
|
if (data.index > input.length) return ""
|
||||||
doPower(0, 1, numBits)
|
doPower(0, 1, numBits)
|
||||||
when (bits) {
|
next = bits
|
||||||
|
when (next) {
|
||||||
0 -> doPower(0, 1, 8, 2).also { checkEnlargeIn() }
|
0 -> doPower(0, 1, 8, 2).also { checkEnlargeIn() }
|
||||||
1 -> doPower(0, 1, 16, 2).also { checkEnlargeIn() }
|
1 -> doPower(0, 1, 16, 2).also { checkEnlargeIn() }
|
||||||
2 -> return builder.toString()
|
2 -> return builder.toString()
|
||||||
}
|
}
|
||||||
entry = when {
|
entry = when {
|
||||||
dictionary.size > bits -> dictionary[bits]
|
dictionary.size > next -> dictionary[next]
|
||||||
bits == dictSize -> w + w[0]
|
next == dictSize -> w + w[0]
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
builder.append(entry)
|
builder.append(entry)
|
||||||
dictionary.add(dictSize++, w + entry[0])
|
dictionary.add(dictSize++, w + entry[0]).also { enlargeIn-- }
|
||||||
w = entry
|
w = entry
|
||||||
checkEnlargeIn()
|
checkEnlargeIn()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user