Clean code
This commit is contained in:
parent
2205d18819
commit
93ad5fe010
|
|
@ -456,7 +456,7 @@ public class AliYun {
|
|||
}
|
||||
|
||||
private String proxyVideoUrl(String cate, String shareId, String fileId) {
|
||||
return ProxyVideo.url(String.format(Proxy.getUrl() + "?do=ali&type=video&cate=%s&shareId=%s&fileId=%s", cate, shareId, fileId), 20);
|
||||
return String.format(Proxy.getUrl() + "?do=ali&type=video&cate=%s&shareId=%s&fileId=%s", cate, shareId, fileId);
|
||||
}
|
||||
|
||||
private String proxyVideoUrl(String cate, String shareId, String fileId, String templateId) {
|
||||
|
|
@ -480,7 +480,6 @@ public class AliYun {
|
|||
public Object[] proxyVideo(Map<String, String> params) throws Exception {
|
||||
if (dialog != null && dialog.isShowing()) return null;
|
||||
String templateId = params.get("templateId");
|
||||
String response = params.get("response");
|
||||
String shareId = params.get("shareId");
|
||||
String mediaId = params.get("mediaId");
|
||||
String fileId = params.get("fileId");
|
||||
|
|
@ -488,7 +487,7 @@ public class AliYun {
|
|||
String downloadUrl = "";
|
||||
|
||||
if ("preview".equals(cate)) {
|
||||
return previewProxy(shareId, fileId, templateId);
|
||||
return new Object[]{200, "application/vnd.apple.mpegurl", new ByteArrayInputStream(getM3u8(shareId, fileId, templateId).getBytes())};
|
||||
}
|
||||
|
||||
if ("open".equals(cate)) {
|
||||
|
|
@ -506,24 +505,14 @@ public class AliYun {
|
|||
downloadUrl = mediaUrl;
|
||||
}
|
||||
|
||||
if ("url".equals(response)) return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream(downloadUrl.getBytes("UTF-8"))};
|
||||
Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
for (String key : params.keySet()) headers.put(key, params.get(key));
|
||||
headers.remove("do");
|
||||
headers.remove("host");
|
||||
headers.remove("type");
|
||||
headers.remove("cate");
|
||||
headers.remove("fileId");
|
||||
headers.remove("shareId");
|
||||
headers.remove("mediaId");
|
||||
headers.remove("templateId");
|
||||
headers.remove("remote-addr");
|
||||
headers.remove("http-client-ip");
|
||||
return new Object[]{ProxyVideo.proxy(downloadUrl, headers)};
|
||||
for (String key : params.keySet()) {
|
||||
if (key.equals("referer") || key.equals("icy-metadata") || key.equals("range") || key.equals("connection") || key.equals("accept-encoding") || key.equals("user-agent")) {
|
||||
headers.put(key, params.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] previewProxy(String shareId, String fileId, String templateId) {
|
||||
return new Object[]{200, "application/vnd.apple.mpegurl", new ByteArrayInputStream(getM3u8(shareId, fileId, templateId).getBytes())};
|
||||
return new Object[]{ProxyVideo.proxy(downloadUrl, headers)};
|
||||
}
|
||||
|
||||
private String getM3u8Url(String shareId, String fileId, String templateId) {
|
||||
|
|
|
|||
|
|
@ -44,15 +44,13 @@ public class ProxyVideo {
|
|||
}
|
||||
|
||||
public static NanoHTTPD.Response proxy(String url, Map<String, String> headers) throws Exception {
|
||||
Status status = headers.containsKey("Range") ? Status.PARTIAL_CONTENT : Status.OK;
|
||||
if (!headers.containsKey("Range")) headers.put("Range", "bytes=0-");
|
||||
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, contentType, response.body().byteStream(), contentLength);
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
4795d43e5d59d58d6d4a92361f73974e
|
||||
60be8553ec8072f56c9f73452fd83d71
|
||||
|
|
|
|||
Loading…
Reference in New Issue