Support ali preview subtitle

This commit is contained in:
FongMi 2023-05-11 16:26:06 +08:00
parent 59703ee352
commit 3927e73874
4 changed files with 41 additions and 9 deletions

View File

@ -13,6 +13,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import com.github.catvod.BuildConfig; import com.github.catvod.BuildConfig;
import com.github.catvod.bean.Result;
import com.github.catvod.bean.Sub; import com.github.catvod.bean.Sub;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.bean.ali.Code; import com.github.catvod.bean.ali.Code;
@ -37,6 +38,7 @@ import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -337,7 +339,7 @@ public class API {
return sb.toString(); return sb.toString();
} }
public List<Sub> getSub(String[] ids) { public List<Sub> getSubs(String[] ids) {
List<Sub> sub = new ArrayList<>(); List<Sub> sub = new ArrayList<>();
for (String text : ids) { for (String text : ids) {
if (!text.contains("@@@")) continue; if (!text.contains("@@@")) continue;
@ -367,7 +369,7 @@ public class API {
} }
} }
public String getPreviewUrl(String fileId, String flag) { public JSONObject getVideoPreviewPlayInfo(String fileId) {
try { try {
SpiderDebug.log("getPreviewUrl..." + fileId); SpiderDebug.log("getPreviewUrl..." + fileId);
tempIds.add(0, copy(fileId)); tempIds.add(0, copy(fileId));
@ -377,17 +379,35 @@ public class API {
body.put("category", "live_transcoding"); body.put("category", "live_transcoding");
body.put("url_expire_sec", "14400"); body.put("url_expire_sec", "14400");
String json = oauth("openFile/getVideoPreviewPlayInfo", body.toString(), true); String json = oauth("openFile/getVideoPreviewPlayInfo", body.toString(), true);
JSONArray taskList = new JSONObject(json).getJSONObject("video_preview_play_info").getJSONArray("live_transcoding_task_list"); return new JSONObject(json).getJSONObject("video_preview_play_info");
return getPreviewQuality(taskList, flag);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ""; return new JSONObject();
} finally { } finally {
Init.execute(this::deleteAll); Init.execute(this::deleteAll);
} }
} }
private String getPreviewQuality(JSONArray taskList, String flag) throws Exception { public String playerContent(String[] ids) {
return Result.get().url(getDownloadUrl(ids[0])).subs(getSubs(ids)).header(getHeader()).string();
}
public String playerContent(String[] ids, String flag) {
try {
JSONObject playInfo = getVideoPreviewPlayInfo(ids[0]);
String url = getPreviewUrl(playInfo, flag);
List<Sub> subs = getSubs(ids);
subs.addAll(getSubs(playInfo));
return Result.get().url(url).subs(subs).header(getHeader()).string();
} catch (Exception e) {
e.printStackTrace();
return Result.get().url("").string();
}
}
private String getPreviewUrl(JSONObject playInfo, String flag) throws Exception {
if (!playInfo.has("live_transcoding_task_list")) return "";
JSONArray taskList = playInfo.getJSONArray("live_transcoding_task_list");
for (int i = 0; i < taskList.length(); ++i) { for (int i = 0; i < taskList.length(); ++i) {
JSONObject task = taskList.getJSONObject(i); JSONObject task = taskList.getJSONObject(i);
if (task.getString("template_id").equals(quality.get(flag))) { if (task.getString("template_id").equals(quality.get(flag))) {
@ -397,6 +417,19 @@ public class API {
return taskList.getJSONObject(0).getString("url"); return taskList.getJSONObject(0).getString("url");
} }
private List<Sub> getSubs(JSONObject playInfo) throws Exception {
if (!playInfo.has("live_transcoding_subtitle_task_list")) return Collections.emptyList();
JSONArray taskList = playInfo.getJSONArray("live_transcoding_subtitle_task_list");
List<Sub> subs = new ArrayList<>();
for (int i = 0; i < taskList.length(); ++i) {
JSONObject task = taskList.getJSONObject(i);
String lang = task.getString("language");
String url = task.getString("url");
subs.add(Sub.create().url(url).name(lang).lang(lang).ext("vtt"));
}
return subs;
}
private String copy(String fileId) throws Exception { private String copy(String fileId) throws Exception {
SpiderDebug.log("Copy..." + fileId); SpiderDebug.log("Copy..." + fileId);
String json = "{\"requests\":[{\"body\":{\"file_id\":\"%s\",\"share_id\":\"%s\",\"auto_rename\":true,\"to_parent_file_id\":\"root\",\"to_drive_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"0\",\"method\":\"POST\",\"url\":\"/file/copy\"}],\"resource\":\"file\"}"; String json = "{\"requests\":[{\"body\":{\"file_id\":\"%s\",\"share_id\":\"%s\",\"auto_rename\":true,\"to_parent_file_id\":\"root\",\"to_drive_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"0\",\"method\":\"POST\",\"url\":\"/file/copy\"}],\"resource\":\"file\"}";

View File

@ -37,8 +37,7 @@ public class Ali extends Spider {
@Override @Override
public String playerContent(String flag, String id, List<String> vipFlags) { public String playerContent(String flag, String id, List<String> vipFlags) {
String[] ids = id.split("\\+"); String[] ids = id.split("\\+");
String url = flag.equals("原畫") ? API.get().getDownloadUrl(ids[0]) : API.get().getPreviewUrl(ids[0], flag); return flag.equals("原畫") ? API.get().playerContent(ids) : API.get().playerContent(ids, flag);
return Result.get().url(url).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string();
} }
public static Object[] proxy(Map<String, String> params) { public static Object[] proxy(Map<String, String> params) {

Binary file not shown.

View File

@ -1 +1 @@
424328e448ccb8365a6e5a9477570853 22a9f82f400252c5adcf68f372540501