Fix normal preview in exhentai

Remove force e-hentai thumb option due to infeasible.
This commit is contained in:
FooIbar committed 2024-08-17 00:52:44 +08:00
1 parent c6b793923e
commit 302b57d4ac
11 files changed
+31 -42

No files matched your search

@@ -142,7 +142,6 @@ object Settings : DataStorePreferences(null) {
var launchPage by intPref("launch_page_2", 0)
var commentThreshold by intPref("comment_threshold", -101)
var hardwareBitmapThreshold by intPref("hardware_bitmap_threshold", 16384)
var forceEhThumb by boolPref("force_eh_thumb", false)
var showComments by boolPref("show_gallery_comments", true)
var requestNews by boolPref("request_news", false).observed { updateWhenRequestNewsChanges() }
var hideHvEvents by boolPref("hide_hv_events", false)
@@ -15,32 +15,36 @@
*/
package com.hippo.ehviewer.client
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.data.GalleryPreview
import com.hippo.ehviewer.client.data.NormalGalleryPreview
// ExHentai Large Preview: https://s.exhentai.org/t/***
// ExHentai Normal Preview: https://s.exhentai.org/m/***
// EHentai Normal Preview: https://ehgt.org/m/***
// ExHentai Normal Preview: https://*.hath.network/cm/[timed token]/[gid]-[index].jpg
// EHentai Normal Preview: https://ehgt.org/m/[permanent token]/[gid]-[index].jpg
// EHentai Large Preview: https://ehgt.org/***
private const val URL_PREFIX_THUMB_E = "https://ehgt.org/"
private const val URL_PREFIX_THUMB_EX = "https://s.exhentai.org/"
private const val URL_PREFIX_LARGE_THUMB_EX = URL_PREFIX_THUMB_EX + "t/"
private const val URL_PREFIX_THUMB_EX = "https://s.exhentai.org/t/"
private const val NORMAL_PREVIEW_PREFIX = "$"
private val NormalPreviewKeyRegex = Regex("/(\\d+-\\d+)\\.jpg$")
fun getImageKey(gid: Long, index: Int): String = "image:$gid:$index"
fun getThumbKey(url: String): String = url.removePrefix(URL_PREFIX_THUMB_E).removePrefix(URL_PREFIX_LARGE_THUMB_EX).removePrefix(URL_PREFIX_THUMB_EX)
fun getThumbKey(url: String): String = url.removePrefix(thumbPrefix)
val GalleryPreview.url
get() = if (exThumb) {
if (this is NormalGalleryPreview) URL_PREFIX_THUMB_EX else URL_PREFIX_LARGE_THUMB_EX
val String.isNormalPreviewKey
get() = startsWith(NORMAL_PREVIEW_PREFIX)
val GalleryPreview.imageKey
get() = if (this is NormalGalleryPreview) {
NormalPreviewKeyRegex.find(url)?.run { NORMAL_PREVIEW_PREFIX + groupValues[1] }
} else {
URL_PREFIX_THUMB_E
} + imageKey
getThumbKey(url)
}
val GalleryInfo.thumbUrl
get() = (if (exThumb) URL_PREFIX_LARGE_THUMB_EX else URL_PREFIX_THUMB_E) + thumbKey!!
get() = thumbPrefix + thumbKey!!
val exThumb get() = EhUtils.isExHentai && !Settings.forceEhThumb
private val thumbPrefix
get() = if (EhUtils.isExHentai) URL_PREFIX_THUMB_EX else URL_PREFIX_THUMB_E
@@ -60,14 +60,10 @@ object EhUrl {
}
val apiUrl: String
get() = if (Settings.forceEhThumb) {
API_E
} else {
when (Settings.gallerySite) {
SITE_E -> API_E
SITE_EX -> API_EX
else -> API_E
}
get() = when (Settings.gallerySite) {
SITE_E -> API_E
SITE_EX -> API_EX
else -> API_E
}
val referer: String
@@ -19,19 +19,19 @@ import android.os.Parcelable
import kotlinx.parcelize.Parcelize
interface GalleryPreview : Parcelable {
val imageKey: String
val url: String
val position: Int
}
@Parcelize
data class LargeGalleryPreview(
override val imageKey: String,
override val url: String,
override val position: Int,
) : GalleryPreview
@Parcelize
data class NormalGalleryPreview(
override val imageKey: String,
override val url: String,
override val position: Int,
val offsetX: Int,
val clipWidth: Int,
@@ -458,9 +458,9 @@ object GalleryDetailParser {
check(PATTERN_LARGE_PREVIEW.containsMatchIn(body))
return PATTERN_LARGE_PREVIEW.findAll(body).unzip {
val position = it.groupValues[2].toInt() - 1
val imageKey = getThumbKey(it.groupValues[3].trim())
val url = it.groupValues[3].trim()
val pageUrl = it.groupValues[1].trim()
LargeGalleryPreview(imageKey, position) to pageUrl
LargeGalleryPreview(url, position) to pageUrl
}.run {
first.toList() to second.toList()
}
@@ -470,12 +470,12 @@ object GalleryDetailParser {
check(PATTERN_NORMAL_PREVIEW.containsMatchIn(body))
return PATTERN_NORMAL_PREVIEW.findAll(body).unzip {
val position = it.groupValues[6].toInt() - 1
val imageKey = getThumbKey(it.groupValues[3].trim())
val url = it.groupValues[3].trim()
val xOffset = it.groupValues[4].toIntOrNull() ?: 0
val width = it.groupValues[1].toInt()
val height = it.groupValues[2].toInt()
val pageUrl = it.groupValues[5].trim()
NormalGalleryPreview(imageKey, position, xOffset, width, height) to pageUrl
NormalGalleryPreview(url, position, xOffset, width, height) to pageUrl
}.run {
first.toList() to second.toList()
}
@@ -16,7 +16,7 @@ import com.hippo.ehviewer.client.CHROME_ACCEPT_LANGUAGE
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.data.GalleryPreview
import com.hippo.ehviewer.client.data.NormalGalleryPreview
import com.hippo.ehviewer.client.url
import com.hippo.ehviewer.client.imageKey
import com.hippo.ehviewer.spider.DownloadInfoMagics.encodeMagicRequestOrUrl
import io.ktor.http.HttpHeaders
@@ -3,6 +3,7 @@ package com.hippo.ehviewer.coil
import coil3.intercept.Interceptor
import coil3.request.ImageResult
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.isNormalPreviewKey
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.CancellableContinuation
@@ -41,7 +42,7 @@ object MergeInterceptor : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val req = chain.request
val key = req.memoryCacheKey?.takeIf { it.startsWith("m/") || Settings.preloadThumbAggressively } ?: return withContext(req.interceptorCoroutineContext) { chain.proceed() }
val key = req.memoryCacheKey?.takeIf { it.isNormalPreviewKey || Settings.preloadThumbAggressively } ?: return withContext(req.interceptorCoroutineContext) { chain.proceed() }
suspendCancellableCoroutine { continuation ->
synchronized(pendingContinuationMapLock) {
@@ -333,11 +333,6 @@ fun EhScreen(navigator: DestinationsNavigator) {
entryValueRes = R.array.thumb_resolution_entry_values,
value = thumbResolution,
)
SwitchPreference(
title = stringResource(id = R.string.settings_eh_force_eh_thumb),
summary = stringResource(id = R.string.settings_eh_force_eh_thumb_summary),
value = Settings::forceEhThumb,
)
var showGalleryPages by Settings.showGalleryPages.asMutableState()
SwitchPref(
checked = showGalleryPages,
@@ -303,8 +303,6 @@
<string name="settings_eh_thumb_resolution">缩略图分辨率</string>
<string name="settings_eh_thumb_resolution_summary">%s,指定分辨率可能使获取缩略图失败</string>
<string name="settings_eh_thumb_resolution_auto">自动</string>
<string name="settings_eh_force_eh_thumb">强制使用 e-hentai 缩略图/API服务器</string>
<string name="settings_eh_force_eh_thumb_summary">若 exhentai 加载失败可尝试此项\n注意此项将使用 e-hentai 设置加载图像</string>
<string name="settings_eh_show_jpn_title">显示日文标题</string>
<string name="settings_eh_show_jpn_title_summary">需同时在 EHentai 网站设置中启用 Japanese Title</string>
<string name="settings_eh_show_gallery_pages">显示画廊页数</string>
@@ -303,8 +303,6 @@
<string name="settings_eh_thumb_resolution">縮圖解析度</string>
<string name="settings_eh_thumb_resolution_summary">%s,指定解析度可能會使縮圖取得失敗</string>
<string name="settings_eh_thumb_resolution_auto">自動</string>
<string name="settings_eh_force_eh_thumb">強制 e-hentai 縮圖/API 伺服器</string>
<string name="settings_eh_force_eh_thumb_summary">若exhentai載入遇到問題可嘗試此項\n注意,此項將使用 e-hentai 設定來載入圖片。</string>
<string name="settings_eh_show_jpn_title">顯示日文標題</string>
<string name="settings_eh_show_jpn_title_summary">需同時在 EHentai 網站設定中啟用 Japanese Title</string>
<string name="settings_eh_show_gallery_pages">顯示圖庫頁數</string>
-2
View File
@@ -319,8 +319,6 @@
<string name="settings_eh_thumb_resolution">Thumb resolution</string>
<string name="settings_eh_thumb_resolution_summary">Currently %s. Certain resolutions might cause getting thumb failed</string>
<string name="settings_eh_thumb_resolution_auto">Auto</string>
<string name="settings_eh_force_eh_thumb">Force e-hentai thumb/API server</string>
<string name="settings_eh_force_eh_thumb_summary">Try this if you have trouble loading from exhentai\nNote this will use e-hentai settings to load images</string>
<string name="settings_eh_show_jpn_title">Show Japanese title</string>
<string name="settings_eh_show_jpn_title_summary">Require enabling Japanese Title in Settings on EHentai website</string>
<string name="settings_eh_show_gallery_pages">Show gallery pages</string>