From 0d4a8c9cd5dbb4c861aaaebb3e19bdb1f848c903 Mon Sep 17 00:00:00 2001 From: Yenaly <2021214976@stu.cqupt.edu.cn> Date: Thu, 14 Mar 2024 18:15:07 +0800 Subject: [PATCH] =?UTF-8?q?v0.13.0=20update.=20[=E6=96=B0=E5=A2=9E]?= =?UTF-8?q?=E9=95=BF=E6=8C=89=E5=BF=AB=E8=BF=9B=E8=A7=A6=E5=8A=A8=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E3=80=82=20[=E6=96=B0=E5=A2=9E]=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E7=99=BB=E5=85=A5=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0=E6=8F=90?= =?UTF-8?q?=E9=86=92=EF=BC=8C=E5=8F=AA=E8=83=BD=E4=BF=9D=E6=8C=812?= =?UTF-8?q?=E5=B0=8F=E6=97=B6=E3=80=82=20[=E6=96=B0=E5=A2=9E]OkHttp?= =?UTF-8?q?=E6=B7=BB=E5=8A=A010MB=E7=BC=93=E5=AD=98=E3=80=82=E6=88=91?= =?UTF-8?q?=E4=B9=9F=E4=B8=8D=E7=9F=A5=E9=81=93=E6=9C=89=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E7=94=A8=E3=80=82=20[=E6=96=B0=E5=A2=9E]readme=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BC=80=E5=8F=91=E8=80=85=E7=A2=8E=E7=A2=8E=E5=BF=B5?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 30 +++++++++++++++++-- .../com/yenaly/han1meviewer/HanimeManager.kt | 10 +++++-- .../yenaly/han1meviewer/logic/NetworkRepo.kt | 10 +++---- .../logic/network/ServiceCreator.kt | 9 ++++++ .../network/service/HanimeBaseService.kt | 2 +- .../han1meviewer/ui/activity/LoginActivity.kt | 6 ++-- .../yenaly/han1meviewer/ui/view/HJzvdStd.kt | 3 ++ .../com/yenaly/han1meviewer/util/Cookies.kt | 4 +-- app/src/main/res/layout/dialog_login.xml | 6 ++++ app/src/main/res/values/strings.xml | 1 + 10 files changed, 65 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f64afe8b..804a334b 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,8 @@ GitHub 上的补充。目前是随着版本更新来更新共享关键H帧集, 你先等会,等该网页出现错误提示之后,会自动弹出一个登入框,你从那里登入就可以。 + 注意:该方法为备用方法,只能保持登入状态 2 个小时,所以还是建议尽可能使用网页登入。 + - **为什么不支持 Google 登录?** 去问 Google 为什么不给开放吧,我目前是没什么好办法。 @@ -160,7 +162,12 @@ GitHub 上的补充。目前是随着版本更新来更新共享关键H帧集, **[新增]** 重磅!应用内置 Hosts 功能,可以让你直连网站。 +**[新增]** [@NeKoOuO](https://github.com/NeKoOuO) 提供的部分影片的关键H帧!开启共享帧集就可立即使用! + **[新增]** 本地登入功能。如果登入网页连接失败,等出现错误提示之后,会自动弹出一个登入框,可以从那里尝试登入。 +注意:该方法为备用方法,只能保持登入状态 2 个小时,所以还是建议尽可能使用网页登入。 + +**[新增]** 长按快进有触动反馈了。 **[修复]** 切换简繁字幕无效的问题。 @@ -266,7 +273,7 @@ GitHub 上的补充。目前是随着版本更新来更新共享关键H帧集, ### v0.10.5 -**[新增]** 终于有图标了,感谢 [rurires](https://github.com/rurires) 提供! +**[新增]** 终于有图标了,感谢 [@rurires](https://github.com/rurires) 提供! **[修复]** 返回主页后总是展开头图。 @@ -393,5 +400,24 @@ bug 产生,所以建议下载完了再关闭。 ------ -~~这里应该还有东西,以后再写!~~ +## 开发者碎碎念 + +目前该软件还是我一人维护,我肯定是希望有更多的人参与到这个项目中来。 + +最近也有点忙,我尽量保证软件能用,其他的有空就整。 + +我 Cookie 有一块逻辑写错了两年我都没发现,但没想到的是,写错了竟然并不影响正常运行。 + +### 目前遇到的问题 + +- 通过分析可知,登入后正确的返回 Cookie 应为三个,分别为 + XSRF-TOKEN(校验token)、hanime1_session(代表登入)、remember_web_xxx(记住登入状态), + 但是通过本地登入方法,只能获取到 XSRF-TOKEN 和 hanime1_session,而 remember_web_xxx 无法获取,导致登入状态无法保存。 + 而 hanime1_session 的有效期只有 2 个小时,所以本地登入只能保持 2 个小时的登入状态。 + 如果有人知道如何正确获取 remember_web_xxx,请告诉我,感激不尽! + +- 关键H帧共享起来(指上传到 Github)确实对于一般人来说不太友好,到时候可能整个一键生成 JSON? + 你只需要负责 Pull Request。 + +- CI 构建是个好东西,但我得学一下怎么用... diff --git a/app/src/main/java/com/yenaly/han1meviewer/HanimeManager.kt b/app/src/main/java/com/yenaly/han1meviewer/HanimeManager.kt index bdc3a5d1..45a8d495 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/HanimeManager.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/HanimeManager.kt @@ -51,7 +51,13 @@ internal fun logout() { CookieManager.getInstance().removeAllCookies(null) } -internal fun login(cookie: CookieString) { +internal fun login(cookies: String) { isAlreadyLogin = true - loginCookie = cookie + loginCookie = CookieString(cookies) +} + +internal fun login(cookies: List) { + login(cookies.joinToString(";") { + it.substringBefore(';') + }) } \ No newline at end of file diff --git a/app/src/main/java/com/yenaly/han1meviewer/logic/NetworkRepo.kt b/app/src/main/java/com/yenaly/han1meviewer/logic/NetworkRepo.kt index 22ba23aa..7cd8e6ab 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/logic/NetworkRepo.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/logic/NetworkRepo.kt @@ -16,7 +16,6 @@ import com.yenaly.han1meviewer.logic.network.HanimeNetwork import com.yenaly.han1meviewer.logic.state.PageLoadingState import com.yenaly.han1meviewer.logic.state.VideoLoadingState import com.yenaly.han1meviewer.logic.state.WebsiteState -import com.yenaly.han1meviewer.util.CookieString import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.catch @@ -308,17 +307,18 @@ object NetworkRepo { fun login(email: String, password: String) = flow { // 首先获取token - val loginPage = HanimeNetwork.hanimeService.loginPage() + val loginPage = HanimeNetwork.hanimeService.getLoginPage() val token = loginPage.body()?.string()?.let(Parse::extractTokenFromLoginPage) - val req = HanimeNetwork.hanimeService.login(token, email, password) if (req.isSuccessful) { // 再次获取登录页面,如果失败则返回 cookie // 因为登录成功再次访问 login 会 404,这是判断是否登录成功的方法 - val loginPageAgain = HanimeNetwork.hanimeService.loginPage() + val loginPageAgain = HanimeNetwork.hanimeService.getLoginPage() if (loginPageAgain.code() == 404) { // Cookie 會返回 XSRF-TOKEN 和 hanime1_session,我們只需要後者 - emit(WebsiteState.Success(CookieString(req.raw().headers["Set-Cookie"]!!))) + // 错误的,还需要 remember_web 字段!但我没找到! + Log.d("login_headers", req.headers().toMultimap().toString()) + emit(WebsiteState.Success(req.headers().values("Set-Cookie"))) } else { emit(WebsiteState.Error(IllegalStateException("賬戶或密碼可能錯誤"))) } diff --git a/app/src/main/java/com/yenaly/han1meviewer/logic/network/ServiceCreator.kt b/app/src/main/java/com/yenaly/han1meviewer/logic/network/ServiceCreator.kt index e6115ba6..543e2eef 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/logic/network/ServiceCreator.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/logic/network/ServiceCreator.kt @@ -2,12 +2,15 @@ package com.yenaly.han1meviewer.logic.network import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import com.yenaly.han1meviewer.USER_AGENT +import com.yenaly.yenaly_libs.utils.applicationContext import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.serialization.json.Json +import okhttp3.Cache import okhttp3.Call import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import retrofit2.Retrofit +import java.io.File import java.io.IOException import java.util.concurrent.TimeUnit import kotlin.coroutines.resume @@ -25,6 +28,11 @@ object ServiceCreator { ignoreUnknownKeys = true } + val cache = Cache( + directory = File(applicationContext.cacheDir, "http_cache"), + maxSize = 10 * 1024 * 1024 + ) + inline fun create(baseUrl: String): T = Retrofit.Builder() .baseUrl(baseUrl) .client(okHttpClient) @@ -63,6 +71,7 @@ object ServiceCreator { chain.request().newBuilder().addHeader("User-Agent", USER_AGENT).build() return@addInterceptor chain.proceed(request) } + .cache(cache) .cookieJar(HCookieJar()) .proxySelector(HProxySelector()) .dns(HDns()) diff --git a/app/src/main/java/com/yenaly/han1meviewer/logic/network/service/HanimeBaseService.kt b/app/src/main/java/com/yenaly/han1meviewer/logic/network/service/HanimeBaseService.kt index 08f97bf2..2c8aba97 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/logic/network/service/HanimeBaseService.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/logic/network/service/HanimeBaseService.kt @@ -49,5 +49,5 @@ interface HanimeBaseService { ): Response @GET("login") - suspend fun loginPage(): Response + suspend fun getLoginPage(): Response } \ No newline at end of file diff --git a/app/src/main/java/com/yenaly/han1meviewer/ui/activity/LoginActivity.kt b/app/src/main/java/com/yenaly/han1meviewer/ui/activity/LoginActivity.kt index 49e2a57b..38de72a7 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/ui/activity/LoginActivity.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/ui/activity/LoginActivity.kt @@ -29,7 +29,6 @@ import com.yenaly.han1meviewer.databinding.ActivityLoginBinding import com.yenaly.han1meviewer.logic.NetworkRepo import com.yenaly.han1meviewer.logic.state.WebsiteState import com.yenaly.han1meviewer.login -import com.yenaly.han1meviewer.util.CookieString import com.yenaly.yenaly_libs.base.frame.FrameActivity import com.yenaly.yenaly_libs.utils.SystemStatusUtil import com.yenaly.yenaly_libs.utils.showShortToast @@ -40,7 +39,6 @@ class LoginActivity : FrameActivity() { private lateinit var binding: ActivityLoginBinding - private val dialog by unsafeLazy { LoginDialog(R.layout.dialog_login) } override fun setUiStyle() { @@ -71,11 +69,11 @@ class LoginActivity : FrameActivity() { it.setDisplayHomeAsUpEnabled(true) it.setHomeActionContentDescription(R.string.back) } + initWebView() binding.srlLogin.setOnRefreshListener { binding.wvLogin.loadUrl(HANIME_LOGIN_URL) } binding.srlLogin.autoRefresh() - initWebView() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -118,7 +116,7 @@ class LoginActivity : FrameActivity() { val url = request.url val cookieManager = CookieManager.getInstance().getCookie(url.host) Log.d("login_cookie", cookieManager.toString()) - login(CookieString(cookieManager)) + login(cookieManager) setResult(RESULT_OK) finish() return true diff --git a/app/src/main/java/com/yenaly/han1meviewer/ui/view/HJzvdStd.kt b/app/src/main/java/com/yenaly/han1meviewer/ui/view/HJzvdStd.kt index 7c54c850..2da22e9f 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/ui/view/HJzvdStd.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/ui/view/HJzvdStd.kt @@ -13,6 +13,7 @@ import android.util.AttributeSet import android.util.Log import android.view.GestureDetector import android.view.Gravity +import android.view.HapticFeedbackConstants import android.view.LayoutInflater import android.view.MotionEvent import android.view.View @@ -239,6 +240,7 @@ class HJzvdStd @JvmOverloads constructor( MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> { if (mediaInterface.isPlaying) { setSpeedInternal(videoSpeed * userDefLongPressSpeedTimes) + textureViewContainer.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) isSpeedGestureDetected = true } } @@ -254,6 +256,7 @@ class HJzvdStd @JvmOverloads constructor( tvKeyframe = findViewById(R.id.tv_keyframe) tvTimer = findViewById(R.id.tv_timer) btnGoHome = findViewById(R.id.go_home) + textureViewContainer.isHapticFeedbackEnabled = true tvSpeed.setOnClickListener(this) tvKeyframe.setOnClickListener(this) tvKeyframe.setOnLongClickListener(this) diff --git a/app/src/main/java/com/yenaly/han1meviewer/util/Cookies.kt b/app/src/main/java/com/yenaly/han1meviewer/util/Cookies.kt index 4f3b551b..033e8a54 100644 --- a/app/src/main/java/com/yenaly/han1meviewer/util/Cookies.kt +++ b/app/src/main/java/com/yenaly/han1meviewer/util/Cookies.kt @@ -15,8 +15,8 @@ internal fun CookieString.toLoginCookieList(domain: String): List { it += preferencesCookieList(domain) } cookie.split(';').forEach { cookie -> - val name = cookie.substringBefore('=').trim() - if (name.equals("hanime1_session", ignoreCase = true)) { + if (cookie.isNotBlank()) { + val name = cookie.substringBefore('=').trim() val value = cookie.substringAfter('=').trim() cookieList += Cookie.Builder().domain(domain).name(name).value(value).build() } diff --git a/app/src/main/res/layout/dialog_login.xml b/app/src/main/res/layout/dialog_login.xml index f701f5ea..738f4c65 100644 --- a/app/src/main/res/layout/dialog_login.xml +++ b/app/src/main/res/layout/dialog_login.xml @@ -7,6 +7,12 @@ android:paddingHorizontal="16dp" android:paddingTop="8dp"> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 901d81f0..ab13714b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -189,4 +189,5 @@ 登入失敗 登入成功 賬戶或密碼可能錯誤 + 該方法只能保持登入 2 個小時… 還是推薦使用網頁登入,\n但網頁是不走 Hosts 的,所以可能需要 VPN。 \ No newline at end of file