|
|
|
@ -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;
|
|
|
|
@ -101,6 +103,8 @@ public class API {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setShareId(String shareId) {
|
|
|
|
public void setShareId(String shareId) {
|
|
|
|
|
|
|
|
if (!getOAuthCache().exists()) oauth.clean().save();
|
|
|
|
|
|
|
|
if (!getUserCache().exists()) user.clean().save();
|
|
|
|
this.shareId = shareId;
|
|
|
|
this.shareId = shareId;
|
|
|
|
refreshShareToken();
|
|
|
|
refreshShareToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -125,16 +129,19 @@ public class API {
|
|
|
|
return headers;
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String alist(String url, JSONObject body) throws Exception {
|
|
|
|
private boolean alist(String url, JSONObject body) {
|
|
|
|
url = "https://api.nn.ci/alist/ali_open/" + url;
|
|
|
|
|
|
|
|
OkResult result = OkHttp.postJson(url, body.toString(), getHeader());
|
|
|
|
OkResult result = OkHttp.postJson(url, body.toString(), getHeader());
|
|
|
|
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
|
|
|
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) {
|
|
|
|
private String post(String url, JSONObject body) {
|
|
|
|
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
|
|
|
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) {
|
|
|
|
private String auth(String url, String json, boolean retry) {
|
|
|
|
@ -191,7 +198,6 @@ public class API {
|
|
|
|
body.put("grant_type", "refresh_token");
|
|
|
|
body.put("grant_type", "refresh_token");
|
|
|
|
String result = post("https://auth.aliyundrive.com/v2/account/token", body);
|
|
|
|
String result = post("https://auth.aliyundrive.com/v2/account/token", body);
|
|
|
|
user = User.objectFrom(result).save();
|
|
|
|
user = User.objectFrom(result).save();
|
|
|
|
SpiderDebug.log(user.toString());
|
|
|
|
|
|
|
|
if (user.getAccessToken().isEmpty()) throw new Exception(result);
|
|
|
|
if (user.getAccessToken().isEmpty()) throw new Exception(result);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -206,7 +212,7 @@ public class API {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void oauthRequest() {
|
|
|
|
private boolean oauthRequest() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
SpiderDebug.log("OAuth Request...");
|
|
|
|
SpiderDebug.log("OAuth Request...");
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
@ -214,37 +220,35 @@ public class API {
|
|
|
|
body.put("scope", "user:base,file:all:read,file:all:write");
|
|
|
|
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 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);
|
|
|
|
String result = auth(url, body.toString(), true);
|
|
|
|
oauthRedirect(Code.objectFrom(result).getCode());
|
|
|
|
return oauthRedirect(Code.objectFrom(result).getCode());
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void oauthRedirect(String code) {
|
|
|
|
private boolean oauthRedirect(String code) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
SpiderDebug.log("OAuth Redirect...");
|
|
|
|
SpiderDebug.log("OAuth Redirect...");
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
body.put("code", code);
|
|
|
|
body.put("code", code);
|
|
|
|
body.put("grant_type", "authorization_code");
|
|
|
|
body.put("grant_type", "authorization_code");
|
|
|
|
String result = alist("code", body);
|
|
|
|
return alist("https://api.nn.ci/alist/ali_open/code", body);
|
|
|
|
if (isManyRequest(result)) return;
|
|
|
|
|
|
|
|
oauth = OAuth.objectFrom(result).save();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
oauth.clean().save();
|
|
|
|
oauth.clean().save();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean refreshOpenToken() {
|
|
|
|
private boolean refreshOpenToken() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (oauth.getRefreshToken().isEmpty()) return oauthRequest();
|
|
|
|
SpiderDebug.log("refreshOpenToken...");
|
|
|
|
SpiderDebug.log("refreshOpenToken...");
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
body.put("grant_type", "refresh_token");
|
|
|
|
body.put("grant_type", "refresh_token");
|
|
|
|
body.put("refresh_token", oauth.getRefreshToken());
|
|
|
|
body.put("refresh_token", oauth.getRefreshToken());
|
|
|
|
String result = alist("token", body);
|
|
|
|
return alist("https://api.nn.ci/alist/ali_open/token", body);
|
|
|
|
if (isManyRequest(result)) return false;
|
|
|
|
|
|
|
|
oauth = OAuth.objectFrom(result).save();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
oauth.clean().save();
|
|
|
|
oauth.clean().save();
|
|
|
|
@ -335,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;
|
|
|
|
@ -356,7 +360,6 @@ public class API {
|
|
|
|
body.put("file_id", tempIds.get(0));
|
|
|
|
body.put("file_id", tempIds.get(0));
|
|
|
|
body.put("drive_id", user.getDriveId());
|
|
|
|
body.put("drive_id", user.getDriveId());
|
|
|
|
String json = oauth("openFile/getDownloadUrl", body.toString(), true);
|
|
|
|
String json = oauth("openFile/getDownloadUrl", body.toString(), true);
|
|
|
|
SpiderDebug.log(json);
|
|
|
|
|
|
|
|
return new JSONObject(json).getString("url");
|
|
|
|
return new JSONObject(json).getString("url");
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -366,9 +369,9 @@ public class API {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getPreviewUrl(String fileId, String flag) {
|
|
|
|
public JSONObject getVideoPreviewPlayInfo(String fileId) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
SpiderDebug.log("getPreviewUrl..." + fileId);
|
|
|
|
SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId);
|
|
|
|
tempIds.add(0, copy(fileId));
|
|
|
|
tempIds.add(0, copy(fileId));
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
body.put("file_id", tempIds.get(0));
|
|
|
|
body.put("file_id", tempIds.get(0));
|
|
|
|
@ -376,18 +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);
|
|
|
|
SpiderDebug.log(json);
|
|
|
|
return new JSONObject(json).getJSONObject("video_preview_play_info");
|
|
|
|
JSONArray taskList = new JSONObject(json).getJSONObject("video_preview_play_info").getJSONArray("live_transcoding_task_list");
|
|
|
|
|
|
|
|
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\"}";
|
|
|
|
@ -505,7 +538,7 @@ public class API {
|
|
|
|
private void setToken(String value) {
|
|
|
|
private void setToken(String value) {
|
|
|
|
SpiderDebug.log("Token:" + value);
|
|
|
|
SpiderDebug.log("Token:" + value);
|
|
|
|
Init.show("Token:" + value);
|
|
|
|
Init.show("Token:" + value);
|
|
|
|
this.refreshToken = value;
|
|
|
|
user.setRefreshToken(value);
|
|
|
|
refreshAccessToken();
|
|
|
|
refreshAccessToken();
|
|
|
|
stopService();
|
|
|
|
stopService();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|