mirror of
https://github.com/bizhangjie/CatVodSpider.git
synced 2025-10-25 17:12:17 +00:00
'更新可用状态'
This commit is contained in:
@@ -50,4 +50,5 @@ dependencies {
|
||||
implementation 'com.google.zxing:core:3.3.0'
|
||||
implementation 'com.orhanobut:logger:2.2.0'
|
||||
implementation 'org.jsoup:jsoup:1.15.3'
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.68'
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class MainActivity extends Activity {
|
||||
private void initSpider() {
|
||||
try {
|
||||
Init.init(getApplicationContext());
|
||||
spider = new CaoLiu();
|
||||
spider = new Cg51();
|
||||
spider.init(this, "");
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -5,9 +5,8 @@ import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.bean.Vod;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.utils.Json;
|
||||
import com.github.catvod.utils.CgImageUtil;
|
||||
import com.github.catvod.utils.Util;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
@@ -18,6 +17,11 @@ import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -36,28 +40,69 @@ public class Cg51 extends Spider {
|
||||
return headers;
|
||||
}
|
||||
|
||||
// private List<Vod> parseVods(Document doc) {
|
||||
// List<Vod> list = new ArrayList<>();
|
||||
// for (Element element : doc.select("article")) {
|
||||
// String pic = String.valueOf(element.select("script"));
|
||||
// String pattern = "'(https?://[^']+)";
|
||||
// Pattern regex = Pattern.compile(pattern);
|
||||
// Matcher matcher = regex.matcher(pic);
|
||||
// String PicAddress = "";
|
||||
// if (matcher.find()) {
|
||||
// PicAddress = CgImageUtil.loadBackgroundImage(matcher.group(1));
|
||||
// } else {
|
||||
// }
|
||||
// String url = element.select("a").attr("href");
|
||||
// String name = element.select(".post-card-title").text();
|
||||
// String id = url.split("/")[2];
|
||||
// if (name != "" && url != ""){
|
||||
// list.add(new Vod(id, name, PicAddress));
|
||||
// }
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
|
||||
private List<Vod> parseVods(Document doc) {
|
||||
List<Vod> list = new ArrayList<>();
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(20); // 创建一个线程池,最大并发数为10
|
||||
|
||||
List<Callable<String>> tasks = new ArrayList<>(); // 用于存储所有的任务
|
||||
|
||||
for (Element element : doc.select("article")) {
|
||||
String pic = String.valueOf(element.select("script"));
|
||||
String pattern = "'(https?://[^']+)";
|
||||
Pattern regex = Pattern.compile(pattern);
|
||||
Matcher matcher = regex.matcher(pic);
|
||||
String PicAddress = "";
|
||||
|
||||
if (matcher.find()) {
|
||||
PicAddress = proxyImgUrl + matcher.group(1);
|
||||
} else {
|
||||
String imageUrl = matcher.group(1);
|
||||
tasks.add(() -> CgImageUtil.loadBackgroundImage(imageUrl)); // 创建一个任务,并将其添加到任务列表中
|
||||
}
|
||||
|
||||
String url = element.select("a").attr("href");
|
||||
String name = element.select(".post-card-title").text();
|
||||
String id = url.split("/")[2];
|
||||
if (name != "" && url != ""){
|
||||
if (!name.isEmpty() && !url.isEmpty()) {
|
||||
list.add(new Vod(id, name, PicAddress));
|
||||
}
|
||||
}
|
||||
try {
|
||||
// 执行所有的任务,并获取结果
|
||||
List<Future<String>> futures = executorService.invokeAll(tasks);
|
||||
|
||||
// 遍历任务结果,并将结果设置到对应的Vod对象中
|
||||
for (int i = 0; i < futures.size(); i++) {
|
||||
Vod vod = list.get(i);
|
||||
String result = futures.get(i).get();
|
||||
vod.setVodPic(result);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executorService.shutdown(); // 关闭线程池
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String homeContent(boolean filter) throws Exception {
|
||||
List<Class> classes = new ArrayList<>();
|
||||
|
||||
91
app/src/main/java/com/github/catvod/utils/CgImageUtil.java
Normal file
91
app/src/main/java/com/github/catvod/utils/CgImageUtil.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package com.github.catvod.utils;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.IOException;
|
||||
import java.security.Security;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
|
||||
public class CgImageUtil {
|
||||
private static final String IV = "97b60394abc2fbe1";
|
||||
private static final String KEY = "f5d965df75336270";
|
||||
|
||||
private static String aesDecrypt(String word) {
|
||||
try {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
byte[] srcBytes = Base64.decode(word, Base64.DEFAULT);
|
||||
byte[] keyBytes = KEY.getBytes("UTF-8");
|
||||
byte[] ivBytes = IV.getBytes("UTF-8");
|
||||
|
||||
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(ivBytes));
|
||||
|
||||
byte[] decryptedBytes = cipher.doFinal(srcBytes);
|
||||
return Base64.encodeToString(decryptedBytes,Base64.DEFAULT);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// String bgUrl = "https://pic.jcezlxm.cn/upload/upload/20240311/2024031120484810172.jpg";
|
||||
// String decryptedImage = loadBackgroundImage(bgUrl);
|
||||
// System.out.println(decryptedImage);
|
||||
// }
|
||||
|
||||
public static String loadBackgroundImage(String bgUrl) {
|
||||
if (isCdnImg(bgUrl)) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(bgUrl)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
ResponseBody body = response.body();
|
||||
if (body != null) {
|
||||
byte[] imageBytes = body.bytes();
|
||||
String base64Str = Base64.encodeToString(imageBytes,Base64.DEFAULT);
|
||||
System.out.println(base64Str);
|
||||
String decryptedStr = aesDecrypt(base64Str);
|
||||
|
||||
// 将解密后的数据拼接为Data URL
|
||||
String[] ary = bgUrl.split("\\.");
|
||||
String base64st = "data:image/" + ary[ary.length - 1] + ";base64," + decryptedStr;
|
||||
return base64st;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
String base64st = "url(\"" + bgUrl + "\")";
|
||||
return base64st;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isCdnImg(String path) {
|
||||
if (path == null || path.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (path.contains("/xiao/")) {
|
||||
return true;
|
||||
}
|
||||
if (path.contains("/upload/upload/")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
a1efde84a6c7ee3ae6c51c3d87fe629e
|
||||
d71d23f640f5e39facbd698a2a692ad8
|
||||
|
||||
Reference in New Issue
Block a user