Fix bom subtitle

pull/88/head
FongMi 1 year ago
parent 0256823cd1
commit 9d006dc413
  1. 23
      app/src/main/java/com/github/catvod/spider/AList.java
  2. 2
      app/src/main/java/com/github/catvod/spider/Proxy.java
  3. 10
      app/src/main/java/com/github/catvod/utils/Util.java
  4. BIN
      jar/custom_spider.jar
  5. 2
      jar/custom_spider.jar.md5

@ -22,6 +22,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -36,6 +37,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import okhttp3.Response;
public class AList extends Spider {
private List<Drive> drives;
@ -150,10 +153,10 @@ public class AList extends Spider {
public String playerContent(String flag, String id, List<String> vipFlags) {
String[] ids = id.split("~~~");
String url = getDetail(ids[0]).getUrl();
return Result.get().url(url).header(getPlayHeader(url)).subs(getSub(ids)).string();
return Result.get().url(url).header(getPlayHeader(url)).subs(getSubs(ids)).string();
}
private Map<String, String> getPlayHeader(String url) {
private static Map<String, String> getPlayHeader(String url) {
try {
Uri uri = Uri.parse(url);
Map<String, String> header = new HashMap<>();
@ -244,19 +247,31 @@ public class AList extends Spider {
return sb.toString();
}
private List<Sub> getSub(String[] ids) {
private List<Sub> getSubs(String[] ids) {
List<Sub> sub = new ArrayList<>();
for (String text : ids) {
if (!text.contains("@@@")) continue;
String[] split = text.split("@@@");
String name = split[0];
String ext = split[1];
String url = getDetail(split[2]).getUrl();
String url = Proxy.getUrl() + "?do=alist&type=sub&url=" + getDetail(split[2]).getUrl();
sub.add(Sub.create().name(name).ext(ext).url(url));
}
return sub;
}
public static Object[] proxy(Map<String, String> params) throws Exception {
if (!"sub".equals(params.get("type"))) return null;
String url = params.get("url");
Response res = OkHttp.newCall(url, getPlayHeader(url));
byte[] body = Util.toUtf8(res.body().bytes());
Object[] result = new Object[3];
result[0] = 200;
result[1] = "application/octet-stream";
result[2] = new ByteArrayInputStream(body);
return result;
}
class Job implements Callable<List<Vod>> {
private final Drive drive;

@ -17,6 +17,8 @@ public class Proxy extends Spider {
return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream("ok".getBytes("UTF-8"))};
case "ali":
return Ali.proxy(params);
case "alist":
return AList.proxy(params);
case "bili":
return Bili.proxy(params);
case "webdav":

@ -62,12 +62,20 @@ public class Util {
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(bytes, 0, bytes.length);
detector.dataEnd();
return new String(bytes, detector.getDetectedCharset()).getBytes("UTF-8");
return removeBOM(new String(bytes, detector.getDetectedCharset()).getBytes("UTF-8"));
} catch (Exception e) {
return bytes;
}
}
public static byte[] removeBOM(byte[] bytes) {
byte[] bom = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF};
if (bytes.length < 3 || !Arrays.equals(Arrays.copyOf(bytes, 3), bom)) return bytes;
byte[] newBytes = new byte[bytes.length - 3];
System.arraycopy(bytes, 3, newBytes, 0, newBytes.length);
return newBytes;
}
public static boolean isSub(String ext) {
return SUB.contains(ext);
}

Binary file not shown.

@ -1 +1 @@
3569e45ba9e1c3200bff36d96acf4241
4c7e0340480fc0778222c0a0bb8bfc0c

Loading…
Cancel
Save