diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt index 3e97ffaccb..754894b7df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt @@ -71,7 +71,11 @@ class NHentai(delegate: HttpSource, val context: Context) : } override suspend fun parseIntoMetadata(metadata: NHentaiSearchMetadata, input: Response) { - val json = GALLERY_JSON_REGEX.find(input.body.string())!!.groupValues[1].replace( + // AZ --> + val strdata = input.body.string() + val server = MEDIA_SERVER_REGEX.find(strdata)?.groupValues?.get(1)?.toInt() ?: 1 + // AZ <-- + val json = GALLERY_JSON_REGEX.find(strdata)!!.groupValues[1].replace( UNICODE_ESCAPE_REGEX, ) { it.groupValues[1].toInt(radix = 16).toChar().toString() } val jsonResponse = jsonParser.decodeFromString(json) @@ -85,6 +89,10 @@ class NHentai(delegate: HttpSource, val context: Context) : mediaId = jsonResponse.mediaId + // AZ --> + mediaServer = server + // AZ <-- + jsonResponse.title?.let { title -> japaneseTitle = title.japanese shortTitle = title.pretty @@ -191,17 +199,33 @@ class NHentai(delegate: HttpSource, val context: Context) : return PagePreviewPage( page, metadata.pageImageTypes.mapIndexed { index, s -> - PagePreviewInfo(index + 1, imageUrl = thumbnailUrlFromType(metadata.mediaId!!, index + 1, s)!!) + PagePreviewInfo( + index + 1, + imageUrl = thumbnailUrlFromType( + metadata.mediaId!!, + // AZ --> + metadata.mediaServer ?: 1, + // AZ <-- + index + 1, + s, + )!!, + ) }, false, 1, ) } - private fun thumbnailUrlFromType(mediaId: String, page: Int, t: String) = - NHentaiSearchMetadata.typeToExtension(t)?.let { - "https://t3.nhentai.net/galleries/$mediaId/${page}t.$it" - } + private fun thumbnailUrlFromType( + mediaId: String, + // AZ --> + mediaServer: Int, + // AZ <-- + page: Int, + t: String, + ) = NHentaiSearchMetadata.typeToExtension(t)?.let { + "https://t$mediaServer.nhentai.net/galleries/$mediaId/${page}t.$it" + } override suspend fun fetchPreviewImage(page: PagePreviewInfo, cacheControl: CacheControl?): Response { return client.newCachelessCallWithProgress( @@ -222,6 +246,11 @@ class NHentai(delegate: HttpSource, val context: Context) : } private val GALLERY_JSON_REGEX = Regex(".parse\\(\"(.*)\"\\);") + + // AZ --> + private val MEDIA_SERVER_REGEX = Regex("media_server\\s*:\\s*(\\d+)") + + // AZ <-- private val UNICODE_ESCAPE_REGEX = Regex("\\\\u([0-9a-fA-F]{4})") private const val TITLE_PREF = "Display manga title as:" } diff --git a/source-api/src/commonMain/kotlin/exh/metadata/metadata/NHentaiSearchMetadata.kt b/source-api/src/commonMain/kotlin/exh/metadata/metadata/NHentaiSearchMetadata.kt index 1885dd6de3..1be880c10c 100644 --- a/source-api/src/commonMain/kotlin/exh/metadata/metadata/NHentaiSearchMetadata.kt +++ b/source-api/src/commonMain/kotlin/exh/metadata/metadata/NHentaiSearchMetadata.kt @@ -29,6 +29,10 @@ class NHentaiSearchMetadata : RaisedSearchMetadata() { var mediaId: String? = null + // AZ --> + var mediaServer: Int? = null + // AZ <-- + var japaneseTitle by titleDelegate(TITLE_TYPE_JAPANESE) var englishTitle by titleDelegate(TITLE_TYPE_ENGLISH) var shortTitle by titleDelegate(TITLE_TYPE_SHORT) @@ -45,8 +49,11 @@ class NHentaiSearchMetadata : RaisedSearchMetadata() { val key = nhId?.let { nhIdToPath(it) } val cover = if (mediaId != null) { + // AZ --> + val server = mediaServer ?: 1 + // AZ <-- typeToExtension(coverImageType)?.let { - "https://t.nhentai.net/galleries/$mediaId/cover.$it" + "https://t$server.nhentai.net/galleries/$mediaId/cover.$it" } } else { null