Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Nhentai cover #587

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonResponse>(json)
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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:"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading