Skip to content

Commit

Permalink
Remove nanohttpd
Browse files Browse the repository at this point in the history
  • Loading branch information
FongMi committed Jul 25, 2024
1 parent 04ed4a7 commit f599cf0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'cn.wanghaomiao:JsoupXpath:2.5.1'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.google.zxing:core:3.3.0'
implementation 'com.orhanobut:logger:2.2.0'
implementation 'org.jsoup:jsoup:1.15.3'
Expand Down
3 changes: 0 additions & 3 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# Gson
-keep class com.google.gson.** { *; }

# Nano
-keep class fi.iki.elonen.** { *; }

# OkHttp
-dontwarn okhttp3.**
-keep class okio.** { *; }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/catvod/api/AliYun.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public Object[] proxyVideo(Map<String, String> params) throws Exception {
Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
List<String> keys = Arrays.asList("referer", "icy-metadata", "range", "connection", "accept-encoding", "user-agent");
for (String key : params.keySet()) if (keys.contains(key)) headers.put(key, params.get(key));
return new Object[]{ProxyVideo.proxy(downloadUrl, headers)};
return ProxyVideo.proxy(downloadUrl, headers);
}

private String getM3u8Url(String shareId, String fileId, String templateId) {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/com/github/catvod/utils/ProxyVideo.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.github.catvod.utils;

import static fi.iki.elonen.NanoHTTPD.Response.Status;
import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse;

import android.os.SystemClock;
import android.text.TextUtils;

Expand All @@ -12,10 +9,10 @@
import org.json.JSONObject;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import fi.iki.elonen.NanoHTTPD;
import okhttp3.Response;

public class ProxyVideo {
Expand Down Expand Up @@ -43,16 +40,14 @@ public static String url(String url, int thread) {
return String.format(Locale.getDefault(), "%s?url=%s&thread=%d", GO_SERVER, URLEncoder.encode(url), thread);
}

public static NanoHTTPD.Response proxy(String url, Map<String, String> headers) throws Exception {
public static Object[] proxy(String url, Map<String, String> headers) throws Exception {
Response response = OkHttp.newCall(url, headers);
String contentType = response.headers().get("Content-Type");
String hContentLength = response.headers().get("Content-Length");
String contentDisposition = response.headers().get("Content-Disposition");
long contentLength = hContentLength != null ? Long.parseLong(hContentLength) : 0;
if (contentDisposition != null) contentType = getMimeType(contentDisposition);
NanoHTTPD.Response resp = newFixedLengthResponse(Status.PARTIAL_CONTENT, contentType, response.body().byteStream(), contentLength);
for (String key : response.headers().names()) resp.addHeader(key, response.headers().get(key));
return resp;
Map<String, String> respHeaders = new HashMap<>();
for (String key : response.headers().names()) respHeaders.put(key, response.headers().get(key));
return new Object[]{206, contentType, response.body().byteStream(), respHeaders};
}

private static String getMimeType(String contentDisposition) {
Expand Down
Binary file modified jar/custom_spider.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion jar/custom_spider.jar.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3eb80d3f9fc40b9470b262c4c66b39f6
748fbc51b767528466bdbbaee22c8803

0 comments on commit f599cf0

Please sign in to comment.