Merge pull request #1 from FongMi/main

跟随很开心
This commit is contained in:
owen10086 2022-09-22 23:08:46 +08:00 committed by GitHub
commit 274448b792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 15 deletions

View File

@ -4,12 +4,12 @@ plugins {
} }
android { android {
compileSdk 32 compileSdk 33
defaultConfig { defaultConfig {
applicationId "com.github.catvod.demo" applicationId "com.github.catvod.demo"
minSdk 21 minSdk 21
targetSdk 32 targetSdk 33
} }
buildTypes { buildTypes {

View File

@ -26,6 +26,8 @@ public class Result {
private String header; private String header;
@SerializedName("url") @SerializedName("url")
private String url; private String url;
@SerializedName("sub")
private String sub;
@SerializedName("parse") @SerializedName("parse")
private int parse; private int parse;
@SerializedName("jx") @SerializedName("jx")
@ -111,6 +113,11 @@ public class Result {
return this; return this;
} }
public Result sub(String sub) {
this.sub = sub;
return this;
}
public List<Vod> getList() { public List<Vod> getList() {
return list == null ? Collections.emptyList() : list; return list == null ? Collections.emptyList() : list;
} }

View File

@ -24,7 +24,7 @@ public class OkHttpUtil {
public static OkHttpClient defaultClient() { public static OkHttpClient defaultClient() {
synchronized (lockO) { synchronized (lockO) {
if (defaultClient == null) { if (defaultClient == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder().dns(safeDns()).readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).retryOnConnectionFailure(true).sslSocketFactory(new SSLSocketFactoryCompat(SSLSocketFactoryCompat.trustAllCert), SSLSocketFactoryCompat.trustAllCert); OkHttpClient.Builder builder = new OkHttpClient.Builder().dns(safeDns()).readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).retryOnConnectionFailure(true).sslSocketFactory(new SSLSocketFactoryCompat(), SSLSocketFactoryCompat.trustAllCert);
defaultClient = builder.build(); defaultClient = builder.build();
} }
return defaultClient; return defaultClient;
@ -39,6 +39,10 @@ public class OkHttpUtil {
} }
} }
public static String stringNoRedirect(String url, Map<String, String> headerMap, Map<String, List<String>> respHeaderMap) {
return string(new OkHttpClient.Builder().dns(safeDns()).readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).followRedirects(false).followSslRedirects(false).retryOnConnectionFailure(true).sslSocketFactory(new SSLSocketFactoryCompat(), SSLSocketFactoryCompat.trustAllCert).build(), url, null, null, headerMap, respHeaderMap, OkHttpUtil.METHOD_GET);
}
public static String string(OkHttpClient client, String url, String tag, Map<String, String> paramsMap, Map<String, String> headerMap, Map<String, List<String>> respHeaderMap, String httpMethod) { public static String string(OkHttpClient client, String url, String tag, Map<String, String> paramsMap, Map<String, String> headerMap, Map<String, List<String>> respHeaderMap, String httpMethod) {
OKCallBack.OKCallBackString callback = new OKCallBack.OKCallBackString() { OKCallBack.OKCallBackString callback = new OKCallBack.OKCallBackString() {
@Override @Override

View File

@ -49,10 +49,10 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
private final SSLSocketFactory defaultFactory; private final SSLSocketFactory defaultFactory;
public SSLSocketFactoryCompat(X509TrustManager tm) { public SSLSocketFactoryCompat() {
try { try {
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, (tm != null) ? new X509TrustManager[]{tm} : null, null); sslContext.init(null, new X509TrustManager[]{SSLSocketFactoryCompat.trustAllCert}, null);
defaultFactory = sslContext.getSocketFactory(); defaultFactory = sslContext.getSocketFactory();
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new AssertionError(); // The system has no TLS. Just give up. throw new AssertionError(); // The system has no TLS. Just give up.

View File

@ -68,7 +68,6 @@ public class Bili extends Spider {
String duration = extend.containsKey("duration") ? extend.get("duration") : "0"; String duration = extend.containsKey("duration") ? extend.get("duration") : "0";
String url = "https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword=" + URLEncoder.encode(tid) + "&duration=" + duration + "&page=" + pg; String url = "https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword=" + URLEncoder.encode(tid) + "&duration=" + duration + "&page=" + pg;
JSONObject resp = new JSONObject(OkHttpUtil.string(url, header)); JSONObject resp = new JSONObject(OkHttpUtil.string(url, header));
System.out.println(resp.toString());
JSONArray result = resp.getJSONObject("data").getJSONArray("result"); JSONArray result = resp.getJSONObject("data").getJSONArray("result");
List<Vod> list = new ArrayList<>(); List<Vod> list = new ArrayList<>();
for (int i = 0; i < result.length(); ++i) { for (int i = 0; i < result.length(); ++i) {

View File

@ -4,28 +4,37 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.widget.Toast;
import com.github.catvod.crawler.SpiderDebug; import com.github.catvod.crawler.SpiderDebug;
public class Init { public class Init {
private final Handler mHandler; private final Handler handler;
private Application mApp; private Application app;
private static class Loader { private static class Loader {
static volatile Init INSTANCE = new Init(); static volatile Init INSTANCE = new Init();
} }
private static Init get() { public static Init get() {
return Loader.INSTANCE; return Loader.INSTANCE;
} }
public Init() { public Init() {
this.mHandler = new Handler(Looper.getMainLooper()); this.handler = new Handler(Looper.getMainLooper());
}
public static Application context() {
return get().app;
} }
public static void init(Context context) { public static void init(Context context) {
SpiderDebug.log("自定義爬蟲代碼載入成功!"); SpiderDebug.log("自定義爬蟲代碼載入成功!");
get().mApp = ((Application) context); get().app = ((Application) context);
}
public static void show(String msg) {
get().handler.post(() -> Toast.makeText(context(), msg, Toast.LENGTH_SHORT).show());
} }
} }

View File

@ -117,6 +117,18 @@ public class Misc {
} }
} }
public static String substring(String text) {
return substring(text, 1);
}
public static String substring(String text, int num) {
if (text != null && text.length() > num) {
return text.substring(0, text.length() - num);
} else {
return text;
}
}
public static String MD5(String src) { public static String MD5(String src) {
return MD5(src, StandardCharsets.UTF_8); return MD5(src, StandardCharsets.UTF_8);
} }

View File

@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id 'ru.cleverpumpkin.proguard-dictionaries-generator' version '1.0.8' apply false id 'ru.cleverpumpkin.proguard-dictionaries-generator' version '1.0.8' apply false
id 'com.android.application' version '7.2.1' apply false id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.2.1' apply false id 'com.android.library' version '7.3.0' apply false
} }
task clean(type: Delete) { task clean(type: Delete) {

View File

@ -1,6 +1,6 @@
#Mon Aug 22 15:05:50 CST 2022 #Mon Aug 22 15:05:50 CST 2022
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

Binary file not shown.

View File

@ -1 +1 @@
82496ffaa62feaa12a8318e606513308 7ccda1ac5ad46cbc3a512821a21fc9ca