fix ali
This commit is contained in:
parent
624c5c0a8e
commit
a430fd6a90
|
|
@ -17,11 +17,7 @@ import com.github.catvod.BuildConfig;
|
||||||
import com.github.catvod.bean.Result;
|
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.*;
|
||||||
import com.github.catvod.bean.ali.Data;
|
|
||||||
import com.github.catvod.bean.ali.Item;
|
|
||||||
import com.github.catvod.bean.ali.OAuth;
|
|
||||||
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;
|
||||||
import com.github.catvod.net.OkResult;
|
import com.github.catvod.net.OkResult;
|
||||||
|
|
@ -58,8 +54,10 @@ public class API {
|
||||||
private String refreshToken;
|
private String refreshToken;
|
||||||
private String shareToken;
|
private String shareToken;
|
||||||
private String shareId;
|
private String shareId;
|
||||||
|
private String driveId;
|
||||||
private OAuth oauth;
|
private OAuth oauth;
|
||||||
private User user;
|
private User user;
|
||||||
|
private Drive drive;
|
||||||
|
|
||||||
private static class Loader {
|
private static class Loader {
|
||||||
static volatile API INSTANCE = new API();
|
static volatile API INSTANCE = new API();
|
||||||
|
|
@ -77,10 +75,15 @@ public class API {
|
||||||
return FileUtil.getCacheFile("aliyundrive_oauth");
|
return FileUtil.getCacheFile("aliyundrive_oauth");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getDriveCache() {
|
||||||
|
return FileUtil.getCacheFile("aliyundrive_drive");
|
||||||
|
}
|
||||||
|
|
||||||
private API() {
|
private API() {
|
||||||
tempIds = new ArrayList<>();
|
tempIds = new ArrayList<>();
|
||||||
oauth = OAuth.objectFrom(FileUtil.read(getOAuthCache()));
|
oauth = OAuth.objectFrom(FileUtil.read(getOAuthCache()));
|
||||||
user = User.objectFrom(FileUtil.read(getUserCache()));
|
user = User.objectFrom(FileUtil.read(getUserCache()));
|
||||||
|
drive = Drive.objectFrom(FileUtil.read(getUserCache()));
|
||||||
quality = new HashMap<>();
|
quality = new HashMap<>();
|
||||||
quality.put("4K", "UHD");
|
quality.put("4K", "UHD");
|
||||||
quality.put("2k", "QHD");
|
quality.put("2k", "QHD");
|
||||||
|
|
@ -105,6 +108,7 @@ public class API {
|
||||||
public void setShareId(String shareId) {
|
public void setShareId(String shareId) {
|
||||||
if (!getOAuthCache().exists()) oauth.clean().save();
|
if (!getOAuthCache().exists()) oauth.clean().save();
|
||||||
if (!getUserCache().exists()) user.clean().save();
|
if (!getUserCache().exists()) user.clean().save();
|
||||||
|
if (!getDriveCache().exists()) drive.clean().save();
|
||||||
this.shareId = shareId;
|
this.shareId = shareId;
|
||||||
refreshShareToken();
|
refreshShareToken();
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +157,8 @@ public class API {
|
||||||
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, json, getHeaderAuth());
|
OkResult result = OkHttp.postJson(url, json, getHeaderAuth());
|
||||||
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
||||||
if (retry && (result.getCode() == 400 || result.getCode() == 401) && refreshAccessToken()) return auth(url, json, false);
|
if (retry && (result.getCode() == 400 || result.getCode() == 401) && refreshAccessToken())
|
||||||
|
return auth(url, json, false);
|
||||||
if (retry && result.getCode() == 429) return auth(url, json, false);
|
if (retry && result.getCode() == 429) return auth(url, json, false);
|
||||||
return result.getBody();
|
return result.getBody();
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +167,8 @@ public class API {
|
||||||
url = url.startsWith("https") ? url : "https://open.aliyundrive.com/adrive/v1.0/" + url;
|
url = url.startsWith("https") ? url : "https://open.aliyundrive.com/adrive/v1.0/" + url;
|
||||||
OkResult result = OkHttp.postJson(url, json, getHeaderOpen());
|
OkResult result = OkHttp.postJson(url, json, getHeaderOpen());
|
||||||
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
||||||
if (retry && (result.getCode() == 400 || result.getCode() == 401) && refreshOpenToken()) return oauth(url, json, false);
|
if (retry && (result.getCode() == 400 || result.getCode() == 401) && refreshOpenToken())
|
||||||
|
return oauth(url, json, false);
|
||||||
return result.getBody();
|
return result.getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,6 +223,20 @@ public class API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean getDriveId() {
|
||||||
|
try {
|
||||||
|
SpiderDebug.log("Obtain drive id...");
|
||||||
|
String result = auth("https://user.aliyundrive.com/v2/user/get", "{}", false);
|
||||||
|
drive = Drive.objectFrom(result).save();
|
||||||
|
driveId = drive.getResourceDriveId().isEmpty() ? drive.getDriveId() : drive.getResourceDriveId();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
drive.clean().save();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean oauthRequest() {
|
private boolean oauthRequest() {
|
||||||
try {
|
try {
|
||||||
SpiderDebug.log("OAuth Request...");
|
SpiderDebug.log("OAuth Request...");
|
||||||
|
|
@ -272,7 +292,8 @@ public class API {
|
||||||
List<String> playFrom = Arrays.asList("原畫", "超清", "高清");
|
List<String> playFrom = Arrays.asList("原畫", "超清", "高清");
|
||||||
List<String> episode = new ArrayList<>();
|
List<String> episode = new ArrayList<>();
|
||||||
List<String> playUrl = new ArrayList<>();
|
List<String> playUrl = new ArrayList<>();
|
||||||
for (Item file : files) episode.add(file.getDisplayName() + "$" + file.getFileId() + findSubs(file.getName(), subs));
|
for (Item file : files)
|
||||||
|
episode.add(file.getDisplayName() + "$" + file.getFileId() + findSubs(file.getName(), subs));
|
||||||
for (int i = 0; i < playFrom.size(); i++) playUrl.add(TextUtils.join("#", episode));
|
for (int i = 0; i < playFrom.size(); i++) playUrl.add(TextUtils.join("#", episode));
|
||||||
Vod vod = new Vod();
|
Vod vod = new Vod();
|
||||||
vod.setVodId(url);
|
vod.setVodId(url);
|
||||||
|
|
@ -338,7 +359,8 @@ public class API {
|
||||||
pair(Utils.removeExt(name1).toLowerCase(), items, subs);
|
pair(Utils.removeExt(name1).toLowerCase(), items, subs);
|
||||||
if (subs.isEmpty()) subs.addAll(items);
|
if (subs.isEmpty()) subs.addAll(items);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Item sub : subs) sb.append("+").append(Utils.removeExt(sub.getName())).append("@@@").append(sub.getExt()).append("@@@").append(sub.getFileId());
|
for (Item sub : subs)
|
||||||
|
sb.append("+").append(Utils.removeExt(sub.getName())).append("@@@").append(sub.getExt()).append("@@@").append(sub.getFileId());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,10 +380,11 @@ public class API {
|
||||||
public String getDownloadUrl(String fileId) {
|
public String getDownloadUrl(String fileId) {
|
||||||
try {
|
try {
|
||||||
SpiderDebug.log("getDownloadUrl..." + fileId);
|
SpiderDebug.log("getDownloadUrl..." + fileId);
|
||||||
|
if (!getDriveId()) throw new Exception("unable obtain drive id");
|
||||||
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));
|
||||||
body.put("drive_id", user.getDriveId());
|
body.put("drive_id", driveId);
|
||||||
String json = oauth("openFile/getDownloadUrl", body.toString(), true);
|
String json = oauth("openFile/getDownloadUrl", body.toString(), true);
|
||||||
return new JSONObject(json).getString("url");
|
return new JSONObject(json).getString("url");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -375,10 +398,11 @@ public class API {
|
||||||
public JSONObject getVideoPreviewPlayInfo(String fileId) {
|
public JSONObject getVideoPreviewPlayInfo(String fileId) {
|
||||||
try {
|
try {
|
||||||
SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId);
|
SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId);
|
||||||
|
if (!getDriveId()) throw new Exception("unable obtain drive id");
|
||||||
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));
|
||||||
body.put("drive_id", user.getDriveId());
|
body.put("drive_id", driveId);
|
||||||
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);
|
||||||
|
|
@ -436,7 +460,7 @@ public class API {
|
||||||
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\"}";
|
||||||
json = String.format(json, fileId, shareId, user.getDriveId());
|
json = String.format(json, fileId, shareId, driveId);
|
||||||
String result = auth("adrive/v2/batch", json, true);
|
String result = auth("adrive/v2/batch", json, true);
|
||||||
if (result.contains("ForbiddenNoPermission.File")) return copy(fileId);
|
if (result.contains("ForbiddenNoPermission.File")) return copy(fileId);
|
||||||
return new JSONObject(result).getJSONArray("responses").getJSONObject(0).getJSONObject("body").getString("file_id");
|
return new JSONObject(result).getJSONArray("responses").getJSONObject(0).getJSONObject("body").getString("file_id");
|
||||||
|
|
@ -454,7 +478,7 @@ public class API {
|
||||||
try {
|
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, user.getDriveId(), fileId, fileId);
|
json = String.format(json, driveId, fileId, fileId);
|
||||||
String result = auth("adrive/v2/batch", json, true);
|
String result = auth("adrive/v2/batch", json, true);
|
||||||
return result.length() == 211;
|
return result.length() == 211;
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.github.catvod.ali.API;
|
||||||
|
import com.github.catvod.utils.FileUtil;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Drive {
|
||||||
|
|
||||||
|
@SerializedName("default_drive_id")
|
||||||
|
private String driveId;
|
||||||
|
@SerializedName("user_id")
|
||||||
|
private String userId;
|
||||||
|
@SerializedName("backup_drive_id")
|
||||||
|
private String backupDriveId;
|
||||||
|
@SerializedName("resource_drive_id")
|
||||||
|
private String resourceDriveId;
|
||||||
|
@SerializedName("sbox_drive_id")
|
||||||
|
private String sboxDriveId;
|
||||||
|
|
||||||
|
public static Drive objectFrom(String str) {
|
||||||
|
Drive item = new Gson().fromJson(str, Drive.class);
|
||||||
|
return item == null ? new Drive() : item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDriveId() {
|
||||||
|
return TextUtils.isEmpty(driveId) ? "" : driveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return TextUtils.isEmpty(userId) ? "" : userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBackupDriveId() {
|
||||||
|
return TextUtils.isEmpty(backupDriveId) ? "" : backupDriveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResourceDriveId() {
|
||||||
|
return TextUtils.isEmpty(resourceDriveId) ? "" : resourceDriveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSboxDriveId() {
|
||||||
|
return TextUtils.isEmpty(sboxDriveId) ? "" : sboxDriveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Drive clean() {
|
||||||
|
this.driveId = "";
|
||||||
|
this.resourceDriveId = "";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drive save() {
|
||||||
|
FileUtil.write(API.get().getDriveCache(), toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new Gson().toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,7 +48,9 @@ public class User {
|
||||||
public void setRefreshToken(String refreshToken) {
|
public void setRefreshToken(String refreshToken) {
|
||||||
this.refreshToken = refreshToken;
|
this.refreshToken = refreshToken;
|
||||||
}
|
}
|
||||||
|
public void setDriveId(String driveId) {
|
||||||
|
this.driveId = driveId;
|
||||||
|
}
|
||||||
public String getAuthorization() {
|
public String getAuthorization() {
|
||||||
return getTokenType() + " " + getAccessToken();
|
return getTokenType() + " " + getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue