Merge branch 'main' of https://github.com/FongMi/CatVodSpider
This commit is contained in:
commit
107fd3e511
|
|
@ -90,7 +90,7 @@ public class API {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> getHeaderAuthOpen() {
|
private HashMap<String, String> getHeaderOpen() {
|
||||||
HashMap<String, String> headers = getHeader();
|
HashMap<String, String> headers = getHeader();
|
||||||
headers.put("authorization", auth.getAccessTokenOpen());
|
headers.put("authorization", auth.getAccessTokenOpen());
|
||||||
return headers;
|
return headers;
|
||||||
|
|
@ -113,15 +113,13 @@ public class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String auth(String url, String json, boolean retry) {
|
private String auth(String url, String json, boolean retry) {
|
||||||
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
return auth(url, json, getHeaderAuth(), retry);
|
||||||
String result = OkHttp.postJson(url, json, getHeaderAuth());
|
|
||||||
if (retry && check401(result)) return auth(url, json, false);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String authOpen(String url, String json, boolean retry) {
|
private String auth(String url, String json, Map<String, String> header, boolean retry) {
|
||||||
String result = OkHttp.postJson(url, json, getHeaderAuthOpen());
|
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
||||||
if (retry && check401Open(result)) return authOpen(url, json, false);
|
String result = OkHttp.postJson(url, json, header);
|
||||||
|
if (retry && check401(result)) return auth(url, json, header, false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,11 +137,6 @@ public class API {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean check401Open(String result) {
|
|
||||||
if (result.contains("AccessTokenInvalid")) return refreshAccessTokenOpen();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAccessToken() {
|
public void checkAccessToken() {
|
||||||
if (auth.getAccessToken().isEmpty()) refreshAccessToken();
|
if (auth.getAccessToken().isEmpty()) refreshAccessToken();
|
||||||
}
|
}
|
||||||
|
|
@ -178,9 +171,10 @@ public class API {
|
||||||
body.put("grant_type", "authorization_code");
|
body.put("grant_type", "authorization_code");
|
||||||
object = new JSONObject(post("https://api.nn.ci/alist/ali_open/code", body));
|
object = new JSONObject(post("https://api.nn.ci/alist/ali_open/code", body));
|
||||||
auth.setRefreshTokenOpen(object.getString("refresh_token"));
|
auth.setRefreshTokenOpen(object.getString("refresh_token"));
|
||||||
refreshAccessTokenOpen();
|
refreshOpenToken();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
SpiderDebug.log(e);
|
||||||
stopService();
|
stopService();
|
||||||
auth.clean();
|
auth.clean();
|
||||||
getQRCode();
|
getQRCode();
|
||||||
|
|
@ -190,22 +184,16 @@ public class API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean refreshAccessTokenOpen() {
|
private void refreshOpenToken() throws Exception {
|
||||||
try {
|
SpiderDebug.log("refreshAccessTokenOpen...");
|
||||||
SpiderDebug.log("refreshAccessTokenOpen...");
|
JSONObject body = new JSONObject();
|
||||||
JSONObject body = new JSONObject();
|
String token = auth.getRefreshTokenOpen();
|
||||||
String token = auth.getRefreshTokenOpen();
|
body.put("refresh_token", token);
|
||||||
body.put("refresh_token", token);
|
body.put("grant_type", "refresh_token");
|
||||||
body.put("grant_type", "refresh_token");
|
JSONObject object = new JSONObject(OkHttp.postJson("https://api.nn.ci/alist/ali_open/token", body.toString(), getHeader()));
|
||||||
JSONObject object = new JSONObject(OkHttp.postJson("https://api.nn.ci/alist/ali_open/token", body.toString(), getHeader()));
|
auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token"));
|
||||||
auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token"));
|
auth.setRefreshTokenOpen(object.optString("refresh_token"));
|
||||||
auth.setRefreshTokenOpen(object.optString("refresh_token"));
|
auth.save();
|
||||||
auth.save();
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
refreshAccessToken();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refreshShareToken() {
|
public boolean refreshShareToken() {
|
||||||
|
|
@ -243,6 +231,7 @@ public class API {
|
||||||
auth.save();
|
auth.save();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
SpiderDebug.log(e);
|
||||||
auth.setSignature("");
|
auth.setSignature("");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -362,7 +351,7 @@ public class API {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("file_id", fileId);
|
body.put("file_id", fileId);
|
||||||
body.put("drive_id", auth.getDriveId());
|
body.put("drive_id", auth.getDriveId());
|
||||||
String url = new JSONObject(authOpen("https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl", body.toString(), true)).optString("url");
|
String url = new JSONObject(auth("https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl", body.toString(), getHeaderOpen(), true)).optString("url");
|
||||||
Init.execute(() -> delete(fileId));
|
Init.execute(() -> delete(fileId));
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,10 @@ public class Ali extends Spider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) {
|
public String playerContent(String flag, String id, List<String> vipFlags) {
|
||||||
String[] ids = id.split("\\+");
|
|
||||||
API.get().checkAccessToken();
|
API.get().checkAccessToken();
|
||||||
if (flag.equals("原畫")) {
|
String[] ids = id.split("\\+");
|
||||||
return Result.get().url(API.get().getDownloadUrl(ids[0])).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string();
|
String url = flag.equals("原畫") ? API.get().getDownloadUrl(ids[0]) : API.get().getPreviewUrl(ids[0], flag);
|
||||||
} else {
|
return Result.get().url(url).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string();
|
||||||
return Result.get().url(API.get().getPreviewUrl(ids[0], flag)).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object[] vod(Map<String, String> params) {
|
public static Object[] vod(Map<String, String> params) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.os.SystemClock;
|
import android.util.Base64;
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.webkit.WebViewClient;
|
|
||||||
|
|
||||||
import com.github.catvod.bean.Class;
|
import com.github.catvod.bean.Class;
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
|
|
@ -15,6 +13,7 @@ import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -60,35 +59,26 @@ public class Doll extends Spider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String detailContent(List<String> ids) throws Exception {
|
public String detailContent(List<String> ids) throws Exception {
|
||||||
Document doc = Jsoup.parse(OkHttp.string(url + ids.get(0)));
|
String html = OkHttp.string(url + ids.get(0));
|
||||||
String name = doc.select("meta[property=og:title]").attr("content");
|
Document doc = Jsoup.parse(html);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String videoId = ids.get(0).split("/")[1].split("\\.")[0];
|
||||||
String pic = doc.select("meta[property=og:image]").attr("content");
|
String pic = doc.select("meta[property=og:image]").attr("content");
|
||||||
|
String name = doc.select("meta[property=og:title]").attr("content");
|
||||||
|
String voteTag = new String(Base64.decode(Utils.getVar(html, "voteTag").getBytes(), 0));
|
||||||
|
for (int i = 0; i < voteTag.length(); i++) sb.append(Character.toChars(voteTag.charAt(i) ^ videoId.charAt(i % videoId.length())));
|
||||||
|
String playUrl = URLDecoder.decode(new String(Base64.decode(sb.toString().getBytes(), 0)));
|
||||||
Vod vod = new Vod();
|
Vod vod = new Vod();
|
||||||
vod.setVodId(ids.get(0));
|
vod.setVodId(ids.get(0));
|
||||||
vod.setVodPic(pic);
|
vod.setVodPic(pic);
|
||||||
vod.setVodName(name);
|
vod.setVodName(name);
|
||||||
vod.setVodPlayFrom("玩偶姐姐");
|
vod.setVodPlayFrom("玩偶姐姐");
|
||||||
vod.setVodPlayUrl("播放$" + ids.get(0));
|
vod.setVodPlayUrl("播放$" + playUrl);
|
||||||
return Result.string(vod);
|
return Result.string(vod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
||||||
HashMap<String, String> result = new HashMap<>();
|
return Result.get().url(id).string();
|
||||||
Utils.loadWebView(url + id, getClient(result));
|
|
||||||
while (result.isEmpty()) SystemClock.sleep(10);
|
|
||||||
return Result.get().url(result.get("url")).string();
|
|
||||||
}
|
|
||||||
|
|
||||||
private WebViewClient getClient(HashMap<String, String> result) {
|
|
||||||
return new WebViewClient() {
|
|
||||||
@Override
|
|
||||||
public void onLoadResource(WebView view, String url) {
|
|
||||||
if (url.endsWith(".m3u8")) {
|
|
||||||
result.put("url", url);
|
|
||||||
view.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,13 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVar(String data, String param) {
|
public static String getVar(String data, String param) {
|
||||||
for (String var : data.split("var")) if (var.contains(param)) return var.split("'")[1];
|
for (String var : data.split("var")) if (var.contains(param)) return checkVar(var);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String checkVar(String var) {
|
||||||
|
if (var.contains("'")) return var.split("'")[1];
|
||||||
|
if (var.contains("\"")) return var.split("\"")[1];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue