commit
23640e8e13
|
|
@ -328,7 +328,7 @@ public class AliYun {
|
||||||
|
|
||||||
public String getShareDownloadUrl(String shareId, String fileId) {
|
public String getShareDownloadUrl(String shareId, String fileId) {
|
||||||
try {
|
try {
|
||||||
if (shareDownloadMap.containsKey(fileId) && shareDownloadMap.get(fileId) != null && !isExpire(shareDownloadMap.get(fileId), 600)) return shareDownloadMap.get(fileId);
|
if (shareDownloadMap.containsKey(fileId) && shareDownloadMap.get(fileId) != null && !isExpire(shareDownloadMap.get(fileId))) return shareDownloadMap.get(fileId);
|
||||||
refreshShareToken(shareId);
|
refreshShareToken(shareId);
|
||||||
SpiderDebug.log("getShareDownloadUrl..." + fileId);
|
SpiderDebug.log("getShareDownloadUrl..." + fileId);
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
|
|
@ -347,7 +347,7 @@ public class AliYun {
|
||||||
|
|
||||||
public String getDownloadUrl(String shareId, String fileId) {
|
public String getDownloadUrl(String shareId, String fileId) {
|
||||||
try {
|
try {
|
||||||
if (downloadMap.containsKey(fileId) && downloadMap.get(fileId) != null && !isExpire(downloadMap.get(fileId), 900)) return downloadMap.get(fileId);
|
if (downloadMap.containsKey(fileId) && downloadMap.get(fileId) != null && !isExpire(downloadMap.get(fileId))) return downloadMap.get(fileId);
|
||||||
refreshShareToken(shareId);
|
refreshShareToken(shareId);
|
||||||
SpiderDebug.log("getDownloadUrl..." + fileId);
|
SpiderDebug.log("getDownloadUrl..." + fileId);
|
||||||
tempIds.add(0, copy(shareId, fileId));
|
tempIds.add(0, copy(shareId, fileId));
|
||||||
|
|
@ -449,7 +449,15 @@ public class AliYun {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String proxyVideoUrl(String cate, String shareId, String fileId) {
|
private String proxyVideoUrl(String cate, String shareId, String fileId) {
|
||||||
return String.format(Proxy.getUrl() + "?do=ali&type=video&cate=%s&shareId=%s&fileId=%s", cate, shareId, fileId);
|
String aliUrl = String.format(Proxy.getUrl() + "?do=ali&type=video&cate=%s&shareId=%s&fileId=%s", cate, shareId, fileId);
|
||||||
|
int thread = 1;
|
||||||
|
if ("open".equals(cate)) {
|
||||||
|
thread = 10;
|
||||||
|
} else if ("share".equals(cate)) {
|
||||||
|
thread = 10;
|
||||||
|
}
|
||||||
|
if (thread == 1) return aliUrl;
|
||||||
|
return ProxyVideo.url(aliUrl, thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String proxyVideoUrl(String cate, String shareId, String fileId, String templateId) {
|
private String proxyVideoUrl(String cate, String shareId, String fileId, String templateId) {
|
||||||
|
|
@ -460,10 +468,10 @@ public class AliYun {
|
||||||
return String.format(Proxy.getUrl() + "?do=ali&type=video&cate=%s&shareId=%s&fileId=%s&templateId=%s&mediaId=%s", cate, shareId, fileId, templateId, mediaId);
|
return String.format(Proxy.getUrl() + "?do=ali&type=video&cate=%s&shareId=%s&fileId=%s&templateId=%s&mediaId=%s", cate, shareId, fileId, templateId, mediaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isExpire(String url, int time) {
|
private static boolean isExpire(String url) {
|
||||||
String expires = new UrlQuerySanitizer(url).getValue("x-oss-expires");
|
String expires = new UrlQuerySanitizer(url).getValue("x-oss-expires");
|
||||||
if (TextUtils.isEmpty(expires)) return false;
|
if (TextUtils.isEmpty(expires)) return false;
|
||||||
return Long.parseLong(expires) - getTimeStamp() <= time / 60;
|
return Long.parseLong(expires) - getTimeStamp() <= 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long getTimeStamp() {
|
private static long getTimeStamp() {
|
||||||
|
|
@ -477,22 +485,19 @@ public class AliYun {
|
||||||
String fileId = params.get("fileId");
|
String fileId = params.get("fileId");
|
||||||
String cate = params.get("cate");
|
String cate = params.get("cate");
|
||||||
String downloadUrl = "";
|
String downloadUrl = "";
|
||||||
int thread = 1;
|
|
||||||
|
|
||||||
if ("preview".equals(cate)) {
|
if ("preview".equals(cate)) {
|
||||||
return previewProxy(shareId, fileId, templateId);
|
return previewProxy(shareId, fileId, templateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("open".equals(cate)) {
|
if ("open".equals(cate)) {
|
||||||
thread = 10;
|
|
||||||
downloadUrl = getDownloadUrl(shareId, fileId);
|
downloadUrl = getDownloadUrl(shareId, fileId);
|
||||||
} else if ("share".equals(cate)) {
|
} else if ("share".equals(cate)) {
|
||||||
thread = 10;
|
|
||||||
downloadUrl = getShareDownloadUrl(shareId, fileId);
|
downloadUrl = getShareDownloadUrl(shareId, fileId);
|
||||||
} else if ("m3u8".equals(cate)) {
|
} else if ("m3u8".equals(cate)) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
String mediaUrl = m3u8MediaMap.get(fileId).get(mediaId);
|
String mediaUrl = m3u8MediaMap.get(fileId).get(mediaId);
|
||||||
if (isExpire(mediaUrl, 900)) {
|
if (isExpire(mediaUrl)) {
|
||||||
getM3u8(shareId, fileId, templateId);
|
getM3u8(shareId, fileId, templateId);
|
||||||
mediaUrl = m3u8MediaMap.get(fileId).get(mediaId);
|
mediaUrl = m3u8MediaMap.get(fileId).get(mediaId);
|
||||||
}
|
}
|
||||||
|
|
@ -512,12 +517,7 @@ public class AliYun {
|
||||||
headers.remove("templateId");
|
headers.remove("templateId");
|
||||||
headers.remove("remote-addr");
|
headers.remove("remote-addr");
|
||||||
headers.remove("http-client-ip");
|
headers.remove("http-client-ip");
|
||||||
|
return new Object[]{ProxyVideo.proxy(downloadUrl, headers)};
|
||||||
if (thread == 1) {
|
|
||||||
return new Object[]{ProxyVideo.proxy(downloadUrl, headers)};
|
|
||||||
} else {
|
|
||||||
return new Object[]{ProxyVideo.multi(downloadUrl, headers, thread)};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[] previewProxy(String shareId, String fileId, String templateId) {
|
private Object[] previewProxy(String shareId, String fileId, String templateId) {
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,15 @@ public class ProxyVideo {
|
||||||
|
|
||||||
private static final String GO_SERVER = "http://127.0.0.1:7777/";
|
private static final String GO_SERVER = "http://127.0.0.1:7777/";
|
||||||
|
|
||||||
public static NanoHTTPD.Response multi(String url, Map<String, String> headers, int thread) throws Exception {
|
public static boolean go() {
|
||||||
if (OkHttp.string(GO_SERVER).isEmpty()) OkHttp.string("http://127.0.0.1:" + Proxy.getPort() + "/go");
|
if (OkHttp.string(GO_SERVER).isEmpty()) OkHttp.string("http://127.0.0.1:" + Proxy.getPort() + "/go");
|
||||||
while (OkHttp.string(GO_SERVER).isEmpty()) SystemClock.sleep(20);
|
while (OkHttp.string(GO_SERVER).isEmpty()) SystemClock.sleep(20);
|
||||||
return proxy(String.format(Locale.getDefault(), "%s?url=%s&thread=%d", GO_SERVER, URLEncoder.encode(url), thread), headers);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String url(String url, int thread) {
|
||||||
|
go();
|
||||||
|
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 NanoHTTPD.Response proxy(String url, Map<String, String> headers) throws Exception {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue