Support gbk srt file

This commit is contained in:
FongMi 2023-05-25 21:15:25 +08:00
parent 7a8b7bedf2
commit a0182d8625
3 changed files with 23 additions and 4 deletions

View File

@ -47,6 +47,8 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import okhttp3.Response;
public class API { public class API {
private final Map<String, String> quality; private final Map<String, String> quality;
@ -457,13 +459,14 @@ public class API {
} }
} }
public Object[] proxySub(Map<String, String> params) { public Object[] proxySub(Map<String, String> params) throws Exception {
String fileId = params.get("file_id"); String fileId = params.get("file_id");
String text = OkHttp.string(getDownloadUrl(fileId), getHeaderAuth()); Response res = OkHttp.newCall(getDownloadUrl(fileId), getHeaderAuth());
byte[] body = Utils.getUTF8(res.body().bytes());
Object[] result = new Object[3]; Object[] result = new Object[3];
result[0] = 200; result[0] = 200;
result[1] = "application/octet-stream"; result[1] = "application/octet-stream";
result[2] = new ByteArrayInputStream(text.getBytes()); result[2] = new ByteArrayInputStream(body);
return result; return result;
} }

View File

@ -40,7 +40,7 @@ public class Ali extends Spider {
return flag.equals("原畫") ? API.get().playerContent(ids) : API.get().playerContent(ids, flag); return flag.equals("原畫") ? API.get().playerContent(ids) : API.get().playerContent(ids, flag);
} }
public static Object[] proxy(Map<String, String> params) { public static Object[] proxy(Map<String, String> params) throws Exception {
String type = params.get("type"); String type = params.get("type");
if (type.equals("sub")) return API.get().proxySub(params); if (type.equals("sub")) return API.get().proxySub(params);
if (type.equals("token")) return API.get().getToken(); if (type.equals("token")) return API.get().getToken();

View File

@ -14,6 +14,7 @@ import android.webkit.WebViewClient;
import com.github.catvod.spider.Init; import com.github.catvod.spider.Init;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -48,6 +49,21 @@ public class Utils {
return hasCamera && hasPhone && hasBT; 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[] getUTF8(byte[] bytes) throws Exception {
if (isGBK(bytes)) {
return new String(bytes, Charset.forName("GBK")).getBytes("UTF-8");
} else {
return bytes;
}
}
public static boolean isSub(String ext) { public static boolean isSub(String ext) {
return ext.equals("srt") || ext.equals("ass") || ext.equals("ssa"); return ext.equals("srt") || ext.equals("ass") || ext.equals("ssa");
} }