diff --git a/app/src/main/java/com/github/catvod/ali/API.java b/app/src/main/java/com/github/catvod/ali/API.java index 0ac05bee..f46d3ae2 100644 --- a/app/src/main/java/com/github/catvod/ali/API.java +++ b/app/src/main/java/com/github/catvod/ali/API.java @@ -13,6 +13,7 @@ import android.widget.FrameLayout; import android.widget.ImageView; import com.github.catvod.BuildConfig; +import com.github.catvod.bean.Result; import com.github.catvod.bean.Sub; import com.github.catvod.bean.Vod; import com.github.catvod.bean.ali.Code; @@ -37,6 +38,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -101,6 +103,8 @@ public class API { } public void setShareId(String shareId) { + if (!getOAuthCache().exists()) oauth.clean().save(); + if (!getUserCache().exists()) user.clean().save(); this.shareId = shareId; refreshShareToken(); } @@ -125,16 +129,19 @@ public class API { return headers; } - private String alist(String url, JSONObject body) throws Exception { - url = "https://api.nn.ci/alist/ali_open/" + url; + private boolean alist(String url, JSONObject body) { OkResult result = OkHttp.postJson(url, body.toString(), getHeader()); SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody()); - return result.getBody(); + if (isManyRequest(result.getBody())) return false; + oauth = OAuth.objectFrom(result.getBody()).save(); + return true; } private String post(String url, JSONObject body) { url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url; - return OkHttp.postJson(url, body.toString(), getHeader()).getBody(); + OkResult result = OkHttp.postJson(url, body.toString(), getHeader()); + SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody()); + return result.getBody(); } private String auth(String url, String json, boolean retry) { @@ -191,7 +198,6 @@ public class API { body.put("grant_type", "refresh_token"); String result = post("https://auth.aliyundrive.com/v2/account/token", body); user = User.objectFrom(result).save(); - SpiderDebug.log(user.toString()); if (user.getAccessToken().isEmpty()) throw new Exception(result); return true; } catch (Exception e) { @@ -206,7 +212,7 @@ public class API { } } - private void oauthRequest() { + private boolean oauthRequest() { try { SpiderDebug.log("OAuth Request..."); JSONObject body = new JSONObject(); @@ -214,37 +220,35 @@ public class API { body.put("scope", "user:base,file:all:read,file:all:write"); String url = "https://open.aliyundrive.com/oauth/users/authorize?client_id=" + BuildConfig.CLIENT_ID + "&redirect_uri=https://alist.nn.ci/tool/aliyundrive/callback&scope=user:base,file:all:read,file:all:write&state="; String result = auth(url, body.toString(), true); - oauthRedirect(Code.objectFrom(result).getCode()); + return oauthRedirect(Code.objectFrom(result).getCode()); } catch (Exception e) { e.printStackTrace(); + return false; } } - private void oauthRedirect(String code) { + private boolean oauthRedirect(String code) { try { SpiderDebug.log("OAuth Redirect..."); JSONObject body = new JSONObject(); body.put("code", code); body.put("grant_type", "authorization_code"); - String result = alist("code", body); - if (isManyRequest(result)) return; - oauth = OAuth.objectFrom(result).save(); + return alist("https://api.nn.ci/alist/ali_open/code", body); } catch (Exception e) { e.printStackTrace(); oauth.clean().save(); + return false; } } private boolean refreshOpenToken() { try { + if (oauth.getRefreshToken().isEmpty()) return oauthRequest(); SpiderDebug.log("refreshOpenToken..."); JSONObject body = new JSONObject(); body.put("grant_type", "refresh_token"); body.put("refresh_token", oauth.getRefreshToken()); - String result = alist("token", body); - if (isManyRequest(result)) return false; - oauth = OAuth.objectFrom(result).save(); - return true; + return alist("https://api.nn.ci/alist/ali_open/token", body); } catch (Exception e) { e.printStackTrace(); oauth.clean().save(); @@ -335,7 +339,7 @@ public class API { return sb.toString(); } - public List getSub(String[] ids) { + public List getSubs(String[] ids) { List sub = new ArrayList<>(); for (String text : ids) { if (!text.contains("@@@")) continue; @@ -356,7 +360,6 @@ public class API { body.put("file_id", tempIds.get(0)); body.put("drive_id", user.getDriveId()); String json = oauth("openFile/getDownloadUrl", body.toString(), true); - SpiderDebug.log(json); return new JSONObject(json).getString("url"); } catch (Exception e) { e.printStackTrace(); @@ -366,9 +369,9 @@ public class API { } } - public String getPreviewUrl(String fileId, String flag) { + public JSONObject getVideoPreviewPlayInfo(String fileId) { try { - SpiderDebug.log("getPreviewUrl..." + fileId); + SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId); tempIds.add(0, copy(fileId)); JSONObject body = new JSONObject(); body.put("file_id", tempIds.get(0)); @@ -376,18 +379,35 @@ public class API { body.put("category", "live_transcoding"); body.put("url_expire_sec", "14400"); String json = oauth("openFile/getVideoPreviewPlayInfo", body.toString(), true); - SpiderDebug.log(json); - JSONArray taskList = new JSONObject(json).getJSONObject("video_preview_play_info").getJSONArray("live_transcoding_task_list"); - return getPreviewQuality(taskList, flag); + return new JSONObject(json).getJSONObject("video_preview_play_info"); } catch (Exception e) { e.printStackTrace(); - return ""; + return new JSONObject(); } finally { 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 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) { JSONObject task = taskList.getJSONObject(i); if (task.getString("template_id").equals(quality.get(flag))) { @@ -397,6 +417,19 @@ public class API { return taskList.getJSONObject(0).getString("url"); } + private List 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 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 { 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\"}"; @@ -505,7 +538,7 @@ public class API { private void setToken(String value) { SpiderDebug.log("Token:" + value); Init.show("Token:" + value); - this.refreshToken = value; + user.setRefreshToken(value); refreshAccessToken(); stopService(); } diff --git a/app/src/main/java/com/github/catvod/bean/ali/Sorter.java b/app/src/main/java/com/github/catvod/bean/ali/Sorter.java index 3ac7fe35..ee200131 100644 --- a/app/src/main/java/com/github/catvod/bean/ali/Sorter.java +++ b/app/src/main/java/com/github/catvod/bean/ali/Sorter.java @@ -22,6 +22,6 @@ public class Sorter implements Comparator { } private int getDigit(String text) throws NumberFormatException { - return Integer.parseInt(Utils.removeExt(text).replaceAll("\\D+", "")); + return Integer.parseInt(Utils.removeExt(text).replace("1080P", "").replace("4K", "").replaceAll("\\D+", "")); } } diff --git a/app/src/main/java/com/github/catvod/spider/Ali.java b/app/src/main/java/com/github/catvod/spider/Ali.java index 02e9cbc6..72e9f556 100644 --- a/app/src/main/java/com/github/catvod/spider/Ali.java +++ b/app/src/main/java/com/github/catvod/spider/Ali.java @@ -37,8 +37,7 @@ public class Ali extends Spider { @Override public String playerContent(String flag, String id, List vipFlags) { String[] ids = id.split("\\+"); - String url = flag.equals("原畫") ? API.get().getDownloadUrl(ids[0]) : API.get().getPreviewUrl(ids[0], flag); - return Result.get().url(url).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string(); + return flag.equals("原畫") ? API.get().playerContent(ids) : API.get().playerContent(ids, flag); } public static Object[] proxy(Map params) { diff --git a/jar/custom_spider.jar b/jar/custom_spider.jar index 229341c1..6c854da1 100644 Binary files a/jar/custom_spider.jar and b/jar/custom_spider.jar differ diff --git a/jar/custom_spider.jar.md5 b/jar/custom_spider.jar.md5 index 0f6420e5..bc84a8db 100644 --- a/jar/custom_spider.jar.md5 +++ b/jar/custom_spider.jar.md5 @@ -1 +1 @@ -77633695c1b9eb30846e021f48424a6d +c0dd741debca724250c91df251fdb2cf diff --git a/json/adult.json b/json/adult.json index 1b6a1289..3baea59d 100644 --- a/json/adult.json +++ b/json/adult.json @@ -1,5 +1,5 @@ { - "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;77633695c1b9eb30846e021f48424a6d", + "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;c0dd741debca724250c91df251fdb2cf", "wallpaper": "https://gao.chuqiuyu.tk", "sites": [ { diff --git a/json/config.json b/json/config.json index 3bdc1c63..da2c93a1 100644 --- a/json/config.json +++ b/json/config.json @@ -1,5 +1,5 @@ { - "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;77633695c1b9eb30846e021f48424a6d", + "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;c0dd741debca724250c91df251fdb2cf", "wallpaper": "http://饭太硬.ga/深色壁纸/api.php", "sites": [ {