From 6a325551aeb85aa383ee1bdfb1b31e44f3f8740f Mon Sep 17 00:00:00 2001 From: FongMi Date: Fri, 23 Jun 2023 19:36:02 +0800 Subject: [PATCH] Fix subtitle charset detect --- app/build.gradle | 1 + .../main/java/com/github/catvod/utils/Utils.java | 15 ++++++--------- jar/custom_spider.jar.md5 | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fa80f51f..720c35c2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,6 +38,7 @@ dependencies { //Debug For HTTP/3 debugImplementation 'org.chromium.net:cronet-embedded:101.4951.41' implementation('com.github.thegrizzlylabs:sardine-android:0.8') { exclude group: 'com.squareup.okhttp3', module: 'okhttp' } + implementation 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3' implementation('com.squareup.okhttp3:okhttp:3.12.13') { force = true } implementation 'com.google.net.cronet:cronet-okhttp:0.1.0' implementation 'com.google.code.gson:gson:2.8.6' diff --git a/app/src/main/java/com/github/catvod/utils/Utils.java b/app/src/main/java/com/github/catvod/utils/Utils.java index 7ab81bc2..ce8a45c5 100644 --- a/app/src/main/java/com/github/catvod/utils/Utils.java +++ b/app/src/main/java/com/github/catvod/utils/Utils.java @@ -13,8 +13,9 @@ import android.webkit.WebViewClient; import com.github.catvod.spider.Init; +import org.mozilla.universalchardet.UniversalDetector; + import java.math.BigInteger; -import java.nio.charset.Charset; import java.security.MessageDigest; import java.util.Arrays; import java.util.List; @@ -49,15 +50,11 @@ public class Utils { return hasCamera && hasPhone && hasBT; } - public static boolean isGbk(byte[] bytes) { - Charset charset = Charset.forName("GBK"); - String str = new String(bytes, charset); - byte[] newBytes = str.getBytes(charset); - return Arrays.equals(bytes, newBytes); - } - public static byte[] toUtf8(byte[] bytes) throws Exception { - return isGbk(bytes) ? new String(bytes, Charset.forName("GBK")).getBytes("UTF-8") : bytes; + UniversalDetector detector = new UniversalDetector(null); + detector.handleData(bytes, 0, bytes.length); + detector.dataEnd(); + return new String(bytes, detector.getDetectedCharset()).getBytes("UTF-8"); } public static boolean isSub(String ext) { diff --git a/jar/custom_spider.jar.md5 b/jar/custom_spider.jar.md5 index 2c3df245..27df9a04 100644 --- a/jar/custom_spider.jar.md5 +++ b/jar/custom_spider.jar.md5 @@ -1 +1 @@ -12256c49c78305f2bedfd09b5d786620 +16f9147da64cbbc596831e87ebcafd79