Merge branch 'main' of github.com:oiltea/CatVodSpider
This commit is contained in:
commit
92c3171f54
|
|
@ -19,9 +19,13 @@ 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;
|
||||||
import com.github.catvod.bean.ali.Data;
|
import com.github.catvod.bean.ali.Data;
|
||||||
|
import com.github.catvod.bean.ali.Download;
|
||||||
import com.github.catvod.bean.ali.Drive;
|
import com.github.catvod.bean.ali.Drive;
|
||||||
import com.github.catvod.bean.ali.Item;
|
import com.github.catvod.bean.ali.Item;
|
||||||
import com.github.catvod.bean.ali.OAuth;
|
import com.github.catvod.bean.ali.OAuth;
|
||||||
|
import com.github.catvod.bean.ali.Preview;
|
||||||
|
import com.github.catvod.bean.ali.Res;
|
||||||
|
import com.github.catvod.bean.ali.Share;
|
||||||
import com.github.catvod.bean.ali.User;
|
import com.github.catvod.bean.ali.User;
|
||||||
import com.github.catvod.crawler.SpiderDebug;
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
|
|
@ -31,9 +35,7 @@ import com.github.catvod.spider.Proxy;
|
||||||
import com.github.catvod.utils.FileUtil;
|
import com.github.catvod.utils.FileUtil;
|
||||||
import com.github.catvod.utils.QRCode;
|
import com.github.catvod.utils.QRCode;
|
||||||
import com.github.catvod.utils.Utils;
|
import com.github.catvod.utils.Utils;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -131,21 +133,18 @@ public class AliYun {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean alist(String url, JSONObject body) {
|
private boolean alist(String url, JsonObject param) {
|
||||||
//https://api-cf.nn.ci/alist/ali_open/
|
|
||||||
//https://api.xhofe.top/alist/ali_open/
|
|
||||||
//https://sni_api_nn_ci.cooluc.com/alist/ali_open/
|
|
||||||
String api = "https://aliapi.ewwe.gq/alist/ali_open/" + url;
|
String api = "https://aliapi.ewwe.gq/alist/ali_open/" + url;
|
||||||
OkResult result = OkHttp.postJson(api, body.toString(), getHeader());
|
OkResult result = OkHttp.postJson(api, param.toString(), getHeader());
|
||||||
SpiderDebug.log(result.getCode() + "," + api + "," + result.getBody());
|
SpiderDebug.log(result.getCode() + "," + api + "," + result.getBody());
|
||||||
if (isManyRequest(result.getBody())) return false;
|
if (isManyRequest(result.getBody())) return false;
|
||||||
oauth = OAuth.objectFrom(result.getBody()).save();
|
oauth = OAuth.objectFrom(result.getBody()).save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String post(String url, JSONObject body) {
|
private String post(String url, JsonObject param) {
|
||||||
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
||||||
OkResult result = OkHttp.postJson(url, body.toString(), getHeader());
|
OkResult result = OkHttp.postJson(url, param.toString(), getHeader());
|
||||||
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
||||||
return result.getBody();
|
return result.getBody();
|
||||||
}
|
}
|
||||||
|
|
@ -180,31 +179,27 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshShareToken() {
|
private void refreshShareToken() {
|
||||||
try {
|
SpiderDebug.log("refreshShareToken...");
|
||||||
SpiderDebug.log("refreshShareToken...");
|
JsonObject param = new JsonObject();
|
||||||
JSONObject body = new JSONObject();
|
param.addProperty("share_id", shareId);
|
||||||
body.put("share_id", shareId);
|
param.addProperty("share_pwd", "");
|
||||||
body.put("share_pwd", "");
|
String json = post("v2/share_link/get_share_token", param);
|
||||||
String result = post("v2/share_link/get_share_token", body);
|
shareToken = Share.objectFrom(json).getShareToken();
|
||||||
shareToken = new JSONObject(result).getString("share_token");
|
if (shareToken.isEmpty()) Utils.notify("來晚啦,該分享已失效。");
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Utils.notify("來晚啦,該分享已失效。");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean refreshAccessToken() {
|
private boolean refreshAccessToken() {
|
||||||
try {
|
try {
|
||||||
SpiderDebug.log("refreshAccessToken...");
|
SpiderDebug.log("refreshAccessToken...");
|
||||||
JSONObject body = new JSONObject();
|
JsonObject param = new JsonObject();
|
||||||
String token = user.getRefreshToken();
|
String token = user.getRefreshToken();
|
||||||
if (token.isEmpty()) token = refreshToken;
|
if (token.isEmpty()) token = refreshToken;
|
||||||
if (token.startsWith("http")) token = OkHttp.string(token).trim();
|
if (token.startsWith("http")) token = OkHttp.string(token).trim();
|
||||||
body.put("refresh_token", token);
|
param.addProperty("refresh_token", token);
|
||||||
body.put("grant_type", "refresh_token");
|
param.addProperty("grant_type", "refresh_token");
|
||||||
String result = post("https://auth.aliyundrive.com/v2/account/token", body);
|
String json = post("https://auth.aliyundrive.com/v2/account/token", param);
|
||||||
user = User.objectFrom(result).save();
|
user = User.objectFrom(json).save();
|
||||||
if (user.getAccessToken().isEmpty()) throw new Exception(result);
|
if (user.getAccessToken().isEmpty()) throw new Exception(json);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e instanceof TimeoutException) return onTimeout();
|
if (e instanceof TimeoutException) return onTimeout();
|
||||||
|
|
@ -218,72 +213,47 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getDriveId() {
|
private void getDriveId() {
|
||||||
try {
|
SpiderDebug.log("Obtain drive id...");
|
||||||
SpiderDebug.log("Obtain drive id...");
|
String result = auth("https://user.aliyundrive.com/v2/user/get", "{}", false);
|
||||||
String result = auth("https://user.aliyundrive.com/v2/user/get", "{}", false);
|
drive = Drive.objectFrom(result).save();
|
||||||
drive = Drive.objectFrom(result).save();
|
driveId = drive.getResourceDriveId().isEmpty() ? drive.getDriveId() : drive.getResourceDriveId();
|
||||||
driveId = drive.getResourceDriveId().isEmpty() ? drive.getDriveId() : drive.getResourceDriveId();
|
|
||||||
return false;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
drive.clean().save();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean oauthRequest() {
|
private boolean oauthRequest() {
|
||||||
try {
|
SpiderDebug.log("OAuth Request...");
|
||||||
SpiderDebug.log("OAuth Request...");
|
JsonObject param = new JsonObject();
|
||||||
JSONObject body = new JSONObject();
|
param.addProperty("authorize", 1);
|
||||||
body.put("authorize", 1);
|
param.addProperty("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 json = auth(url, param.toString(), true);
|
||||||
String result = auth(url, body.toString(), true);
|
return oauthRedirect(Code.objectFrom(json).getCode());
|
||||||
return oauthRedirect(Code.objectFrom(result).getCode());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean oauthRedirect(String code) {
|
private boolean oauthRedirect(String code) {
|
||||||
try {
|
SpiderDebug.log("OAuth Redirect...");
|
||||||
SpiderDebug.log("OAuth Redirect...");
|
JsonObject param = new JsonObject();
|
||||||
JSONObject body = new JSONObject();
|
param.addProperty("code", code);
|
||||||
body.put("code", code);
|
param.addProperty("grant_type", "authorization_code");
|
||||||
body.put("grant_type", "authorization_code");
|
return alist("code", param);
|
||||||
return alist("code", body);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
oauth.clean().save();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean refreshOpenToken() {
|
private boolean refreshOpenToken() {
|
||||||
try {
|
if (oauth.getRefreshToken().isEmpty()) return oauthRequest();
|
||||||
if (oauth.getRefreshToken().isEmpty()) return oauthRequest();
|
SpiderDebug.log("refreshOpenToken...");
|
||||||
SpiderDebug.log("refreshOpenToken...");
|
JsonObject param = new JsonObject();
|
||||||
JSONObject body = new JSONObject();
|
param.addProperty("grant_type", "refresh_token");
|
||||||
body.put("grant_type", "refresh_token");
|
param.addProperty("refresh_token", oauth.getRefreshToken());
|
||||||
body.put("refresh_token", oauth.getRefreshToken());
|
return alist("token", param);
|
||||||
return alist("token", body);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
oauth.clean().save();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vod getVod(String url, String fileId) throws Exception {
|
public Vod getVod(String url, String fileId) {
|
||||||
JSONObject body = new JSONObject();
|
JsonObject param = new JsonObject();
|
||||||
body.put("share_id", shareId);
|
param.addProperty("share_id", shareId);
|
||||||
String result = post("adrive/v3/share_link/get_share_by_anonymous", body);
|
Share share = Share.objectFrom(post("adrive/v3/share_link/get_share_by_anonymous", param));
|
||||||
JSONObject object = new JSONObject(result);
|
|
||||||
List<Item> files = new ArrayList<>();
|
List<Item> files = new ArrayList<>();
|
||||||
List<Item> subs = new ArrayList<>();
|
List<Item> subs = new ArrayList<>();
|
||||||
listFiles(new Item(getParentFileId(fileId, object)), files, subs);
|
listFiles(new Item(getParentFileId(fileId, share)), files, subs);
|
||||||
Collections.sort(files);
|
Collections.sort(files);
|
||||||
List<String> playFrom = Arrays.asList("原畫", "普畫");
|
List<String> playFrom = Arrays.asList("原畫", "普畫");
|
||||||
List<String> episode = new ArrayList<>();
|
List<String> episode = new ArrayList<>();
|
||||||
|
|
@ -293,28 +263,28 @@ public class AliYun {
|
||||||
Vod vod = new Vod();
|
Vod vod = new Vod();
|
||||||
vod.setVodId(url);
|
vod.setVodId(url);
|
||||||
vod.setVodContent(url);
|
vod.setVodContent(url);
|
||||||
vod.setVodPic(object.getString("avatar"));
|
vod.setVodPic(share.getAvatar());
|
||||||
vod.setVodName(object.getString("share_name"));
|
vod.setVodName(share.getShareName());
|
||||||
vod.setVodPlayUrl(TextUtils.join("$$$", playUrl));
|
vod.setVodPlayUrl(TextUtils.join("$$$", playUrl));
|
||||||
vod.setVodPlayFrom(TextUtils.join("$$$", playFrom));
|
vod.setVodPlayFrom(TextUtils.join("$$$", playFrom));
|
||||||
vod.setTypeName("阿里雲盤");
|
vod.setTypeName("阿里雲盤");
|
||||||
return vod;
|
return vod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listFiles(Item folder, List<Item> files, List<Item> subs) throws Exception {
|
private void listFiles(Item folder, List<Item> files, List<Item> subs) {
|
||||||
listFiles(folder, files, subs, "");
|
listFiles(folder, files, subs, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listFiles(Item parent, List<Item> files, List<Item> subs, String marker) throws Exception {
|
private void listFiles(Item parent, List<Item> files, List<Item> subs, String marker) {
|
||||||
JSONObject body = new JSONObject();
|
|
||||||
List<Item> folders = new ArrayList<>();
|
List<Item> folders = new ArrayList<>();
|
||||||
body.put("limit", 200);
|
JsonObject param = new JsonObject();
|
||||||
body.put("share_id", shareId);
|
param.addProperty("limit", 200);
|
||||||
body.put("parent_file_id", parent.getFileId());
|
param.addProperty("share_id", shareId);
|
||||||
body.put("order_by", "name");
|
param.addProperty("parent_file_id", parent.getFileId());
|
||||||
body.put("order_direction", "ASC");
|
param.addProperty("order_by", "name");
|
||||||
if (marker.length() > 0) body.put("marker", marker);
|
param.addProperty("order_direction", "ASC");
|
||||||
Item item = Item.objectFrom(auth("adrive/v3/file/list", body.toString(), true));
|
if (marker.length() > 0) param.addProperty("marker", marker);
|
||||||
|
Item item = Item.objectFrom(auth("adrive/v3/file/list", param.toString(), true));
|
||||||
for (Item file : item.getItems()) {
|
for (Item file : item.getItems()) {
|
||||||
if (file.getType().equals("folder")) {
|
if (file.getType().equals("folder")) {
|
||||||
folders.add(file);
|
folders.add(file);
|
||||||
|
|
@ -332,14 +302,11 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParentFileId(String fileId, JSONObject shareInfo) throws Exception {
|
private String getParentFileId(String fileId, Share share) {
|
||||||
JSONArray array = shareInfo.getJSONArray("file_infos");
|
|
||||||
if (!TextUtils.isEmpty(fileId)) return fileId;
|
if (!TextUtils.isEmpty(fileId)) return fileId;
|
||||||
if (array.length() == 0) return "";
|
if (share.getFileInfos().isEmpty()) return "";
|
||||||
JSONObject fileInfo = array.getJSONObject(0);
|
Item item = share.getFileInfos().get(0);
|
||||||
if (fileInfo.getString("type").equals("folder")) return fileInfo.getString("file_id");
|
return item.getType().equals("folder") ? item.getFileId() : "root";
|
||||||
if (fileInfo.getString("type").equals("file") && fileInfo.getString("category").equals("video")) return "root";
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pair(String name1, List<Item> items, List<Item> subs) {
|
private void pair(String name1, List<Item> items, List<Item> subs) {
|
||||||
|
|
@ -373,14 +340,14 @@ public class AliYun {
|
||||||
|
|
||||||
public String getDownloadUrl(String fileId) {
|
public String getDownloadUrl(String fileId) {
|
||||||
try {
|
try {
|
||||||
|
getDriveId();
|
||||||
SpiderDebug.log("getDownloadUrl..." + fileId);
|
SpiderDebug.log("getDownloadUrl..." + fileId);
|
||||||
if (getDriveId()) throw new Exception("unable obtain drive id");
|
tempIds.add(0, copy(fileId, true));
|
||||||
tempIds.add(0, copy(fileId));
|
JsonObject param = new JsonObject();
|
||||||
JSONObject body = new JSONObject();
|
param.addProperty("file_id", tempIds.get(0));
|
||||||
body.put("file_id", tempIds.get(0));
|
param.addProperty("drive_id", driveId);
|
||||||
body.put("drive_id", driveId);
|
String json = oauth("openFile/getDownloadUrl", param.toString(), true);
|
||||||
String json = oauth("openFile/getDownloadUrl", body.toString(), true);
|
return Download.objectFrom(json).getUrl();
|
||||||
return new JSONObject(json).getString("url");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return "";
|
return "";
|
||||||
|
|
@ -389,21 +356,21 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getVideoPreviewPlayInfo(String fileId) {
|
public Preview.Info getVideoPreviewPlayInfo(String fileId) {
|
||||||
try {
|
try {
|
||||||
|
getDriveId();
|
||||||
SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId);
|
SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId);
|
||||||
if (getDriveId()) throw new Exception("unable obtain drive id");
|
tempIds.add(0, copy(fileId, true));
|
||||||
tempIds.add(0, copy(fileId));
|
JsonObject param = new JsonObject();
|
||||||
JSONObject body = new JSONObject();
|
param.addProperty("file_id", tempIds.get(0));
|
||||||
body.put("file_id", tempIds.get(0));
|
param.addProperty("drive_id", driveId);
|
||||||
body.put("drive_id", driveId);
|
param.addProperty("category", "live_transcoding");
|
||||||
body.put("category", "live_transcoding");
|
param.addProperty("url_expire_sec", "14400");
|
||||||
body.put("url_expire_sec", "14400");
|
String json = oauth("openFile/getVideoPreviewPlayInfo", param.toString(), true);
|
||||||
String json = oauth("openFile/getVideoPreviewPlayInfo", body.toString(), true);
|
return Preview.objectFrom(json).getVideoPreviewPlayInfo();
|
||||||
return new JSONObject(json).getJSONObject("video_preview_play_info");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new JSONObject();
|
return new Preview.Info();
|
||||||
} finally {
|
} finally {
|
||||||
Init.execute(this::deleteAll);
|
Init.execute(this::deleteAll);
|
||||||
}
|
}
|
||||||
|
|
@ -415,51 +382,38 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPreviewContent(String[] ids) {
|
private String getPreviewContent(String[] ids) {
|
||||||
try {
|
Preview.Info info = getVideoPreviewPlayInfo(ids[0]);
|
||||||
JSONObject playInfo = getVideoPreviewPlayInfo(ids[0]);
|
List<String> url = getPreviewUrl(info);
|
||||||
List<String> url = getPreviewUrl(playInfo);
|
List<Sub> subs = getSubs(ids);
|
||||||
List<Sub> subs = getSubs(ids);
|
subs.addAll(getSubs(info));
|
||||||
subs.addAll(getSubs(playInfo));
|
return Result.get().url(url).m3u8().subs(subs).header(getHeader()).string();
|
||||||
return Result.get().url(url).m3u8().subs(subs).header(getHeader()).string();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return Result.get().url("").string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getPreviewUrl(JSONObject playInfo) throws Exception {
|
private List<String> getPreviewUrl(Preview.Info info) {
|
||||||
if (!playInfo.has("live_transcoding_task_list")) return Collections.emptyList();
|
List<Preview.LiveTranscodingTask> tasks = info.getLiveTranscodingTaskList();
|
||||||
JSONArray taskList = playInfo.getJSONArray("live_transcoding_task_list");
|
|
||||||
List<String> url = new ArrayList<>();
|
List<String> url = new ArrayList<>();
|
||||||
for (int i = taskList.length() - 1; i >= 0; i--) {
|
for (int i = tasks.size() - 1; i >= 0; i--) {
|
||||||
JSONObject task = taskList.getJSONObject(i);
|
url.add(tasks.get(i).getTemplateId());
|
||||||
if (!task.optString("status").equals("finished")) continue;
|
url.add(tasks.get(i).getUrl());
|
||||||
url.add(task.optString("template_id"));
|
|
||||||
url.add(task.optString("url"));
|
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Sub> getSubs(JSONObject playInfo) throws Exception {
|
private List<Sub> getSubs(Preview.Info info) {
|
||||||
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<>();
|
List<Sub> subs = new ArrayList<>();
|
||||||
for (int i = 0; i < taskList.length(); ++i) {
|
for (Preview.LiveTranscodingTask task : info.getLiveTranscodingSubtitleTaskList()) subs.add(task.getSub());
|
||||||
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;
|
return subs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String copy(String fileId) throws Exception {
|
private String copy(String fileId, boolean retry) 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\"}";
|
||||||
json = String.format(json, fileId, shareId, driveId);
|
json = String.format(json, fileId, shareId, driveId);
|
||||||
String result = auth("adrive/v2/batch", json, true);
|
Res res = Res.objectFrom(auth("adrive/v2/batch", json, true));
|
||||||
if (result.contains("ForbiddenNoPermission.File")) return copy(fileId);
|
if (res.getResponse().getStatus() == 403 && retry) refreshShareToken();
|
||||||
return new JSONObject(result).getJSONArray("responses").getJSONObject(0).getJSONObject("body").getString("file_id");
|
if (res.getResponse().getStatus() == 403 && retry) copy(fileId, false);
|
||||||
|
if (res.getResponse().getStatus() == 403 && !retry) throw new Exception(res.getResponse().getBody().getMessage());
|
||||||
|
return res.getResponse().getBody().getFileId();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAll() {
|
private void deleteAll() {
|
||||||
|
|
@ -471,15 +425,11 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean delete(String fileId) {
|
private boolean delete(String fileId) {
|
||||||
try {
|
SpiderDebug.log("Delete..." + fileId);
|
||||||
SpiderDebug.log("Delete..." + fileId);
|
String json = "{\"requests\":[{\"body\":{\"drive_id\":\"%s\",\"file_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"%s\",\"method\":\"POST\",\"url\":\"/file/delete\"}],\"resource\":\"file\"}";
|
||||||
String json = "{\"requests\":[{\"body\":{\"drive_id\":\"%s\",\"file_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"%s\",\"method\":\"POST\",\"url\":\"/file/delete\"}],\"resource\":\"file\"}";
|
json = String.format(json, driveId, fileId, fileId);
|
||||||
json = String.format(json, driveId, fileId, fileId);
|
Res res = Res.objectFrom(auth("adrive/v2/batch", json, true));
|
||||||
String result = auth("adrive/v2/batch", json, true);
|
return res.getResponse().getStatus() == 404;
|
||||||
return result.length() == 211;
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] proxySub(Map<String, String> params) throws Exception {
|
public Object[] proxySub(Map<String, String> params) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.github.catvod.bean;
|
package com.github.catvod.bean;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
|
@ -54,6 +55,10 @@ public class Result {
|
||||||
return Result.get().classes(classes).vod(list).filters(filters).string();
|
return Result.get().classes(classes).vod(list).filters(filters).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String string(List<Class> classes, List<Vod> list, JsonElement filters) {
|
||||||
|
return Result.get().classes(classes).vod(list).filters(filters).string();
|
||||||
|
}
|
||||||
|
|
||||||
public static String string(List<Class> classes, LinkedHashMap<String, List<Filter>> filters) {
|
public static String string(List<Class> classes, LinkedHashMap<String, List<Filter>> filters) {
|
||||||
return Result.get().classes(classes).filters(filters).string();
|
return Result.get().classes(classes).filters(filters).string();
|
||||||
}
|
}
|
||||||
|
|
@ -105,6 +110,13 @@ public class Result {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result filters(JsonElement element) {
|
||||||
|
if (element == null) return this;
|
||||||
|
Type listType = new TypeToken<LinkedHashMap<String, List<Filter>>>() {}.getType();
|
||||||
|
this.filters = new Gson().fromJson(element.toString(), listType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Result header(Map<String, String> header) {
|
public Result header(Map<String, String> header) {
|
||||||
if (header.isEmpty()) return this;
|
if (header.isEmpty()) return this;
|
||||||
this.header = new Gson().toJson(header);
|
this.header = new Gson().toJson(header);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Download {
|
||||||
|
|
||||||
|
@SerializedName("url")
|
||||||
|
private String url;
|
||||||
|
@SerializedName("file_id")
|
||||||
|
private String fileId;
|
||||||
|
@SerializedName("expiration")
|
||||||
|
private String expiration;
|
||||||
|
|
||||||
|
public static Download objectFrom(String str) {
|
||||||
|
return new Gson().fromJson(str, Download.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return TextUtils.isEmpty(url) ? "" : url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileId() {
|
||||||
|
return TextUtils.isEmpty(fileId) ? "" : fileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpiration() {
|
||||||
|
return TextUtils.isEmpty(expiration) ? "" : expiration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.github.catvod.bean.Sub;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Preview {
|
||||||
|
|
||||||
|
@SerializedName("video_preview_play_info")
|
||||||
|
private Info videoPreviewPlayInfo;
|
||||||
|
@SerializedName("drive_id")
|
||||||
|
private String driveId;
|
||||||
|
@SerializedName("file_id")
|
||||||
|
private String fileId;
|
||||||
|
|
||||||
|
public static Preview objectFrom(String str) {
|
||||||
|
return new Gson().fromJson(str, Preview.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Info getVideoPreviewPlayInfo() {
|
||||||
|
return videoPreviewPlayInfo == null ? new Info() : videoPreviewPlayInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDriveId() {
|
||||||
|
return TextUtils.isEmpty(driveId) ? "" : driveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileId() {
|
||||||
|
return TextUtils.isEmpty(fileId) ? "" : fileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Info {
|
||||||
|
|
||||||
|
@SerializedName("live_transcoding_task_list")
|
||||||
|
private List<LiveTranscodingTask> liveTranscodingTaskList;
|
||||||
|
@SerializedName("live_transcoding_subtitle_task_list")
|
||||||
|
private List<LiveTranscodingTask> liveTranscodingSubtitleTaskList;
|
||||||
|
|
||||||
|
public List<LiveTranscodingTask> getLiveTranscodingTaskList() {
|
||||||
|
return liveTranscodingTaskList == null ? Collections.emptyList() : liveTranscodingTaskList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LiveTranscodingTask> getLiveTranscodingSubtitleTaskList() {
|
||||||
|
return liveTranscodingSubtitleTaskList == null ? Collections.emptyList() : liveTranscodingSubtitleTaskList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LiveTranscodingTask {
|
||||||
|
|
||||||
|
@SerializedName("template_id")
|
||||||
|
private String templateId;
|
||||||
|
@SerializedName("language")
|
||||||
|
private String language;
|
||||||
|
@SerializedName("status")
|
||||||
|
private String status;
|
||||||
|
@SerializedName("url")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public String getTemplateId() {
|
||||||
|
return TextUtils.isEmpty(templateId) ? "" : templateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return TextUtils.isEmpty(language) ? "" : language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return TextUtils.isEmpty(status) ? "" : status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return TextUtils.isEmpty(url) ? "" : url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sub getSub() {
|
||||||
|
return Sub.create().url(getUrl()).name(getLanguage()).lang(getLanguage()).ext("vtt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Res {
|
||||||
|
|
||||||
|
@SerializedName("responses")
|
||||||
|
private List<Res> responses;
|
||||||
|
@SerializedName("body")
|
||||||
|
private Body body;
|
||||||
|
@SerializedName("id")
|
||||||
|
private String id;
|
||||||
|
@SerializedName("status")
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
public static Res objectFrom(String str) {
|
||||||
|
return new Gson().fromJson(str, Res.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Res> getResponses() {
|
||||||
|
return responses == null ? Collections.emptyList() : responses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Res getResponse() {
|
||||||
|
return getResponses().isEmpty() ? new Res() : getResponses().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Body getBody() {
|
||||||
|
return body == null ? new Body() : body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return TextUtils.isEmpty(id) ? "" : id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Body {
|
||||||
|
|
||||||
|
@SerializedName("domain_id")
|
||||||
|
private String domainId;
|
||||||
|
@SerializedName("drive_id")
|
||||||
|
private String driveId;
|
||||||
|
@SerializedName("file_id")
|
||||||
|
private String fileId;
|
||||||
|
@SerializedName("code")
|
||||||
|
private String code;
|
||||||
|
@SerializedName("message")
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public String getDomainId() {
|
||||||
|
return TextUtils.isEmpty(domainId) ? "" : domainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDriveId() {
|
||||||
|
return TextUtils.isEmpty(driveId) ? "" : driveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileId() {
|
||||||
|
return TextUtils.isEmpty(fileId) ? "" : fileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return TextUtils.isEmpty(code) ? "" : code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return TextUtils.isEmpty(message) ? "" : message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Share {
|
||||||
|
|
||||||
|
@SerializedName("share_token")
|
||||||
|
private String shareToken;
|
||||||
|
@SerializedName("expire_time")
|
||||||
|
private String expireTime;
|
||||||
|
@SerializedName("expires_in")
|
||||||
|
private int expiresIn;
|
||||||
|
|
||||||
|
@SerializedName("creator_id")
|
||||||
|
private String creatorId;
|
||||||
|
@SerializedName("creator_name")
|
||||||
|
private String creatorName;
|
||||||
|
@SerializedName("creator_phone")
|
||||||
|
private String creatorPhone;
|
||||||
|
@SerializedName("expiration")
|
||||||
|
private String expiration;
|
||||||
|
@SerializedName("updated_at")
|
||||||
|
private String updatedAt;
|
||||||
|
@SerializedName("vip")
|
||||||
|
private String vip;
|
||||||
|
@SerializedName("avatar")
|
||||||
|
private String avatar;
|
||||||
|
@SerializedName("share_name")
|
||||||
|
private String shareName;
|
||||||
|
@SerializedName("display_name")
|
||||||
|
private String displayName;
|
||||||
|
@SerializedName("share_title")
|
||||||
|
private String shareTitle;
|
||||||
|
@SerializedName("has_pwd")
|
||||||
|
private boolean hasPwd;
|
||||||
|
@SerializedName("file_infos")
|
||||||
|
private List<Item> fileInfos;
|
||||||
|
|
||||||
|
public static Share objectFrom(String str) {
|
||||||
|
return new Gson().fromJson(str, Share.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShareToken() {
|
||||||
|
return TextUtils.isEmpty(shareToken) ? "" : shareToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpireTime() {
|
||||||
|
return TextUtils.isEmpty(expireTime) ? "" : expireTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getExpiresIn() {
|
||||||
|
return expiresIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatorId() {
|
||||||
|
return TextUtils.isEmpty(creatorId) ? "" : creatorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatorName() {
|
||||||
|
return TextUtils.isEmpty(creatorName) ? "" : creatorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatorPhone() {
|
||||||
|
return TextUtils.isEmpty(creatorPhone) ? "" : creatorPhone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpiration() {
|
||||||
|
return TextUtils.isEmpty(expiration) ? "" : expiration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpdatedAt() {
|
||||||
|
return TextUtils.isEmpty(updatedAt) ? "" : updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVip() {
|
||||||
|
return TextUtils.isEmpty(vip) ? "" : vip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvatar() {
|
||||||
|
return TextUtils.isEmpty(avatar) ? "" : avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShareName() {
|
||||||
|
return TextUtils.isEmpty(shareName) ? "" : shareName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return TextUtils.isEmpty(displayName) ? "" : displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShareTitle() {
|
||||||
|
return TextUtils.isEmpty(shareTitle) ? "" : shareTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasPwd() {
|
||||||
|
return hasPwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Item> getFileInfos() {
|
||||||
|
return fileInfos == null ? Collections.emptyList() : fileInfos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.github.catvod.api.AliYun;
|
import com.github.catvod.api.AliYun;
|
||||||
import android.text.TextUtils;
|
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
@ -25,13 +30,9 @@ public class Ali extends Spider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String detailContent(List<String> ids) throws Exception {
|
public String detailContent(List<String> ids) throws Exception {
|
||||||
String url = ids.get(0).trim();
|
String id = ids.get(0).trim();
|
||||||
Matcher matcher = pattern.matcher(url);
|
Matcher matcher = pattern.matcher(id);
|
||||||
if (!matcher.find()) return "";
|
return matcher.find() ? Result.string(parseVod(matcher, id)) : "";
|
||||||
String shareId = matcher.group(1);
|
|
||||||
String fileId = matcher.groupCount() == 3 ? matcher.group(3) : "";
|
|
||||||
AliYun.get().setShareId(shareId);
|
|
||||||
return Result.string(AliYun.get().getVod(url, fileId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -39,45 +40,45 @@ public class Ali extends Spider {
|
||||||
AliYun.get().setShareId(id.split("@")[0]);
|
AliYun.get().setShareId(id.split("@")[0]);
|
||||||
return AliYun.get().playerContent(id.split("@")[1].split("\\+"), flag.split("#")[0].equals("原畫"));
|
return AliYun.get().playerContent(id.split("@")[1].split("\\+"), flag.split("#")[0].equals("原畫"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private Vod parseVod(Matcher matcher, String id) {
|
||||||
* 获取详情内容视频播放地址(多 share_link 模式)
|
String shareId = matcher.group(1);
|
||||||
*
|
String fileId = matcher.groupCount() == 3 ? matcher.group(3) : "";
|
||||||
* @param ids share_link 集合
|
AliYun.get().setShareId(shareId);
|
||||||
* @return 详情内容视频播放地址
|
return AliYun.get().getVod(id, fileId);
|
||||||
*/
|
|
||||||
public String detailContentVodPlayUrl(List<String> ids) throws Exception {
|
|
||||||
List<String> playUrl = new ArrayList<>();
|
|
||||||
for (String id : ids) {
|
|
||||||
Matcher matcher = pattern.matcher(id);
|
|
||||||
if (matcher.find()) {
|
|
||||||
String shareId = matcher.group(1);
|
|
||||||
String fileId = matcher.groupCount() == 3 ? matcher.group(3) : "";
|
|
||||||
AliYun.get().setShareId(shareId);
|
|
||||||
playUrl.add(AliYun.get().getVod(id, fileId).getVodPlayUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TextUtils.join("$$$", playUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取详情内容视频播放来源(多 shared_link 模式)
|
* 獲取詳情內容視頻播放來源(多 shared_link)
|
||||||
*
|
*
|
||||||
* @param ids share_link 集合
|
* @param ids share_link 集合
|
||||||
* @return 详情内容视频播放来源
|
* @return 詳情內容視頻播放來源
|
||||||
*/
|
*/
|
||||||
public String detailContentVodPlayFrom(List<String> ids) {
|
public String detailContentVodPlayFrom(List<String> ids) {
|
||||||
List<String> playFrom = new ArrayList<>();
|
List<String> playFrom = new ArrayList<>();
|
||||||
if (ids.size() > 1) {
|
if (ids.size() < 1) return TextUtils.join("$$$", Arrays.asList("原畫", "普畫"));
|
||||||
for (int i = 1; i <= ids.size(); i++) {
|
for (int i = 1; i <= ids.size(); i++) {
|
||||||
playFrom.addAll(Arrays.asList(String.format(Locale.CHINA, "原畫#%02d", i), String.format(Locale.CHINA, "普畫#%02d", i)));
|
playFrom.add(String.format(Locale.getDefault(), "原畫#%02d", i));
|
||||||
}
|
playFrom.add(String.format(Locale.getDefault(), "普畫#%02d", i));
|
||||||
} else {
|
|
||||||
playFrom.addAll(Arrays.asList("原畫", "普畫"));
|
|
||||||
}
|
}
|
||||||
return TextUtils.join("$$$", playFrom);
|
return TextUtils.join("$$$", playFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 獲取詳情內容視頻播放地址(多 share_link)
|
||||||
|
*
|
||||||
|
* @param ids share_link 集合
|
||||||
|
* @return 詳情內容視頻播放地址
|
||||||
|
*/
|
||||||
|
public String detailContentVodPlayUrl(List<String> ids) {
|
||||||
|
List<String> playUrl = new ArrayList<>();
|
||||||
|
for (String id : ids) {
|
||||||
|
Matcher matcher = pattern.matcher(id);
|
||||||
|
if (matcher.find()) playUrl.add(parseVod(matcher, id).getVodPlayUrl());
|
||||||
|
}
|
||||||
|
return TextUtils.join("$$$", playUrl);
|
||||||
|
}
|
||||||
|
|
||||||
public static Object[] proxy(Map<String, String> params) throws Exception {
|
public static Object[] proxy(Map<String, String> params) throws Exception {
|
||||||
String type = params.get("type");
|
String type = params.get("type");
|
||||||
if ("sub".equals(type)) return AliYun.get().proxySub(params);
|
if ("sub".equals(type)) return AliYun.get().proxySub(params);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue