fix: Nhentai cover (#587)
* fix nh images not loading (cherry picked from commit 3278e2fe918de87056528eb4aeaf57be6d71d35a) * fix thumbs on nh (cherry picked from commit aa295377e78a0d5a658ec983f7a28b6345d86c09) * default to media server 1 for old nh entries (cherry picked from commit 2990a5e7ab98de5dc89c0affe7e265827d3244a3) --------- Co-authored-by: az4521 <18432684+az4521@users.noreply.github.com>
This commit is contained in:
parent
573f1cf20a
commit
7c2467aed5
2 changed files with 43 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
@ -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,16 +199,32 @@ 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 {
|
||||
|
|
@ -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:"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue