commit
274448b792
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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.
|
|
@ -1 +1 @@
|
||||||
82496ffaa62feaa12a8318e606513308
|
7ccda1ac5ad46cbc3a512821a21fc9ca
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue