Support non utf-8 subtitle

pull/445/head
FongMi 2 years ago
parent 253bf0e788
commit fde6c59919
  1. 2
      app/src/main/java/com/fongmi/android/tv/bean/Sub.java
  2. 3
      catvod/build.gradle
  3. 17
      catvod/src/main/java/com/github/catvod/utils/Path.java
  4. 14
      catvod/src/main/java/com/github/catvod/utils/Util.java

@ -30,7 +30,7 @@ public class Sub {
if (path.startsWith("http")) {
return http(path);
} else {
return file(Path.local(path));
return file(Path.utf8(Path.local(path)));
}
}

@ -16,9 +16,10 @@ dependencies {
api 'androidx.annotation:annotation:' + annotationVersion
api 'androidx.preference:preference:1.2.1'
api 'com.google.code.gson:gson:' + gsonVersion
api 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
api 'org.nanohttpd:nanohttpd:2.3.1'
api 'com.orhanobut:logger:2.2.0'
api 'com.squareup.okhttp3:okhttp:' + okhttpVersion
api 'com.squareup.okhttp3:okhttp-dnsoverhttps:' + okhttpVersion
api 'org.nanohttpd:nanohttpd:2.3.1'
api 'com.tencent.tbs:tbssdk:44286'
}

@ -150,6 +150,19 @@ public class Path {
}
}
public static byte[] readToByte(File file) {
try {
FileInputStream is = new FileInputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
is.close();
return data;
} catch (IOException e) {
e.printStackTrace();
return new byte[0];
}
}
public static File write(File file, byte[] data) {
try {
FileOutputStream fos = new FileOutputStream(create(file));
@ -163,6 +176,10 @@ public class Path {
}
}
public static File utf8(File file) {
return write(cache(file.getName()), Util.utf8(readToByte(file)));
}
public static void move(File in, File out) {
copy(in, out);
clear(in);

@ -8,6 +8,8 @@ import android.util.Base64;
import com.github.catvod.Init;
import org.mozilla.universalchardet.UniversalDetector;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
@ -15,6 +17,7 @@ import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
@ -45,6 +48,17 @@ public class Util {
return md5(Path.jar(name)).equalsIgnoreCase(md5);
}
public static byte[] utf8(byte[] bytes) {
try {
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(bytes, 0, bytes.length);
detector.dataEnd();
return new String(bytes, detector.getDetectedCharset()).getBytes(StandardCharsets.UTF_8);
} catch (Exception e) {
return bytes;
}
}
public static String md5(String src) {
try {
if (TextUtils.isEmpty(src)) return "";

Loading…
Cancel
Save