commit
274448b792
|
|
@ -4,12 +4,12 @@ plugins {
|
|||
}
|
||||
|
||||
android {
|
||||
compileSdk 32
|
||||
compileSdk 33
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.github.catvod.demo"
|
||||
minSdk 21
|
||||
targetSdk 32
|
||||
targetSdk 33
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ public class Result {
|
|||
private String header;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
@SerializedName("sub")
|
||||
private String sub;
|
||||
@SerializedName("parse")
|
||||
private int parse;
|
||||
@SerializedName("jx")
|
||||
|
|
@ -111,6 +113,11 @@ public class Result {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Result sub(String sub) {
|
||||
this.sub = sub;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Vod> getList() {
|
||||
return list == null ? Collections.emptyList() : list;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class OkHttpUtil {
|
|||
public static OkHttpClient defaultClient() {
|
||||
synchronized (lockO) {
|
||||
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();
|
||||
}
|
||||
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) {
|
||||
OKCallBack.OKCallBackString callback = new OKCallBack.OKCallBackString() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
|||
|
||||
private final SSLSocketFactory defaultFactory;
|
||||
|
||||
public SSLSocketFactoryCompat(X509TrustManager tm) {
|
||||
public SSLSocketFactoryCompat() {
|
||||
try {
|
||||
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();
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new AssertionError(); // The system has no TLS. Just give up.
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ public class Bili extends Spider {
|
|||
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;
|
||||
JSONObject resp = new JSONObject(OkHttpUtil.string(url, header));
|
||||
System.out.println(resp.toString());
|
||||
JSONArray result = resp.getJSONObject("data").getJSONArray("result");
|
||||
List<Vod> list = new ArrayList<>();
|
||||
for (int i = 0; i < result.length(); ++i) {
|
||||
|
|
|
|||
|
|
@ -4,28 +4,37 @@ import android.app.Application;
|
|||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
|
||||
public class Init {
|
||||
|
||||
private final Handler mHandler;
|
||||
private Application mApp;
|
||||
private final Handler handler;
|
||||
private Application app;
|
||||
|
||||
private static class Loader {
|
||||
static volatile Init INSTANCE = new Init();
|
||||
}
|
||||
|
||||
private static Init get() {
|
||||
public static Init get() {
|
||||
return Loader.INSTANCE;
|
||||
}
|
||||
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
return MD5(src, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
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.library' version '7.2.1' apply false
|
||||
id 'com.android.application' version '7.3.0' apply false
|
||||
id 'com.android.library' version '7.3.0' apply false
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#Mon Aug 22 15:05:50 CST 2022
|
||||
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
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
82496ffaa62feaa12a8318e606513308
|
||||
7ccda1ac5ad46cbc3a512821a21fc9ca
|
||||
|
|
|
|||
Loading…
Reference in New Issue