Use MediaServer in Json for NHentai
Co-authored-by: 4521 <18432684+az4521@users.noreply.github.com>
This commit is contained in:
parent
f919d42370
commit
f876cdb037
@ -70,7 +70,9 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun parseIntoMetadata(metadata: NHentaiSearchMetadata, input: Response) {
|
override suspend fun parseIntoMetadata(metadata: NHentaiSearchMetadata, input: Response) {
|
||||||
val json = GALLERY_JSON_REGEX.find(input.body.string())!!.groupValues[1].replace(
|
val body = input.body.string()
|
||||||
|
val server = MEDIA_SERVER_REGEX.find(body)?.groupValues?.get(1)?.toInt() ?: 1
|
||||||
|
val json = GALLERY_JSON_REGEX.find(body)!!.groupValues[1].replace(
|
||||||
UNICODE_ESCAPE_REGEX,
|
UNICODE_ESCAPE_REGEX,
|
||||||
) { it.groupValues[1].toInt(radix = 16).toChar().toString() }
|
) { it.groupValues[1].toInt(radix = 16).toChar().toString() }
|
||||||
val jsonResponse = jsonParser.decodeFromString<JsonResponse>(json)
|
val jsonResponse = jsonParser.decodeFromString<JsonResponse>(json)
|
||||||
@ -84,6 +86,8 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
|||||||
|
|
||||||
mediaId = jsonResponse.mediaId
|
mediaId = jsonResponse.mediaId
|
||||||
|
|
||||||
|
mediaServer = server
|
||||||
|
|
||||||
jsonResponse.title?.let { title ->
|
jsonResponse.title?.let { title ->
|
||||||
japaneseTitle = title.japanese
|
japaneseTitle = title.japanese
|
||||||
shortTitle = title.pretty
|
shortTitle = title.pretty
|
||||||
@ -190,16 +194,23 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
|||||||
return PagePreviewPage(
|
return PagePreviewPage(
|
||||||
page,
|
page,
|
||||||
metadata.pageImageTypes.mapIndexed { index, s ->
|
metadata.pageImageTypes.mapIndexed { index, s ->
|
||||||
PagePreviewInfo(index + 1, imageUrl = thumbnailUrlFromType(metadata.mediaId!!, index + 1, s)!!)
|
PagePreviewInfo(
|
||||||
|
index + 1,
|
||||||
|
imageUrl = thumbnailUrlFromType(metadata.mediaId!!, metadata.mediaServer ?: 1, index + 1, s)!!
|
||||||
|
)
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun thumbnailUrlFromType(mediaId: String, page: Int, t: String) =
|
private fun thumbnailUrlFromType(
|
||||||
NHentaiSearchMetadata.typeToExtension(t)?.let {
|
mediaId: String,
|
||||||
"https://t1.nhentai.net/galleries/$mediaId/${page}t.$it"
|
mediaServer: Int,
|
||||||
|
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 {
|
override suspend fun fetchPreviewImage(page: PagePreviewInfo, cacheControl: CacheControl?): Response {
|
||||||
@ -221,6 +232,7 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val GALLERY_JSON_REGEX = Regex(".parse\\(\"(.*)\"\\);")
|
private val GALLERY_JSON_REGEX = Regex(".parse\\(\"(.*)\"\\);")
|
||||||
|
private val MEDIA_SERVER_REGEX = Regex("media_server\\s*:\\s*(\\d+)")
|
||||||
private val UNICODE_ESCAPE_REGEX = Regex("\\\\u([0-9a-fA-F]{4})")
|
private val UNICODE_ESCAPE_REGEX = Regex("\\\\u([0-9a-fA-F]{4})")
|
||||||
private const val TITLE_PREF = "Display manga title as:"
|
private const val TITLE_PREF = "Display manga title as:"
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class NHentaiSearchMetadata : RaisedSearchMetadata() {
|
|||||||
var favoritesCount: Long? = null
|
var favoritesCount: Long? = null
|
||||||
|
|
||||||
var mediaId: String? = null
|
var mediaId: String? = null
|
||||||
|
var mediaServer: Int? = null
|
||||||
|
|
||||||
var japaneseTitle by titleDelegate(TITLE_TYPE_JAPANESE)
|
var japaneseTitle by titleDelegate(TITLE_TYPE_JAPANESE)
|
||||||
var englishTitle by titleDelegate(TITLE_TYPE_ENGLISH)
|
var englishTitle by titleDelegate(TITLE_TYPE_ENGLISH)
|
||||||
@ -46,7 +47,7 @@ class NHentaiSearchMetadata : RaisedSearchMetadata() {
|
|||||||
|
|
||||||
val cover = if (mediaId != null) {
|
val cover = if (mediaId != null) {
|
||||||
typeToExtension(coverImageType)?.let {
|
typeToExtension(coverImageType)?.let {
|
||||||
"https://t1.nhentai.net/galleries/$mediaId/cover.$it"
|
"https://t${mediaServer ?: 1}.nhentai.net/galleries/$mediaId/cover.$it"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user