Skip to content

Commit

Permalink
fix nh images not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
az4521 committed Dec 7, 2024
1 parent 5e4e06e commit 3278e2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 201,7 @@ class NHentai(context: Context) : HttpSource(), LewdSource<NHentaiSearchMetadata
metadata: NHentaiSearchMetadata,
input: Response
) {
val server = MEDIA_SERVER_REGEX.find(input.body.string())?.groupValues?.get(1)?.toInt() ?: 1
val json =
GALLERY_JSON_REGEX.find(input.body.string())!!.groupValues[1].replace(UNICODE_ESCAPE_REGEX) {
it.groupValues[1].toInt(
Expand All @@ -218,6 219,8 @@ class NHentai(context: Context) : HttpSource(), LewdSource<NHentaiSearchMetadata

mediaId = obj["media_id"].nullString

mediaServer = server

obj["title"].nullObj?.let { title ->
japaneseTitle = title["japanese"].nullString
shortTitle = title["pretty"].nullString
Expand Down Expand Up @@ -275,7 278,7 @@ class NHentai(context: Context) : HttpSource(), LewdSource<NHentaiSearchMetadata
emptyList()
} else {
metadata.pageImageTypes.mapIndexed { index, s ->
val imageUrl = imageUrlFromType(metadata.mediaId!!, index 1, s)
val imageUrl = imageUrlFromType(metadata.mediaId!!, metadata.mediaServer!!, index 1, s)
Page(index, imageUrl!!, imageUrl)
}
}
Expand All @@ -285,10 288,11 @@ class NHentai(context: Context) : HttpSource(), LewdSource<NHentaiSearchMetadata

fun imageUrlFromType(
mediaId: String,
mediaServer: Int,
page: Int,
t: String
) = NHentaiSearchMetadata.typeToExtension(t)?.let {
"https://i.nhentai.net/galleries/$mediaId/$page.$it"
"https://i$mediaServer.nhentai.net/galleries/$mediaId/$page.$it"
}

override fun chapterListParse(response: Response): List<SChapter> {
Expand Down Expand Up @@ -352,6 356,7 @@ class NHentai(context: Context) : HttpSource(), LewdSource<NHentaiSearchMetadata

companion object {
private val GALLERY_JSON_REGEX = Regex(".parse\\(\"(.*)\"\\);")
private val MEDIA_SERVER_REGEX = Regex("media_server:\\s*(\\d ),")
private val UNICODE_ESCAPE_REGEX = Regex("\\\\u([0-9a-fA-F]{4})")
private const val REVERSE_PARAM = "TEH_REVERSE"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@ class NHentaiSearchMetadata : RaisedSearchMetadata() {
var favoritesCount: Long? = null

var mediaId: String? = null
var mediaServer: Int? = null

var japaneseTitle by titleDelegate(TITLE_TYPE_JAPANESE)
var englishTitle by titleDelegate(TITLE_TYPE_ENGLISH)
Expand Down

0 comments on commit 3278e2f

Please sign in to comment.