Fix Hitomi chapters (#75)

This commit is contained in:
Mike 2020-08-09 20:00:49 -04:00 committed by GitHub
parent 2bc845b1d2
commit 1211b2c86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -372,7 +372,6 @@ class Hitomi(val context: Context) : HttpSource(), LewdSource<HitomiSearchMetada
* @param response the response from the site. * @param response the response from the site.
*/ */
override fun pageListParse(response: Response): List<Page> { override fun pageListParse(response: Response): List<Page> {
val hlId = response.request.url.pathSegments.last().removeSuffix(".js").toLong()
val str = response.body!!.string() val str = response.body!!.string()
val json = JsonParser.parseString(str.removePrefix("var galleryinfo = ")) val json = JsonParser.parseString(str.removePrefix("var galleryinfo = "))
return json["files"].array.mapIndexed { index, jsonElement -> return json["files"].array.mapIndexed { index, jsonElement ->
@ -384,13 +383,24 @@ class Hitomi(val context: Context) : HttpSource(), LewdSource<HitomiSearchMetada
Page( Page(
index, index,
"", "",
"https://${subdomainFromGalleryId(hlId)}a.hitomi.la/$path/$hashPath1/$hashPath2/$hash.$ext" "https://${subdomainFromGalleryId(hashPath2)}a.hitomi.la/$path/$hashPath1/$hashPath2/$hash.$ext"
) )
} }
} }
private fun subdomainFromGalleryId(id: Long): Char { // https://ltn.hitomi.la/common.js
return (97 + id.rem(NUMBER_OF_FRONTENDS)).toChar() private fun subdomainFromGalleryId(pathSegment: String): Char {
var numberOfFrontends = 3
val b = 16
var g = Integer.parseInt(pathSegment, b)
if (g < 0x30) {
numberOfFrontends = 2
}
if (g < 0x09) {
g = 1
}
return (97 + g.rem(numberOfFrontends)).toChar()
} }
/** /**
@ -431,7 +441,6 @@ class Hitomi(val context: Context) : HttpSource(), LewdSource<HitomiSearchMetada
companion object { companion object {
private val INDEX_VERSION_CACHE_TIME_MS = 1000 * 60 * 10 private val INDEX_VERSION_CACHE_TIME_MS = 1000 * 60 * 10
private val PAGE_SIZE = 25 private val PAGE_SIZE = 25
private val NUMBER_OF_FRONTENDS = 2
private val DATE_FORMAT by lazy { private val DATE_FORMAT by lazy {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {