diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 59037bbf..bcfc24b8 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -1,6 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -12,6 +23,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 65b8e5e1..13afaa32 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -86,5 +86,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 3373fc1d..d93660f5 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -38,7 +38,7 @@ android {
minSdkVersion 16
targetSdkVersion 31
versionCode 69
- versionName "5.2.25"
+ versionName "5.3.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
@@ -67,12 +67,12 @@ android {
viewBinding true
}
kotlinOptions {
- jvmTarget = JavaVersion.VERSION_1_8.toString()
+ jvmTarget = JavaVersion.VERSION_11.toString()
freeCompilerArgs += "-Xuse-experimental=kotlin.Experimental"
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
+ sourceCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_11
}
}
@@ -91,7 +91,6 @@ dependencies {
implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation "androidx.biometric:biometric:1.1.0"
implementation "androidx.work:work-runtime-ktx:2.7.1"
- implementation 'androidx.webkit:webkit:1.4.0'
implementation "com.daimajia.swipelayout:library:1.2.0@aar"
@@ -129,6 +128,10 @@ dependencies {
implementation "org.jsoup:jsoup:1.14.3"
+ implementation ("app.cash.zipline:zipline:1.0.0-SNAPSHOT") {
+ exclude group: "com.squareup.okio", module: "okio"
+ }
+
implementation "xyz.quaver:documentfilex:0.7.2"
implementation "xyz.quaver:floatingsearchview:1.1.7"
diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
index f5f160fa..650f9aa3 100644
--- a/app/release/output-metadata.json
+++ b/app/release/output-metadata.json
@@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 69,
- "versionName": "5.2.25",
+ "versionName": "5.3.0",
"outputFile": "app-release.apk"
}
],
diff --git a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt
index cbb8cde9..b278adff 100644
--- a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt
+++ b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt
@@ -20,18 +20,18 @@
package xyz.quaver.pupil
-import android.os.Build
import android.util.Log
-import android.webkit.*
-import android.widget.Toast
import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.platform.app.InstrumentationRegistry
-import com.google.firebase.crashlytics.FirebaseCrashlytics
-import kotlinx.coroutines.*
+import kotlinx.coroutines.runBlocking
+import okhttp3.OkHttpClient
+import okhttp3.Request
+import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import xyz.quaver.pupil.hitomi.*
+import java.util.*
+import java.util.concurrent.TimeUnit
/**
* Instrumented test, which will execute on an Android device.
@@ -40,81 +40,142 @@ import xyz.quaver.pupil.hitomi.*
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
+// @Before
+// fun init() {
+// val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+// }
+
@Before
fun init() {
- val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+ clientBuilder = OkHttpClient.Builder()
+ .readTimeout(0, TimeUnit.SECONDS)
+ .writeTimeout(0, TimeUnit.SECONDS)
+ .callTimeout(0, TimeUnit.SECONDS)
+ .connectTimeout(0, TimeUnit.SECONDS)
+ .addInterceptor { chain ->
+ val request = chain.request().newBuilder()
+ .header("Referer", "https://hitomi.la/")
+ .build()
- runBlocking {
- withContext(Dispatchers.Main) {
- initWebView(appContext)
+ chain.proceed(request)
}
- }
}
@Test
- fun test_getGalleryIDsFromNozomi() {
- runBlocking {
- val result = getGalleryIDsFromNozomi(null, "boten", "all")
+ fun test_empty() {
+ print(
+ "".trim()
+ .replace(Regex("""^\?"""), "")
+ .lowercase(Locale.getDefault())
+ .split(Regex("\\s+"))
+ .map {
+ it.replace('_', ' ')
+ })
+ }
+ @Test
+ fun test_nozomi() {
+ val nozomi = getGalleryIDsFromNozomi(null, "index", "all")
- Log.d("PUPILD", "getGalleryIDsFromNozomi: ${result.size}")
- }
+ Log.d("PUPILD", nozomi.size.toString())
}
@Test
- fun test_getGalleryIDsForQuery() {
- runBlocking {
- val result = getGalleryIDsForQuery("female:crotch tattoo")
+ fun test_search() {
+ val ids = getGalleryIDsForQuery("language:korean").reversed()
- Log.d("PUPILD", "getGalleryIDsForQuery: ${result.size}")
- }
+ print(ids.size)
}
@Test
- fun test_getSuggestionsForQuery() {
- runBlocking {
- val result = getSuggestionsForQuery("fem")
+ fun test_suggestions() {
+ val suggestions = getSuggestionsForQuery("language:g")
- Log.d("PUPILD", "getSuggestionsForQuery: ${result.size}")
+ print(suggestions)
+ }
+
+ @Test
+ fun test_doSearch() {
+ val r = runBlocking {
+ doSearch("language:korean")
+ }
+
+ Log.d("PUPILD", r.take(10).toString())
+ }
+
+ @Test
+ fun test_getBlock() {
+ val galleryBlock = getGalleryBlock(2097576)
+
+ print(galleryBlock)
+ }
+
+ @Test
+ fun test_getGallery() {
+ val gallery = getGallery(2097751)
+
+ print(gallery)
+ }
+
+ @Test
+ fun test_getGalleryInfo() {
+ val info = getGalleryInfo(1469394)
+
+ print(info)
+ }
+
+ @Test
+ fun test_getReader() {
+ val reader = getGalleryInfo(1722144)
+
+ print(reader)
+ }
+
+ @Test
+ fun test_getImages() {
+ val galleryID = 2099306
+
+ val images = getGalleryInfo(galleryID).files.map {
+ imageUrlFromImage(galleryID, it,false)
+ }
+
+ images.forEachIndexed { index, image ->
+ println("Testing $index/${images.size}: $image")
+ val response = client.newCall(
+ Request.Builder()
+ .url(image)
+ .header("Referer", "https://hitomi.la/")
+ .build()
+ ).execute()
+
+ assertEquals(200, response.code())
+
+ println("$index/${images.size} Passed")
}
}
@Test
fun test_urlFromUrlFromHash() {
- runBlocking {
- val galleryInfo = getGalleryInfo(2102416)
+ val url = urlFromUrlFromHash(1531795, GalleryFiles(
+ 212, "719d46a7556be0d0021c5105878507129b5b3308b02cf67f18901b69dbb3b5ef", 1, "00.jpg", 300
+ ), "webp")
- val result = galleryInfo.files.map {
- imageUrlFromImage(2102416, it, false)
- }
-
- Log.d("PUPILD", result.toString())
- }
+ print(url)
}
- @Test
- fun test_getGalleryInfo() {
- runBlocking {
- val galleryInfo = getGalleryInfo(2102416)
+// @Test
+// suspend fun test_doSearch_extreme() {
+// val query = "language:korean -tag:sample -female:humiliation -female:diaper -female:strap-on -female:squirting -female:lizard_girl -female:voyeurism -type:artistcg -female:blood -female:ryona -male:blood -male:ryona -female:crotch_tattoo -male:urethra_insertion -female:living_clothes -male:tentacles -female:slave -female:gag -male:gag -female:wooden_horse -male:exhibitionism -male:miniguy -female:mind_break -male:mind_break -male:unbirth -tag:scanmark -tag:no_penetration -tag:nudity_only -female:enema -female:brain_fuck -female:navel_fuck -tag:novel -tag:mosaic_censorship -tag:webtoon -male:rape -female:rape -female:yuri -male:anal -female:anal -female:futanari -female:huge_breasts -female:big_areolae -male:torture -male:stuck_in_wall -female:stuck_in_wall -female:torture -female:birth -female:pregnant -female:drugs -female:bdsm -female:body_writing -female:cbt -male:dark_skin -male:insect -female:insect -male:vore -female:vore -female:vomit -female:urination -female:urethra_insertion -tag:mmf_threesome -female:sex_toys -female:double_penetration -female:eggs -female:prolapse -male:smell -male:bestiality -female:bestiality -female:big_ass -female:milf -female:mother -male:dilf -male:netorare -female:netorare -female:cosplaying -female:filming -female:armpit_sex -female:armpit_licking -female:tickling -female:lactation -male:skinsuit -female:skinsuit -male:bbm -female:prostitution -female:double_penetration -female:females_only -male:males_only -female:tentacles -female:tentacles -female:stomach_deformation -female:hairy_armpits -female:large_insertions -female:mind_control -male:orc -female:dark_skin -male:yandere -female:yandere -female:scat -female:toddlercon -female:bbw -female:hairy -male:cuntboy -male:lactation -male:drugs -female:body_modification -female:monoeye -female:chikan -female:long_tongue -female:harness -female:fisting -female:glory_hole -female:latex -male:latex -female:unbirth -female:giantess -female:sole_dickgirl -female:robot -female:doll_joints -female:machine -tag:artbook -male:cbt -female:farting -male:farting -male:midget -female:midget -female:exhibitionism -male:monster -female:big_nipples -female:big_clit -female:gyaru -female:piercing -female:necrophilia -female:snuff -female:smell -male:cheating -female:cheating -male:snuff -female:harem -male:harem"
+// print(doSearch(query).size)
+// }
- Log.d("PUPILD", galleryInfo.toString())
- }
- }
+// @Test
+// suspend fun test_parse() {
+// print(doSearch("-male:yaoi -female:yaoi -female:loli").size)
+// }
@Test
- fun test_getGallery() {
- runBlocking {
- val gallery = getGallery(2109479)
-
- Log.d("PUPILD", gallery.toString())
- }
- }
-
- @Test
- fun test_getGalleryBlock() {
- runBlocking {
- val block = getGalleryBlock(2119310)
-
- Log.d("PUPILD", block.toString())
- }
+ fun test_subdomainFromUrl() {
+ val galleryInfo = getGalleryInfo(1929109).files[2]
+ print(urlFromUrlFromHash(1929109, galleryInfo, "webp", null, "a"))
}
}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/quaver/pupil/Pupil.kt b/app/src/main/java/xyz/quaver/pupil/Pupil.kt
index 4c701164..8998cdcb 100644
--- a/app/src/main/java/xyz/quaver/pupil/Pupil.kt
+++ b/app/src/main/java/xyz/quaver/pupil/Pupil.kt
@@ -18,7 +18,6 @@
package xyz.quaver.pupil
-import android.annotation.SuppressLint
import android.app.Application
import android.app.Notification
import android.app.NotificationChannel
@@ -28,27 +27,26 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import android.util.Log
-import android.webkit.*
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
-import androidx.webkit.WebViewCompat
+import app.cash.zipline.QuickJs
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
import com.github.piasy.biv.BigImageViewer
import com.github.piasy.biv.loader.fresco.FrescoImageLoader
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import com.google.android.gms.security.ProviderInstaller
+import com.google.firebase.FirebaseApp
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.*
-import kotlinx.coroutines.flow.MutableSharedFlow
-import kotlinx.coroutines.flow.asSharedFlow
-import kotlinx.serialization.decodeFromString
-import kotlinx.serialization.json.Json
-import okhttp3.*
+import okhttp3.Dispatcher
+import okhttp3.Interceptor
+import okhttp3.OkHttpClient
+import okhttp3.Response
import xyz.quaver.io.FileX
import xyz.quaver.pupil.hitomi.evaluationContext
-import xyz.quaver.pupil.types.JavascriptException
+import xyz.quaver.pupil.hitomi.readText
import xyz.quaver.pupil.types.Tag
import xyz.quaver.pupil.util.*
import java.io.File
@@ -79,138 +77,11 @@ val client: OkHttpClient
clientHolder = it
}
-@SuppressLint("StaticFieldLeak")
-lateinit var webView: WebView
-val _webViewFlow = MutableSharedFlow>()
-val webViewFlow = _webViewFlow.asSharedFlow()
-var webViewReady = false
-var oldWebView = false
-private var reloadJob: Job? = null
-
-fun reloadWebView() {
- if (reloadJob?.isActive == true) return
-
- reloadJob = CoroutineScope(Dispatchers.IO).launch {
- webViewReady = false
- oldWebView = false
-
- evaluationContext.cancelChildren(CancellationException("reload"))
-
- runCatching {
- URL(
- if (BuildConfig.DEBUG)
- "https://tom5079.github.io/PupilSources/hitomi-dev.html"
- else
- "https://tom5079.github.io/PupilSources/hitomi.html"
- ).readText()
- }.getOrNull()?.let { html ->
- launch(Dispatchers.Main) {
- webView.loadDataWithBaseURL(
- "https://hitomi.la/",
- html,
- "text/html",
- null,
- null
- )
- }
- }
- }
-}
-
-private var htmlVersion: String = ""
-fun reloadWhenFailedOrUpdate() = CoroutineScope(Dispatchers.Default).launch {
- while (true) {
- if (
- (!webViewReady && !oldWebView) ||
- runCatching {
- URL(
- if (BuildConfig.DEBUG)
- "https://tom5079.github.io/PupilSources/hitomi-dev.html.ver"
- else
- "https://tom5079.github.io/PupilSources/hitomi.html.ver"
- ).readText()
- }.getOrNull().let { version ->
- (!version.isNullOrEmpty() && version != htmlVersion).also {
- if (it) htmlVersion = version!!
- }
- }
- ) {
- reloadWebView()
- }
-
- delay(if (webViewReady) 10000 else 1000)
- }
-}
-
-@SuppressLint("SetJavaScriptEnabled")
-fun initWebView(context: Context) {
- if (BuildConfig.DEBUG) WebView.setWebContentsDebuggingEnabled(true)
-
- webView = WebView(context).apply {
- with (settings) {
- javaScriptEnabled = true
- domStorageEnabled = true
- }
-
- userAgent = settings.userAgentString
-
- webViewClient = object: WebViewClient() {
- override fun onPageFinished(view: WebView?, url: String?) {
- webView.evaluateJavascript("try { self_test() } catch (err) { 'err' }") {
- val result: String = Json.decodeFromString(it)
-
- oldWebView = result == "es2020_unsupported";
- webViewReady = result == "OK";
- }
- }
-
- override fun onReceivedError(
- view: WebView?,
- request: WebResourceRequest?,
- error: WebResourceError?
- ) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- FirebaseCrashlytics.getInstance().log(
- "onReceivedError: ${error?.description}"
- )
- }
- }
- }
-
- webChromeClient = object: WebChromeClient() {
- override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
- FirebaseCrashlytics.getInstance().log(
- "onConsoleMessage: ${consoleMessage?.message()} (${consoleMessage?.sourceId()}:${consoleMessage?.lineNumber()})"
- )
-
- return super.onConsoleMessage(consoleMessage)
- }
- }
-
- addJavascriptInterface(object {
- @JavascriptInterface
- fun onResult(uid: String, result: String) {
- CoroutineScope(Dispatchers.Unconfined).launch {
- _webViewFlow.emit(uid to result)
- }
- }
- @JavascriptInterface
- fun onError(uid: String, script: String, message: String, stack: String) {
- CoroutineScope(Dispatchers.Unconfined).launch {
- _webViewFlow.emit(uid to "")
- }
-
- FirebaseCrashlytics.getInstance().recordException(
- JavascriptException("onError script: $script\nmessage: $message\nstack: $stack")
- )
- }
- }, "Callback")
- }
-
- reloadWhenFailedOrUpdate()
-}
-
-lateinit var userAgent: String
+private var version = ""
+var runtimeReady = false
+ private set
+lateinit var runtime: QuickJs
+ private set
class Pupil : Application() {
@@ -219,12 +90,35 @@ class Pupil : Application() {
private set
}
- @SuppressLint("SetJavaScriptEnabled")
+ init {
+ CoroutineScope(Dispatchers.IO).launch {
+ withContext(evaluationContext) {
+ runtime = QuickJs.create()
+ }
+ while (true) {
+ kotlin.runCatching {
+ val newVersion = URL("https://tom5079.github.io/PupilSources/hitomi.html.ver").readText()
+
+ if (version != newVersion) {
+ runtimeReady = false
+ version = newVersion
+ evaluationContext.cancelChildren()
+ withContext(evaluationContext) {
+ Log.d("PUPILD", "UPDATE!")
+ runtime.evaluate(URL("https://tom5079.github.io/PupilSources/assets/js/gg.js").readText())
+ runtimeReady = true
+ }
+ }
+ }
+
+ delay(10000)
+ }
+ }
+ }
+
override fun onCreate() {
instance = this
- initWebView(this)
-
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
preferences = PreferenceManager.getDefaultSharedPreferences(this)
@@ -234,6 +128,7 @@ class Pupil : Application() {
else userID
}
+ FirebaseApp.initializeApp(this)
FirebaseCrashlytics.getInstance().setUserId(userID)
val proxyInfo = getProxyInfo()
@@ -244,7 +139,7 @@ class Pupil : Application() {
.proxyInfo(proxyInfo)
.addInterceptor { chain ->
val request = chain.request().newBuilder()
- .header("User-Agent", userAgent)
+ .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36")
.header("Referer", "https://hitomi.la/")
.build()
diff --git a/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt b/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt
index 0c1e79f9..a36e6328 100644
--- a/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt
+++ b/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt
@@ -16,31 +16,81 @@
package xyz.quaver.pupil.hitomi
-import android.util.Log
-import android.webkit.WebView
-import kotlinx.coroutines.*
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.first
-import kotlinx.coroutines.flow.transformWhile
-import kotlinx.serialization.ExperimentalSerializationApi
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.asCoroutineDispatcher
+import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.withContext
+import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
-import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
-import xyz.quaver.pupil.*
-import java.util.*
-import kotlin.coroutines.resume
-import kotlin.coroutines.suspendCoroutine
+import okhttp3.Request
+import xyz.quaver.pupil.client
+import xyz.quaver.pupil.runtime
+import java.io.IOException
+import java.net.URL
+import java.util.concurrent.Executors
const val protocol = "https:"
-val evaluationContext = Dispatchers.Main + Job()
+@Serializable
+data class Artist(
+ val artist: String,
+ val url: String
+)
+
+@Serializable
+data class Group(
+ val group: String,
+ val url: String
+)
+
+@Serializable
+data class Parody(
+ val parody: String,
+ val url: String
+)
+
+@Serializable
+data class Character(
+ val character: String,
+ val url: String
+)
+
+@Serializable
+data class Tag(
+ val tag: String,
+ val url: String,
+ val female: String? = null,
+ val male: String? = null
+)
+
+@Serializable
+data class Language(
+ val galleryid: String,
+ val url: String,
+ val language_localname: String,
+ val name: String
+)
+
+@Serializable
+data class GalleryInfo(
+ val id: String,
+ val title: String,
+ val japanese_title: String? = null,
+ val language: String? = null,
+ val type: String,
+ val date: String,
+ val artists: List? = null,
+ val groups: List? = null,
+ val parodys: List? = null,
+ val tags: List? = null,
+ val related: List,
+ val languages: List,
+ val characters: List? = null,
+ val scene_indexes: List,
+ val files: List
+)
-/**
- * kotlinx.serialization.json.Json object for global use
- * properties should not be changed
- *
- * @see [https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx-serialization-core/kotlinx.serialization.json/-json/index.html]
- */
val json = Json {
isLenient = true
ignoreUnknownKeys = true
@@ -48,89 +98,103 @@ val json = Json {
useArrayPolymorphism = true
}
-suspend inline fun WebView.evaluate(script: String): T = coroutineScope { withTimeout(60000) {
- var result: String? = null
+typealias HeaderSetter = (Request.Builder) -> Request.Builder
+fun URL.readText(settings: HeaderSetter? = null): String {
+ val request = Request.Builder()
+ .url(this).let {
+ settings?.invoke(it) ?: it
+ }.build()
- while (result == null) {
- try {
- while (!oldWebView && !webViewReady) delay(1000)
+ return client.newCall(request).execute().also{ if (it.code() != 200) throw IOException("CODE ${it.code()}") }.body()?.use { it.string() } ?: throw IOException()
+}
- result = if (oldWebView)
- "null"
- else withContext(evaluationContext) {
- suspendCoroutine { continuation ->
- evaluateJavascript(script) {
- continuation.resume(it)
- }
- }
+fun URL.readBytes(settings: HeaderSetter? = null): ByteArray {
+ val request = Request.Builder()
+ .url(this).let {
+ settings?.invoke(it) ?: it
+ }.build()
- }
- } catch (e: CancellationException) {
- if (e.message != "reload") result = "null"
- }
- }
-
- json.decodeFromString(result)
-} }
-
-@OptIn(ExperimentalCoroutinesApi::class)
-suspend inline fun WebView.evaluatePromise(
- script: String,
- then: String = ".then(result => Callback.onResult(%uid, JSON.stringify(result))).catch(err => Callback.onError(%uid, String.raw`$script`, err.message, err.stack))"
-): T = coroutineScope { withTimeout(60000) {
- var result: String? = null
-
- while (result == null) {
- try {
- while (!oldWebView && !webViewReady) delay(1000)
-
- result = if (oldWebView)
- "null"
- else withContext(evaluationContext) {
- val uid = UUID.randomUUID().toString()
-
- val flow: Flow> = webViewFlow.transformWhile { (currentUid, result) ->
- if (currentUid == uid) {
- emit(currentUid to result)
- }
- currentUid != uid
- }
-
- launch {
- evaluateJavascript((script + then).replace("%uid", "'$uid'"), null)
- }
-
- flow.first().second
- }
- } catch (e: CancellationException) {
- if (e.message != "reload") result = "null"
- }
- }
-
- json.decodeFromString(result)
-} }
+ return client.newCall(request).execute().also { if (it.code() != 200) throw IOException("CODE ${it.code()}") }.body()?.use { it.bytes() } ?: throw IOException()
+}
@Suppress("EXPERIMENTAL_API_USAGE")
-suspend fun getGalleryInfo(galleryID: Int): GalleryInfo =
- webView.evaluatePromise("get_gallery_info($galleryID)")
+fun getGalleryInfo(galleryID: Int) =
+ json.decodeFromString(
+ URL("$protocol//$domain/galleries/$galleryID.js").readText()
+ .replace("var galleryinfo = ", "")
+ )
//common.js
const val domain = "ltn.hitomi.la"
+const val galleryblockextension = ".html"
+const val galleryblockdir = "galleryblock"
+const val nozomiextension = ".nozomi"
-val String?.js: String
- get() = if (this == null) "null" else "'$this'"
+val evaluationContext = Executors.newSingleThreadExecutor().asCoroutineDispatcher() + Job()
-@OptIn(ExperimentalSerializationApi::class)
-suspend fun urlFromUrlFromHash(galleryID: Int, image: GalleryFiles, dir: String? = null, ext: String? = null, base: String? = null): String =
- webView.evaluate(
- """
- url_from_url_from_hash(
- ${galleryID.toString().js},
- ${Json.encodeToString(image)},
- ${dir.js}, ${ext.js}, ${base.js}
- )
- """.trimIndent()
- )
+object gg {
+
+ suspend fun m(g: Int): Int = withContext(evaluationContext) {
+ runtime.evaluate("gg.m($g)").toString().toInt()
+ }
+ suspend fun b(): String = withContext(evaluationContext) {
+ runtime.evaluate("gg.b").toString()
+ }
+
+ suspend fun s(h: String): String = withContext(evaluationContext) {
+ runtime.evaluate("gg.s('$h')").toString()
+ }
+}
+
+suspend fun subdomainFromURL(url: String, base: String? = null) : String {
+ var retval = "b"
+
+ if (!base.isNullOrBlank())
+ retval = base
+
+ val b = 16
+
+ val r = Regex("""/[0-9a-f]{61}([0-9a-f]{2})([0-9a-f])""")
+ val m = r.find(url) ?: return "a"
+
+ val g = m.groupValues.let { it[2]+it[1] }.toIntOrNull(b)
+
+ if (g != null) {
+ retval = (97+ gg.m(g)).toChar().toString() + retval
+ }
+
+ return retval
+}
+
+suspend fun urlFromUrl(url: String, base: String? = null) : String {
+ return url.replace(Regex("""//..?\.hitomi\.la/"""), "//${subdomainFromURL(url, base)}.hitomi.la/")
+}
+
+suspend fun fullPathFromHash(hash: String) : String =
+ "${gg.b()}${gg.s(hash)}/$hash"
+
+fun realFullPathFromHash(hash: String): String =
+ hash.replace(Regex("""^.*(..)(.)$"""), "$2/$1/$hash")
+
+suspend fun urlFromHash(galleryID: Int, image: GalleryFiles, dir: String? = null, ext: String? = null) : String {
+ val ext = ext ?: dir ?: image.name.takeLastWhile { it != '.' }
+ val dir = dir ?: "images"
+ return "https://a.hitomi.la/$dir/${fullPathFromHash(image.hash)}.$ext"
+}
+
+suspend fun urlFromUrlFromHash(galleryID: Int, image: GalleryFiles, dir: String? = null, ext: String? = null, base: String? = null) =
+ if (base == "tn")
+ urlFromUrl("https://a.hitomi.la/$dir/${realFullPathFromHash(image.hash)}.$ext", base)
+ else
+ urlFromUrl(urlFromHash(galleryID, image, dir, ext), base)
+
+suspend fun rewriteTnPaths(html: String) {
+ html.replace(Regex("""//tn\.hitomi\.la/[^/]+/[0-9a-f]/[0-9a-f]{2}/[0-9a-f]{64}""")) { url ->
+ runBlocking {
+ urlFromUrl(url.value, "tn")
+ }
+ }
+}
suspend fun imageUrlFromImage(galleryID: Int, image: GalleryFiles, noWebp: Boolean) : String {
return when {
diff --git a/app/src/main/java/xyz/quaver/pupil/hitomi/galleries.kt b/app/src/main/java/xyz/quaver/pupil/hitomi/galleries.kt
index 4b60931f..6920c666 100644
--- a/app/src/main/java/xyz/quaver/pupil/hitomi/galleries.kt
+++ b/app/src/main/java/xyz/quaver/pupil/hitomi/galleries.kt
@@ -17,14 +17,11 @@
package xyz.quaver.pupil.hitomi
import kotlinx.serialization.Serializable
-import kotlinx.serialization.decodeFromString
-import kotlinx.serialization.json.Json
-import xyz.quaver.pupil.webView
@Serializable
data class Gallery(
val related: List,
- val langList: Map,
+ val langList: List>,
val cover: String,
val title: String,
val artists: List,
@@ -36,5 +33,22 @@ data class Gallery(
val tags: List,
val thumbnails: List
)
-suspend fun getGallery(galleryID: Int) : Gallery =
- webView.evaluatePromise("get_gallery($galleryID)")
\ No newline at end of file
+
+suspend fun getGallery(galleryID: Int) : Gallery {
+ val info = getGalleryInfo(galleryID)
+
+ return Gallery(
+ info.related,
+ info.languages.map { it.name to it.galleryid },
+ urlFromUrlFromHash(galleryID, info.files.first(), "webpbigtn", "webp", "tn"),
+ info.title,
+ info.artists?.map { it.artist }.orEmpty(),
+ info.groups?.map { it.group }.orEmpty(),
+ info.type,
+ info.language.orEmpty(),
+ info.parodys?.map { it.parody }.orEmpty(),
+ info.characters?.map { it.character }.orEmpty(),
+ info.tags?.map { "${if (it.female.isNullOrEmpty()) "" else "female:"}${if (it.male.isNullOrEmpty()) "" else "male:"}${it.tag}" }.orEmpty(),
+ info.files.map { urlFromUrlFromHash(galleryID, it, "webpsmalltn", "webp", "tn") }
+ )
+}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/quaver/pupil/hitomi/galleryblock.kt b/app/src/main/java/xyz/quaver/pupil/hitomi/galleryblock.kt
index e49d6975..4868d6aa 100644
--- a/app/src/main/java/xyz/quaver/pupil/hitomi/galleryblock.kt
+++ b/app/src/main/java/xyz/quaver/pupil/hitomi/galleryblock.kt
@@ -17,7 +17,48 @@
package xyz.quaver.pupil.hitomi
import kotlinx.serialization.Serializable
-import xyz.quaver.pupil.webView
+import org.jsoup.Jsoup
+import java.net.URL
+import java.net.URLDecoder
+import java.nio.ByteBuffer
+import java.nio.ByteOrder
+import javax.net.ssl.HttpsURLConnection
+import kotlin.io.readText
+
+//galleryblock.js
+fun fetchNozomi(area: String? = null, tag: String = "index", language: String = "all", start: Int = -1, count: Int = -1) : Pair, Int> {
+ val url = when(area) {
+ null -> "$protocol//$domain/$tag-$language$nozomiextension"
+ else -> "$protocol//$domain/$area/$tag-$language$nozomiextension"
+ }
+
+ with(URL(url).openConnection() as HttpsURLConnection) {
+ requestMethod = "GET"
+
+ if (start != -1 && count != -1) {
+ val startByte = start*4
+ val endByte = (start+count)*4-1
+
+ setRequestProperty("Range", "bytes=$startByte-$endByte")
+ }
+
+ connect()
+
+ val totalItems = getHeaderField("Content-Range")
+ .replace(Regex("^[Bb]ytes \\d+-\\d+/"), "").toInt() / 4
+
+ val nozomi = ArrayList()
+
+ val arrayBuffer = ByteBuffer
+ .wrap(inputStream.readBytes())
+ .order(ByteOrder.BIG_ENDIAN)
+
+ while (arrayBuffer.hasRemaining())
+ nozomi.add(arrayBuffer.int)
+
+ return Pair(nozomi, totalItems)
+ }
+}
@Serializable
data class GalleryBlock(
@@ -28,9 +69,24 @@ data class GalleryBlock(
val artists: List,
val series: List,
val type: String,
- val language: String?,
- val relatedTags: List
+ val language: String,
+ val relatedTags: List,
+ val groups: List
)
-suspend fun getGalleryBlock(galleryID: Int) : GalleryBlock =
- webView.evaluatePromise("get_gallery_block($galleryID)")
\ No newline at end of file
+suspend fun getGalleryBlock(galleryID: Int) : GalleryBlock {
+ val info = getGalleryInfo(galleryID)
+
+ return GalleryBlock(
+ galleryID,
+ "",
+ listOf(urlFromUrlFromHash(galleryID, info.files.first(), "webpbigtn", "webp", "tn")),
+ info.title,
+ info.artists?.map { it.artist }.orEmpty(),
+ info.parodys?.map { it.parody }.orEmpty(),
+ info.type,
+ info.language.orEmpty(),
+ info.tags?.map { "${if (it.female.isNullOrEmpty()) "" else "female:"}${if (it.male.isNullOrEmpty()) "" else "male:"}${it.tag}" }.orEmpty(),
+ info.groups?.map { it.group }.orEmpty()
+ )
+}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/quaver/pupil/hitomi/reader.kt b/app/src/main/java/xyz/quaver/pupil/hitomi/reader.kt
index be7a86eb..af8db372 100644
--- a/app/src/main/java/xyz/quaver/pupil/hitomi/reader.kt
+++ b/app/src/main/java/xyz/quaver/pupil/hitomi/reader.kt
@@ -17,19 +17,8 @@
package xyz.quaver.pupil.hitomi
import kotlinx.serialization.Serializable
-
-fun getReferer(galleryID: Int) = "https://hitomi.la/reader/$galleryID.html"
-
-@Serializable
-data class GalleryInfo(
- val language_localname: String? = null,
- val language: String? = null,
- val date: String? = null,
- val files: List,
- val id: Int? = null,
- val type: String? = null,
- val title: String? = null
-)
+import xyz.quaver.pupil.hitomi.GalleryInfo
+import xyz.quaver.pupil.hitomi.getGalleryInfo
@Serializable
data class GalleryFiles(
@@ -44,6 +33,6 @@ data class GalleryFiles(
//Set header `Referer` to reader url to avoid 403 error
@Deprecated("", replaceWith = ReplaceWith("getGalleryInfo"))
-suspend fun getReader(galleryID: Int) : GalleryInfo {
+fun getReader(galleryID: Int) : GalleryInfo {
return getGalleryInfo(galleryID)
}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/quaver/pupil/hitomi/search.kt b/app/src/main/java/xyz/quaver/pupil/hitomi/search.kt
index 649db5da..b4eaecf6 100644
--- a/app/src/main/java/xyz/quaver/pupil/hitomi/search.kt
+++ b/app/src/main/java/xyz/quaver/pupil/hitomi/search.kt
@@ -16,42 +16,313 @@
package xyz.quaver.pupil.hitomi
-import android.util.Log
-import kotlinx.serialization.ExperimentalSerializationApi
-import kotlinx.serialization.Serializable
-import kotlinx.serialization.decodeFromString
-import kotlinx.serialization.json.Json
-import xyz.quaver.pupil.webView
+import okhttp3.Request
+import xyz.quaver.pupil.client
+import java.net.URL
+import java.nio.ByteBuffer
+import java.nio.ByteOrder
+import java.security.MessageDigest
+import kotlin.math.min
//searchlib.js
+const val separator = "-"
const val extension = ".html"
+const val index_dir = "tagindex"
+const val galleries_index_dir = "galleriesindex"
+const val max_node_size = 464
+const val B = 16
+const val compressed_nozomi_prefix = "n"
-@OptIn(ExperimentalSerializationApi::class)
-suspend fun getGalleryIDsForQuery(query: String) : Set =
- webView.evaluatePromise("get_galleryids_for_query('$query')")
+val tag_index_version: String by lazy { getIndexVersion("tagindex") }
+val galleries_index_version: String by lazy { getIndexVersion("galleriesindex") }
-@Serializable
-data class Suggestion(val s: String, val t: Int, val u: String, val n: String)
+fun sha256(data: ByteArray) : ByteArray {
+ return MessageDigest.getInstance("SHA-256").digest(data)
+}
-@OptIn(ExperimentalSerializationApi::class)
-suspend fun getSuggestionsForQuery(query: String) : List =
- webView.evaluatePromise(
- "get_suggestions_for_query('$query', ++search_serial)",
- then = """
- .then(r => {
- let [results, results_serial] = r;
- if (search_serial !== results_serial) {
- Callback.onResult(%uid, '[]');
- } else {
- Callback.onResult(%uid, JSON.stringify(results));
+@OptIn(ExperimentalUnsignedTypes::class)
+fun hashTerm(term: String) : UByteArray {
+ return sha256(term.toByteArray()).toUByteArray().sliceArray(0 until 4)
+}
+
+fun sanitize(input: String) : String {
+ return input.replace(Regex("[/#]"), "")
+}
+
+fun getIndexVersion(name: String) =
+ URL("$protocol//$domain/$name/version?_=${System.currentTimeMillis()}").readText()
+
+//search.js
+fun getGalleryIDsForQuery(query: String) : Set {
+ query.replace("_", " ").let {
+ if (it.indexOf(':') > -1) {
+ val sides = it.split(":")
+ val ns = sides[0]
+ var tag = sides[1]
+
+ var area : String? = ns
+ var language = "all"
+ when (ns) {
+ "female", "male" -> {
+ area = "tag"
+ tag = it
}
- });
- """.trimIndent()
- )
+ "language" -> {
+ area = null
+ language = tag
+ tag = "index"
+ }
+ }
-@OptIn(ExperimentalSerializationApi::class)
-suspend fun getGalleryIDsFromNozomi(area: String?, tag: String, language: String) : Set {
- val jsArea = if (area == null) "null" else "'$area'"
+ return getGalleryIDsFromNozomi(area, tag, language)
+ }
- return webView.evaluatePromise("""get_galleryids_from_nozomi($jsArea, '$tag', '$language')""")
+ val key = hashTerm(it)
+ val field = "galleries"
+
+ val node = getNodeAtAddress(field, 0) ?: return emptySet()
+
+ val data = bSearch(field, key, node)
+
+ if (data != null)
+ return getGalleryIDsFromData(data)
+
+ return emptySet()
+ }
+}
+
+fun getSuggestionsForQuery(query: String) : List {
+ query.replace('_', ' ').let {
+ var field = "global"
+ var term = it
+
+ if (term.indexOf(':') > -1) {
+ val sides = it.split(':')
+ field = sides[0]
+ term = sides[1]
+ }
+
+ val key = hashTerm(term)
+ val node = getNodeAtAddress(field, 0) ?: return emptyList()
+ val data = bSearch(field, key, node)
+
+ if (data != null)
+ return getSuggestionsFromData(field, data)
+
+ return emptyList()
+ }
+}
+
+data class Suggestion(val s: String, val t: Int, val u: String, val n: String)
+fun getSuggestionsFromData(field: String, data: Pair) : List {
+ val url = "$protocol//$domain/$index_dir/$field.$tag_index_version.data"
+ val (offset, length) = data
+ if (length > 10000 || length <= 0)
+ throw Exception("length $length is too long")
+
+ val inbuf = getURLAtRange(url, offset.until(offset+length))
+
+ val suggestions = ArrayList()
+
+ val buffer = ByteBuffer
+ .wrap(inbuf)
+ .order(ByteOrder.BIG_ENDIAN)
+ val numberOfSuggestions = buffer.int
+
+ if (numberOfSuggestions > 100 || numberOfSuggestions <= 0)
+ throw Exception("number of suggestions $numberOfSuggestions is too long")
+
+ for (i in 0.until(numberOfSuggestions)) {
+ var top = buffer.int
+
+ val ns = inbuf.sliceArray(buffer.position().until(buffer.position()+top)).toString(charset("UTF-8"))
+ buffer.position(buffer.position()+top)
+
+ top = buffer.int
+
+ val tag = inbuf.sliceArray(buffer.position().until(buffer.position()+top)).toString(charset("UTF-8"))
+ buffer.position(buffer.position()+top)
+
+ val count = buffer.int
+
+ val tagname = sanitize(tag)
+ val u =
+ when(ns) {
+ "female", "male" -> "/tag/$ns:$tagname${separator}1$extension"
+ "language" -> "/index-$tagname${separator}1$extension"
+ else -> "/$ns/$tagname${separator}all${separator}1$extension"
+ }
+
+ suggestions.add(Suggestion(tag, count, u, ns))
+ }
+
+ return suggestions
+}
+
+fun getGalleryIDsFromNozomi(area: String?, tag: String, language: String) : Set {
+ val nozomiAddress =
+ when(area) {
+ null -> "$protocol//$domain/$compressed_nozomi_prefix/$tag-$language$nozomiextension"
+ else -> "$protocol//$domain/$compressed_nozomi_prefix/$area/$tag-$language$nozomiextension"
+ }
+
+ val bytes = try {
+ URL(nozomiAddress).readBytes()
+ } catch (e: Exception) {
+ return emptySet()
+ }
+
+ val nozomi = mutableSetOf()
+
+ val arrayBuffer = ByteBuffer
+ .wrap(bytes)
+ .order(ByteOrder.BIG_ENDIAN)
+
+ while (arrayBuffer.hasRemaining())
+ nozomi.add(arrayBuffer.int)
+
+ return nozomi
+}
+
+fun getGalleryIDsFromData(data: Pair) : Set {
+ val url = "$protocol//$domain/$galleries_index_dir/galleries.$galleries_index_version.data"
+ val (offset, length) = data
+ if (length > 100000000 || length <= 0)
+ throw Exception("length $length is too long")
+
+ val inbuf = getURLAtRange(url, offset.until(offset+length))
+
+ val galleryIDs = mutableSetOf()
+
+ val buffer = ByteBuffer
+ .wrap(inbuf)
+ .order(ByteOrder.BIG_ENDIAN)
+
+ val numberOfGalleryIDs = buffer.int
+
+ val expectedLength = numberOfGalleryIDs*4+4
+
+ if (numberOfGalleryIDs > 10000000 || numberOfGalleryIDs <= 0)
+ throw Exception("number_of_galleryids $numberOfGalleryIDs is too long")
+ else if (inbuf.size != expectedLength)
+ throw Exception("inbuf.byteLength ${inbuf.size} != expected_length $expectedLength")
+
+ for (i in 0.until(numberOfGalleryIDs))
+ galleryIDs.add(buffer.int)
+
+ return galleryIDs
+}
+
+fun getNodeAtAddress(field: String, address: Long) : Node? {
+ val url =
+ when(field) {
+ "galleries" -> "$protocol//$domain/$galleries_index_dir/galleries.$galleries_index_version.index"
+ "languages" -> "$protocol//$domain/$galleries_index_dir/languages.$galleries_index_version.index"
+ "nozomiurl" -> "$protocol//$domain/$galleries_index_dir/nozomiurl.$galleries_index_version.index"
+ else -> "$protocol//$domain/$index_dir/$field.$tag_index_version.index"
+ }
+
+ val nodedata = getURLAtRange(url, address.until(address+ max_node_size))
+
+ return decodeNode(nodedata)
+}
+
+fun getURLAtRange(url: String, range: LongRange) : ByteArray {
+ val request = Request.Builder()
+ .url(url)
+ .header("Range", "bytes=${range.first}-${range.last}")
+ .build()
+
+ return client.newCall(request).execute().body()?.use { it.bytes() } ?: byteArrayOf()
+}
+
+@OptIn(ExperimentalUnsignedTypes::class)
+data class Node(val keys: List, val datas: List>, val subNodeAddresses: List)
+@OptIn(ExperimentalUnsignedTypes::class)
+fun decodeNode(data: ByteArray) : Node {
+ val buffer = ByteBuffer
+ .wrap(data)
+ .order(ByteOrder.BIG_ENDIAN)
+
+ val uData = data.toUByteArray()
+
+ val numberOfKeys = buffer.int
+ val keys = ArrayList()
+
+ for (i in 0.until(numberOfKeys)) {
+ val keySize = buffer.int
+
+ if (keySize == 0 || keySize > 32)
+ throw Exception("fatal: !keySize || keySize > 32")
+
+ keys.add(uData.sliceArray(buffer.position().until(buffer.position()+keySize)))
+ buffer.position(buffer.position()+keySize)
+ }
+
+ val numberOfDatas = buffer.int
+ val datas = ArrayList>()
+
+ for (i in 0.until(numberOfDatas)) {
+ val offset = buffer.long
+ val length = buffer.int
+
+ datas.add(Pair(offset, length))
+ }
+
+ val numberOfSubNodeAddresses = B +1
+ val subNodeAddresses = ArrayList()
+
+ for (i in 0.until(numberOfSubNodeAddresses)) {
+ val subNodeAddress = buffer.long
+ subNodeAddresses.add(subNodeAddress)
+ }
+
+ return Node(keys, datas, subNodeAddresses)
+}
+
+@OptIn(ExperimentalUnsignedTypes::class)
+fun bSearch(field: String, key: UByteArray, node: Node) : Pair? {
+ fun compareArrayBuffers(dv1: UByteArray, dv2: UByteArray) : Int {
+ val top = min(dv1.size, dv2.size)
+
+ for (i in 0.until(top)) {
+ if (dv1[i] < dv2[i])
+ return -1
+ else if (dv1[i] > dv2[i])
+ return 1
+ }
+
+ return 0
+ }
+
+ fun locateKey(key: UByteArray, node: Node) : Pair {
+ for (i in node.keys.indices) {
+ val cmpResult = compareArrayBuffers(key, node.keys[i])
+
+ if (cmpResult <= 0)
+ return Pair(cmpResult==0, i)
+ }
+
+ return Pair(false, node.keys.size)
+ }
+
+ fun isLeaf(node: Node) : Boolean {
+ for (subnode in node.subNodeAddresses)
+ if (subnode != 0L)
+ return false
+
+ return true
+ }
+
+ if (node.keys.isEmpty())
+ return null
+
+ val (there, where) = locateKey(key, node)
+ if (there)
+ return node.datas[where]
+ else if (isLeaf(node))
+ return null
+
+ val nextNode = getNodeAtAddress(field, node.subNodeAddresses[where]) ?: return null
+ return bSearch(field, key, nextNode)
}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
index 1d322359..08b281b1 100644
--- a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
+++ b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
@@ -19,14 +19,12 @@
package xyz.quaver.pupil.ui
import android.annotation.SuppressLint
-import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.text.util.Linkify
-import android.util.Log
import android.view.KeyEvent
import android.view.MenuItem
import android.view.View
@@ -38,7 +36,6 @@ import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.RecyclerView
-import androidx.webkit.WebViewCompat
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.crashlytics.FirebaseCrashlytics
@@ -47,12 +44,12 @@ import xyz.quaver.floatingsearchview.FloatingSearchView
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
import xyz.quaver.floatingsearchview.util.view.MenuView
import xyz.quaver.floatingsearchview.util.view.SearchInputView
-import xyz.quaver.pupil.hitomi.doSearch
-import xyz.quaver.pupil.hitomi.getGalleryIDsFromNozomi
-import xyz.quaver.pupil.hitomi.getSuggestionsForQuery
import xyz.quaver.pupil.*
import xyz.quaver.pupil.adapters.GalleryBlockAdapter
import xyz.quaver.pupil.databinding.MainActivityBinding
+import xyz.quaver.pupil.hitomi.doSearch
+import xyz.quaver.pupil.hitomi.getGalleryIDsFromNozomi
+import xyz.quaver.pupil.hitomi.getSuggestionsForQuery
import xyz.quaver.pupil.services.DownloadService
import xyz.quaver.pupil.types.*
import xyz.quaver.pupil.ui.dialog.DownloadLocationDialogFragment
@@ -66,7 +63,10 @@ import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.downloader.DownloadManager
import xyz.quaver.pupil.util.restore
import java.util.regex.Pattern
-import kotlin.math.*
+import kotlin.math.ceil
+import kotlin.math.max
+import kotlin.math.min
+import kotlin.math.roundToInt
class MainActivity :
BaseActivity(),
@@ -107,8 +107,6 @@ class MainActivity :
private lateinit var binding: MainActivityBinding
- private var oldWebViewJob: Job? = null
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = MainActivityBinding.inflate(layoutInflater)
@@ -129,39 +127,6 @@ class MainActivity :
if (Preferences["download_folder", ""].isEmpty())
DownloadLocationDialogFragment().show(supportFragmentManager, "Download Location Dialog")
- oldWebViewJob = CoroutineScope(Dispatchers.Unconfined).launch {
- do {
- delay(1000)
- if (oldWebView) {
- AlertDialog.Builder(this@MainActivity)
- .setTitle(android.R.string.dialog_alert_title)
- .setMessage(R.string.old_webview)
- .setCancelable(false)
- .setPositiveButton(android.R.string.ok) { _, _ ->
- WebViewCompat.getCurrentWebViewPackage(this@MainActivity)?.packageName?.let { packageName ->
- try {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("market://details?id=$packageName")
- )
- )
- } catch (e: ActivityNotFoundException) {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("https://play.google.com/store/apps/details?id=$packageName")
- )
- )
- }
- }
- }
- .show()
- break
- }
- } while (isActive)
- }
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Preferences["download_folder_ignore_warning", false] &&
ContextCompat.getExternalFilesDirs(this, null).filterNotNull().map { Uri.fromFile(it).toString() }
.contains(Preferences["download_folder", ""])
@@ -204,8 +169,6 @@ class MainActivity :
override fun onDestroy() {
super.onDestroy()
- oldWebViewJob?.cancel()
-
(binding.contents.recyclerview.adapter as? GalleryBlockAdapter)?.updateAll = false
}
diff --git a/app/src/main/java/xyz/quaver/pupil/ui/fragment/ManageStorageFragment.kt b/app/src/main/java/xyz/quaver/pupil/ui/fragment/ManageStorageFragment.kt
index d1a69da9..0999f08d 100644
--- a/app/src/main/java/xyz/quaver/pupil/ui/fragment/ManageStorageFragment.kt
+++ b/app/src/main/java/xyz/quaver/pupil/ui/fragment/ManageStorageFragment.kt
@@ -121,7 +121,7 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
Json.decodeFromString(it)
} ?: return@forEach
- val galleryID = metadata.galleryBlock?.id ?: metadata.galleryInfo?.id ?: return@forEach
+ val galleryID = metadata.galleryBlock?.id ?: metadata.galleryInfo?.id?.toIntOrNull() ?: return@forEach
downloadFolderMap[galleryID] = folder.name
}
diff --git a/app/src/main/java/xyz/quaver/pupil/util/downloader/Cache.kt b/app/src/main/java/xyz/quaver/pupil/util/downloader/Cache.kt
index b1af608e..65a8e83e 100644
--- a/app/src/main/java/xyz/quaver/pupil/util/downloader/Cache.kt
+++ b/app/src/main/java/xyz/quaver/pupil/util/downloader/Cache.kt
@@ -58,38 +58,12 @@ data class OldGalleryBlock(
val relatedTags: List
)
-@Serializable
-data class OldReader(val code: String, val galleryInfo: GalleryInfo)
-
-@Serializable
-data class OldMetadata(
- var galleryBlock: OldGalleryBlock? = null,
- var reader: OldReader? = null,
- var imageList: MutableList? = null
-) {
- fun copy(): OldMetadata = OldMetadata(galleryBlock, reader, imageList?.let { MutableList(it.size) { i -> it[i] } })
-}
-
@Serializable
data class Metadata(
var galleryBlock: GalleryBlock? = null,
var galleryInfo: GalleryInfo? = null,
var imageList: MutableList? = null
) {
- constructor(old: OldMetadata) : this(old.galleryBlock?.let { galleryBlock -> GalleryBlock(
- galleryBlock.id,
- galleryBlock.galleryUrl,
- galleryBlock.thumbnails,
- galleryBlock.title,
- galleryBlock.artists,
- galleryBlock.series,
- galleryBlock.type,
- galleryBlock.language,
- galleryBlock.relatedTags) },
- old.reader?.galleryInfo,
- old.imageList
- )
-
fun copy(): Metadata = Metadata(galleryBlock, galleryInfo, imageList?.let { MutableList(it.size) { i -> it[i] } })
}
@@ -116,11 +90,7 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
var metadata = kotlin.runCatching {
findFile(".metadata")?.readText()?.let { metadata ->
- kotlin.runCatching {
- Json.decodeFromString(metadata)
- }.getOrElse {
- Metadata(Json.decodeFromString(metadata))
- }
+ Json.decodeFromString(metadata)
}
}.getOrNull() ?: Metadata()
diff --git a/app/src/main/java/xyz/quaver/pupil/util/misc.kt b/app/src/main/java/xyz/quaver/pupil/util/misc.kt
index 885482c2..44884445 100644
--- a/app/src/main/java/xyz/quaver/pupil/util/misc.kt
+++ b/app/src/main/java/xyz/quaver/pupil/util/misc.kt
@@ -25,9 +25,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import xyz.quaver.pupil.hitomi.GalleryBlock
import xyz.quaver.pupil.hitomi.GalleryInfo
-import xyz.quaver.pupil.hitomi.getReferer
import xyz.quaver.pupil.hitomi.imageUrlFromImage
-import xyz.quaver.pupil.userAgent
import java.util.*
import kotlin.collections.ArrayList
@@ -79,7 +77,8 @@ fun OkHttpClient.Builder.proxyInfo(proxyInfo: ProxyInfo) = this.apply {
val formatMap = mapOf (String)>(
"-id-" to { id.toString() },
"-title-" to { title },
- "-artist-" to { artists.joinToString() }
+ "-artist-" to { artists.joinToString() },
+ "-group-" to { groups.joinToString() }
// TODO
)
/**
@@ -100,7 +99,7 @@ fun GalleryBlock.formatDownloadFolderTest(format: String): String =
}.replace(Regex("""[*\\|"?><:/]"""), "").ellipsize(127)
suspend fun GalleryInfo.getRequestBuilders(): List {
- val galleryID = this.id ?: 0
+ val galleryID = this.id.toIntOrNull() ?: 0
val lowQuality = Preferences["low_quality", true]
return this.files.map {
@@ -115,7 +114,6 @@ suspend fun GalleryInfo.getRequestBuilders(): List {
.getOrDefault("https://a/")
)
.header("Referer", "https://hitomi.la/")
- .header("User-Agent", userAgent)
}
}
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 8008573f..de1fcf06 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -157,6 +157,5 @@
並列ダウンロード
アンドロイド11以上では外部からのアプリ内部空間接近が不可能です。ダウンロードフォルダを変更しますか?
ネットワーク
- WebViewのアップデートが必要です
ダウンロードデータベースを再構築
\ No newline at end of file
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 9d4ebb0c..0e4f93fe 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -157,6 +157,5 @@
병렬 다운로드
안드로이드 11 이상에서는 외부에서 현재 다운로드 폴더에 접근할 수 없습니다. 변경하시겠습니까?
네트워크
- WebView 업데이트가 필요합니다
다운로드 데이터베이스 복구
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8fa0a73d..c813e482 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -51,8 +51,6 @@
From Android 11 and above, current Download folder cannot be accessed by outside apps. Would you like to change the download folder?
- You are using an old version of WebView. Please update it on PlayStore
-
Home
History
Downloads
diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml
index d1f163b0..5594b3e0 100644
--- a/app/src/main/res/xml/network_security_config.xml
+++ b/app/src/main/res/xml/network_security_config.xml
@@ -18,6 +18,9 @@
-->
+
+ 10.0.2.2
+
ix.io
diff --git a/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt b/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt
index 54369f9a..27402b96 100644
--- a/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt
+++ b/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt
@@ -26,15 +26,8 @@ package xyz.quaver.pupil
* See [testing documentation](http://d.android.com/tools/testing).
*/
-import okhttp3.OkHttpClient
-import okhttp3.Request
-import org.junit.Assert.assertEquals
-import org.junit.Before
import org.junit.Test
-import xyz.quaver.pupil.hitomi.getGalleryInfo
-import xyz.quaver.pupil.hitomi.imageUrlFromImage
import java.lang.reflect.ParameterizedType
-import java.util.concurrent.TimeUnit
class ExampleUnitTest {
@Test
diff --git a/build.gradle b/build.gradle
index 5b8cfb15..3573c05c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,6 +26,7 @@ allprojects {
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://guardian.github.io/maven/repo-releases/" }
+ maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}