Merge pull request #55 from okcaptain/main

goroutine video proxy
pull/69/head
FongMi 2 years ago committed by GitHub
commit 390f76b1b7
  1. 8
      app/src/main/java/com/github/catvod/api/AliYun.java
  2. 4
      app/src/main/java/com/github/catvod/utils/MultiThread.java
  3. 4
      app/src/main/java/com/github/catvod/utils/ProxyVideo.java

@ -34,7 +34,7 @@ import com.github.catvod.net.OkHttp;
import com.github.catvod.net.OkResult;
import com.github.catvod.spider.Init;
import com.github.catvod.spider.Proxy;
import com.github.catvod.utils.MultiThreadedDownloader;
import com.github.catvod.utils.MultiThread;
import com.github.catvod.utils.Path;
import com.github.catvod.utils.ProxyVideo;
import com.github.catvod.utils.QRCode;
@ -67,8 +67,6 @@ public class AliYun {
private final List<String> tempIds;
private final ReentrantLock lock;
private final Cache cache;
private MultiThreadedDownloader downloader;
private ScheduledExecutorService service;
private String refreshToken;
private AlertDialog dialog;
@ -516,9 +514,7 @@ public class AliYun {
if (thread == 1) {
return new Object[]{ProxyVideo.proxy(downloadUrl, headers)};
} else {
if (downloader != null) downloader.destory();
downloader = new MultiThreadedDownloader(downloadUrl, headers, thread);
return new Object[]{downloader.start()};
return new Object[]{ProxyVideo.proxy(MultiThread.go(downloadUrl, thread), headers)};
}
}

@ -12,6 +12,10 @@ public class MultiThread {
return String.format(Proxy.getUrl() + "?do=multi&url=%s&thread=%d", URLEncoder.encode(url), thread);
}
public static String go(String url, int thread) {
return String.format("http://127.0.0.1:7777/?url=%s&thread=%d", URLEncoder.encode(url), thread);
}
public static Object[] proxy(Map<String, String> params) throws Exception {
String url = params.get("url");
int thread = Integer.parseInt(params.get("thread"));

@ -23,6 +23,8 @@ public class ProxyVideo {
String contentDisposition = response.headers().get("Content-Disposition");
long contentLength = hContentLength != null ? Long.parseLong(hContentLength) : 0;
if (contentDisposition != null) contentType = Utils.getMimeType(contentDisposition);
return newFixedLengthResponse(status, contentType, response.body().byteStream(), contentLength);
NanoHTTPD.Response resp = newFixedLengthResponse(status, contentType, response.body().byteStream(), contentLength);
for (String key : response.headers().names()) resp.addHeader(key, response.headers().get(key));
return resp;
}
}

Loading…
Cancel
Save