httpserver
This commit is contained in:
parent
882b07dd41
commit
55463407e0
|
|
@ -85,12 +85,9 @@ dependencies {
|
||||||
|
|
||||||
|
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
|
||||||
implementation 'io.ktor:ktor-server-core:2.3.13'
|
// https://mvnrepository.com/artifact/com.sun.net.httpserver/http
|
||||||
|
|
||||||
implementation 'io.ktor:ktor-server-netty:2.3.13'
|
implementation("com.sun.net.httpserver:http:20070405")
|
||||||
|
|
||||||
implementation 'io.ktor:ktor-server-call-logging:2.3.13'
|
|
||||||
implementation("org.slf4j:slf4j-android:1.7.36")
|
|
||||||
|
|
||||||
//implementation 'wang.harlon.quickjs:wrapper-java:1.0.0'
|
//implementation 'wang.harlon.quickjs:wrapper-java:1.0.0'
|
||||||
// implementation(ext: 'aar', name: 'quickjs', group: 'fongmi', version: 'release')
|
// implementation(ext: 'aar', name: 'quickjs', group: 'fongmi', version: 'release')
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
-keep class io.ktor.server.config.HoconConfigLoader { *; }
|
-keep class io.ktor.server.config.HoconConfigLoader { *; }
|
||||||
-keep class io.netty.** { *; }
|
|
||||||
|
|
||||||
# Logback (Custom rules, see https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-logback-android.pro)
|
# Logback (Custom rules, see https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-logback-android.pro)
|
||||||
# to ignore warnings coming from slf4j and logback
|
# to ignore warnings coming from slf4j and logback
|
||||||
|
|
@ -95,8 +95,53 @@
|
||||||
-keepattributes SourceFile,LineNumberTable
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
-keepattributes Signature,InnerClasses
|
-keepattributes Signature,InnerClasses
|
||||||
-keepclasseswithmembers class io.netty.** {
|
# 保留所有 Netty 类
|
||||||
*;
|
-keep class io.netty.** { *; }
|
||||||
|
|
||||||
|
# 保留 Netty 的内部类
|
||||||
|
-keep class io.netty.**$* { *; }
|
||||||
|
|
||||||
|
# 保留 Netty 的注解
|
||||||
|
-keep @interface io.netty.**
|
||||||
|
|
||||||
|
# 保留 Netty 的 native 方法
|
||||||
|
-keepclasseswithmembernames,includedescriptorclasses class io.netty.** {
|
||||||
|
native <methods>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 保留 Netty 的序列化相关类
|
||||||
|
-keepclassmembers class io.netty.** implements java.io.Serializable {
|
||||||
|
static final long serialVersionUID;
|
||||||
|
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||||
|
private void writeObject(java.io.ObjectOutputStream);
|
||||||
|
private void readObject(java.io.ObjectInputStream);
|
||||||
|
java.lang.Object writeReplace();
|
||||||
|
java.lang.Object readResolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
# 保留 Netty 的 ChannelFuture 相关类
|
||||||
|
-keep class io.netty.channel.ChannelFuture { *; }
|
||||||
|
-keep class io.netty.util.concurrent.Future { *; }
|
||||||
|
|
||||||
|
# 保留 Netty 的异常类
|
||||||
|
-keep class io.netty.** extends java.lang.Exception { *; }
|
||||||
|
|
||||||
|
# 保留 Netty 的注解处理器
|
||||||
|
-keepclassmembers class * extends io.netty.** {
|
||||||
|
@io.netty.** *;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 不警告 Netty 相关的类
|
||||||
-dontwarn io.netty.**
|
-dontwarn io.netty.**
|
||||||
-dontwarn sun.**
|
# Please add these rules to your existing keep rules in order to suppress warnings.
|
||||||
|
# This is generated automatically by the Android Gradle plugin.
|
||||||
|
-dontwarn java.beans.BeanInfo
|
||||||
|
-dontwarn java.beans.IntrospectionException
|
||||||
|
-dontwarn java.beans.Introspector
|
||||||
|
-dontwarn java.beans.PropertyDescriptor
|
||||||
|
-dontwarn javax.lang.model.element.Modifier
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 禁用代码混淆
|
||||||
|
-dontobfuscate
|
||||||
|
|
@ -25,9 +25,9 @@ import com.github.catvod.net.OkResult;
|
||||||
import com.github.catvod.spider.Init;
|
import com.github.catvod.spider.Init;
|
||||||
import com.github.catvod.spider.Proxy;
|
import com.github.catvod.spider.Proxy;
|
||||||
import com.github.catvod.utils.Json;
|
import com.github.catvod.utils.Json;
|
||||||
import com.github.catvod.utils.KtorServer;
|
|
||||||
import com.github.catvod.utils.Notify;
|
import com.github.catvod.utils.Notify;
|
||||||
import com.github.catvod.utils.Path;
|
import com.github.catvod.utils.Path;
|
||||||
|
import com.github.catvod.utils.ProxyServer;
|
||||||
import com.github.catvod.utils.ProxyVideo;
|
import com.github.catvod.utils.ProxyVideo;
|
||||||
import com.github.catvod.utils.QRCode;
|
import com.github.catvod.utils.QRCode;
|
||||||
import com.github.catvod.utils.ResUtil;
|
import com.github.catvod.utils.ResUtil;
|
||||||
|
|
@ -235,7 +235,7 @@ public class QuarkApi {
|
||||||
Map<String, String> header = getHeaders();
|
Map<String, String> header = getHeaders();
|
||||||
header.remove("Host");
|
header.remove("Host");
|
||||||
header.remove("Content-Type");
|
header.remove("Content-Type");
|
||||||
return Result.get().url(KtorServer.INSTANCE.buildProxyUrl(playUrl, header)).octet().header(header).string();
|
return Result.get().url(ProxyServer.INSTANCE.buildProxyUrl(playUrl, header)).octet().header(header).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String proxyVideoUrl(String url, Map<String, String> header) {
|
private String proxyVideoUrl(String url, Map<String, String> header) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import com.github.catvod.crawler.SpiderDebug;
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
import com.github.catvod.utils.KtorServer;
|
import com.github.catvod.utils.ProxyServer;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -43,8 +43,8 @@ public class Init {
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
get().app = ((Application) context);
|
get().app = ((Application) context);
|
||||||
SpiderDebug.log("自定義爬蟲代碼載入成功!"+"1");
|
SpiderDebug.log("自定義爬蟲代碼載入成功!"+"1");
|
||||||
KtorServer.INSTANCE.stop();
|
ProxyServer.INSTANCE.stop();
|
||||||
KtorServer.INSTANCE.start();
|
ProxyServer.INSTANCE.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void execute(Runnable runnable) {
|
public static void execute(Runnable runnable) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/*
|
||||||
package com.github.catvod.utils
|
package com.github.catvod.utils
|
||||||
|
|
||||||
import com.github.catvod.crawler.SpiderDebug
|
import com.github.catvod.crawler.SpiderDebug
|
||||||
|
|
@ -72,14 +73,18 @@ object KtorServer {
|
||||||
SpiderDebug.log("ktorServer start on $port")
|
SpiderDebug.log("ktorServer start on $port")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 启动服务器 */
|
*/
|
||||||
|
/** 启动服务器 *//*
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch { init() }
|
CoroutineScope(Dispatchers.IO).launch { init() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** 停止服务器 */
|
*/
|
||||||
|
/** 停止服务器 *//*
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
ser?.stop(1_000, 2_000)
|
ser?.stop(1_000, 2_000)
|
||||||
}
|
}
|
||||||
|
|
@ -94,9 +99,11 @@ object KtorServer {
|
||||||
}"
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
*/
|
||||||
|
/**
|
||||||
* 获取是否分片信息,顺带请求一个1MB块
|
* 获取是否分片信息,顺带请求一个1MB块
|
||||||
*/
|
*//*
|
||||||
|
|
||||||
@Throws(java.lang.Exception::class)
|
@Throws(java.lang.Exception::class)
|
||||||
fun getInfo(url: String?, headers: Map<String, String>): Array<Any> {
|
fun getInfo(url: String?, headers: Map<String, String>): Array<Any> {
|
||||||
val newHeaders: MutableMap<String, String> = java.util.HashMap(headers)
|
val newHeaders: MutableMap<String, String> = java.util.HashMap(headers)
|
||||||
|
|
@ -219,3 +226,4 @@ object KtorServer {
|
||||||
url: String, headerNew: Map<String, String>
|
url: String, headerNew: Map<String, String>
|
||||||
): Response? = OkHttp.newCall(url, headerNew)
|
): Response? = OkHttp.newCall(url, headerNew)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
//@RunWith(RobolectricTestRunner.class)
|
||||||
public class ProxyVideoTest {
|
public class ProxyVideoTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -17,8 +17,8 @@ public class ProxyVideoTest {
|
||||||
// "https://js.shipin520.com/pc/images/new/banner20250225.mp4", new HashMap<>());
|
// "https://js.shipin520.com/pc/images/new/banner20250225.mp4", new HashMap<>());
|
||||||
"http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>());
|
"http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>());
|
||||||
System.out.println(url);*/
|
System.out.println(url);*/
|
||||||
KtorServer.INSTANCE.start();
|
ProxyServer.INSTANCE.start();
|
||||||
System.out.println(KtorServer.INSTANCE.buildProxyUrl("http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>()));
|
System.out.println(ProxyServer.INSTANCE.buildProxyUrl("http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>()));
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
8a9fee904fd090f7eb5ec9eb73fc257a
|
9013187cddf48a5b4bf4604b07dd534b
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue