Clean code
This commit is contained in:
parent
6e4f3dd77f
commit
9ea7bc4016
|
|
@ -434,11 +434,7 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startFlow() {
|
private void startFlow() {
|
||||||
if (Utils.isMobile()) {
|
Init.run(this::showInput);
|
||||||
Init.run(this::showInput);
|
|
||||||
} else {
|
|
||||||
getQRCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showInput() {
|
private void showInput() {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
package com.github.catvod.net;
|
package com.github.catvod.net;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Authenticator;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -43,8 +41,12 @@ public class OkHttp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient.Builder getBuilder() {
|
public static OkHttpClient.Builder getBuilder() {
|
||||||
|
return getBuilder(proxy());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OkHttpClient.Builder getBuilder(Uri proxy) {
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder().dns(safeDns()).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).hostnameVerifier(SSLCompat.VERIFIER).sslSocketFactory(new SSLCompat(), SSLCompat.TM);
|
OkHttpClient.Builder builder = new OkHttpClient.Builder().dns(safeDns()).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).hostnameVerifier(SSLCompat.VERIFIER).sslSocketFactory(new SSLCompat(), SSLCompat.TM);
|
||||||
if (!TextUtils.isEmpty(proxy())) setProxy(builder);
|
if (proxy != null && proxy.getScheme() != null && proxy.getHost() != null && proxy.getPort() > 0) setProxy(builder, proxy);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,17 +66,9 @@ public class OkHttp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String proxy() {
|
public static Uri proxy() {
|
||||||
try {
|
try {
|
||||||
return (String) Spider.class.getMethod("proxy").invoke(null);
|
return (Uri) Spider.class.getMethod("proxy").invoke(null);
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Authenticator auth() {
|
|
||||||
try {
|
|
||||||
return (Authenticator) Spider.class.getMethod("auth").invoke(null);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -164,14 +158,12 @@ public class OkHttp {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setProxy(OkHttpClient.Builder builder) {
|
private static void setProxy(OkHttpClient.Builder builder, Uri proxy) {
|
||||||
Uri uri = Uri.parse(proxy());
|
String userInfo = proxy.getUserInfo();
|
||||||
String userInfo = uri.getUserInfo();
|
if (proxy.getScheme() == null || proxy.getScheme().startsWith("socks")) {
|
||||||
if (uri.getScheme() != null && uri.getScheme().startsWith("socks")) {
|
builder.proxy(new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(proxy.getHost(), proxy.getPort())));
|
||||||
builder.proxy(new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort())));
|
} else if (proxy.getScheme().startsWith("http")) {
|
||||||
}
|
builder.proxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(proxy.getHost(), proxy.getPort())));
|
||||||
if (uri.getScheme() != null && uri.getScheme().startsWith("http")) {
|
|
||||||
builder.proxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort())));
|
|
||||||
if (userInfo != null && userInfo.contains(":")) builder.proxyAuthenticator((route, response) -> {
|
if (userInfo != null && userInfo.contains(":")) builder.proxyAuthenticator((route, response) -> {
|
||||||
String credential = Credentials.basic(userInfo.split(":")[0], userInfo.split(":")[1]);
|
String credential = Credentials.basic(userInfo.split(":")[0], userInfo.split(":")[1]);
|
||||||
return response.request().newBuilder().header("Proxy-Authorization", credential).build();
|
return response.request().newBuilder().header("Proxy-Authorization", credential).build();
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,6 @@ public class Utils {
|
||||||
return RULE.matcher(url).find();
|
return RULE.matcher(url).find();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMobile() {
|
|
||||||
boolean hasCamera = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
|
|
||||||
boolean hasPhone = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
|
||||||
boolean hasBT = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
|
||||||
return hasCamera && hasPhone && hasBT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] toUtf8(byte[] bytes) {
|
public static byte[] toUtf8(byte[] bytes) {
|
||||||
try {
|
try {
|
||||||
UniversalDetector detector = new UniversalDetector(null);
|
UniversalDetector detector = new UniversalDetector(null);
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
17be876e842892abafa9dd0306e63cc3
|
f6c79a469fd9a93db4dbd5fb568b705a
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue