Update ali : remove cache

This commit is contained in:
FongMi 2023-03-25 09:34:30 +08:00
parent a8601a0855
commit 865f4c0fee
3 changed files with 27 additions and 26 deletions

View File

@ -21,7 +21,6 @@ import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.spider.Init; import com.github.catvod.spider.Init;
import com.github.catvod.spider.Proxy; import com.github.catvod.spider.Proxy;
import com.github.catvod.utils.Prefers;
import com.github.catvod.utils.QRCode; import com.github.catvod.utils.QRCode;
import com.github.catvod.utils.Trans; import com.github.catvod.utils.Trans;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Utils;
@ -30,15 +29,12 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -61,7 +57,7 @@ public class API {
} }
private API() { private API() {
auth = Auth.objectFrom(Prefers.getString("aliyundrive")); auth = new Auth();
quality = new HashMap<>(); quality = new HashMap<>();
quality.put("4K", "UHD"); quality.put("4K", "UHD");
quality.put("2k", "QHD"); quality.put("2k", "QHD");
@ -72,15 +68,7 @@ public class API {
} }
public void setRefreshToken(String token) { public void setRefreshToken(String token) {
try { auth.setRefreshToken(token);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault());
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
long expireTime = sdf.parse(auth.getExpireTime()).getTime();
boolean expired = expireTime < System.currentTimeMillis();
if (expired) auth.setRefreshToken(token);
} catch (Exception e) {
auth.setRefreshToken(token);
}
} }
public void setShareId(String shareId) { public void setShareId(String shareId) {
@ -145,6 +133,12 @@ public class API {
return false; return false;
} }
private boolean checkManyRequest(String result) {
if (!result.contains("Too Many Requests")) return false;
Init.show("洗洗睡吧Too Many Requests。");
return true;
}
public void checkAccessToken() { public void checkAccessToken() {
if (auth.getAccessToken().isEmpty()) refreshAccessToken(); if (auth.getAccessToken().isEmpty()) refreshAccessToken();
} }
@ -186,14 +180,20 @@ public class API {
oauthRedirect(object.getString("redirectUri").split("code=")[1]); oauthRedirect(object.getString("redirectUri").split("code=")[1]);
} }
private void oauthRedirect(String code) throws Exception { private void oauthRedirect(String code) {
SpiderDebug.log("OAuth Redirect..."); try {
JSONObject body = new JSONObject(); SpiderDebug.log("OAuth Redirect...");
body.put("code", code); JSONObject body = new JSONObject();
body.put("grant_type", "authorization_code"); body.put("code", code);
JSONObject object = new JSONObject(post("https://api.nn.ci/alist/ali_open/code", body)); body.put("grant_type", "authorization_code");
Log.e("DDD", object.toString()); String result = post("https://api.nn.ci/alist/ali_open/code", body);
auth.setRefreshTokenOpen(object.getString("refresh_token")); Log.e("DDD", result);
if (checkManyRequest(result)) return;
JSONObject object = new JSONObject(result);
auth.setRefreshTokenOpen(object.getString("refresh_token"));
} catch (Exception e) {
SpiderDebug.log(e);
}
} }
private boolean refreshOpenToken() { private boolean refreshOpenToken() {
@ -202,11 +202,12 @@ public class API {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("grant_type", "refresh_token"); body.put("grant_type", "refresh_token");
body.put("refresh_token", auth.getRefreshTokenOpen()); body.put("refresh_token", auth.getRefreshTokenOpen());
JSONObject object = new JSONObject(post("https://api.nn.ci/alist/ali_open/token", body)); String result = post("https://api.nn.ci/alist/ali_open/token", body);
Log.e("DDD", object.toString()); Log.e("DDD", result);
if (checkManyRequest(result)) return false;
JSONObject object = new JSONObject(result);
auth.setRefreshTokenOpen(object.optString("refresh_token")); auth.setRefreshTokenOpen(object.optString("refresh_token"));
auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token")); auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token"));
auth.save();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
SpiderDebug.log(e); SpiderDebug.log(e);

Binary file not shown.

View File

@ -1 +1 @@
255c5dca97c64efb39b5fbe7d748cc0b 4777a559fab527837e373a6a1a59b3a1