Update alist and ali
This commit is contained in:
parent
f08beb768e
commit
dde5ec77ee
|
|
@ -42,6 +42,14 @@ public class Vod {
|
||||||
setVodRemarks(vodRemarks);
|
setVodRemarks(vodRemarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vod(String vodId, String vodName, String vodPic, String vodRemarks, String vodTag) {
|
||||||
|
setVodId(vodId);
|
||||||
|
setVodName(vodName);
|
||||||
|
setVodPic(vodPic);
|
||||||
|
setVodRemarks(vodRemarks);
|
||||||
|
setVodTag(vodTag);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTypeName(String typeName) {
|
public void setTypeName(String typeName) {
|
||||||
this.typeName = Trans.get(typeName);
|
this.typeName = Trans.get(typeName);
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +58,10 @@ public class Vod {
|
||||||
this.vodId = vodId;
|
this.vodId = vodId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVodName() {
|
||||||
|
return vodName;
|
||||||
|
}
|
||||||
|
|
||||||
public void setVodName(String vodName) {
|
public void setVodName(String vodName) {
|
||||||
this.vodName = Trans.get(vodName);
|
this.vodName = Trans.get(vodName);
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +99,7 @@ public class Vod {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVodPlayUrl(String vodPlayUrl) {
|
public void setVodPlayUrl(String vodPlayUrl) {
|
||||||
this.vodPlayUrl = Trans.get(vodPlayUrl);
|
this.vodPlayUrl = vodPlayUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVodTag(String vodTag) {
|
public void setVodTag(String vodTag) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
package com.github.catvod.bean.alist;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.github.catvod.bean.Vod;
|
||||||
|
import com.github.catvod.utils.Misc;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
|
||||||
|
@SerializedName("name")
|
||||||
|
private String name;
|
||||||
|
@SerializedName("type")
|
||||||
|
private int type;
|
||||||
|
@SerializedName("size")
|
||||||
|
private long size;
|
||||||
|
@SerializedName(value = "thumb", alternate = "thumbnail")
|
||||||
|
private String thumb;
|
||||||
|
@SerializedName(value = "url", alternate = "raw_url")
|
||||||
|
private String url;
|
||||||
|
@SerializedName(value = "modified", alternate = "updated_at")
|
||||||
|
private String modified;
|
||||||
|
|
||||||
|
public static Item objectFrom(String str) {
|
||||||
|
return new Gson().fromJson(str, Item.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Item> arrayFrom(String str) {
|
||||||
|
Type listType = new TypeToken<List<Item>>() {}.getType();
|
||||||
|
return new Gson().fromJson(str, listType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThumb() {
|
||||||
|
return thumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return TextUtils.isEmpty(url) ? "" : url.startsWith("//") ? "http:" + url : url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModified() {
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
try {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault());
|
||||||
|
return format.parse(getModified());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFolder() {
|
||||||
|
return getType() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMedia() {
|
||||||
|
return getType() == 2 || getType() == 3 || getType() == 4 || getType() == 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSub() {
|
||||||
|
return getType() == 5 && Misc.isSub(getExt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean ignore() {
|
||||||
|
return !isFolder() && !isMedia() && !isSub();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExt() {
|
||||||
|
return getName().substring(getName().lastIndexOf(".") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVodId(String tid) {
|
||||||
|
return tid + "/" + getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPic() {
|
||||||
|
return getThumb().isEmpty() && isFolder() ? "http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png" : getThumb();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return Misc.getSize(getSize()) + (isFolder() ? " 文件夹" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVodTag() {
|
||||||
|
return isFolder() ? "folder" : "file";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vod getVod(String tid) {
|
||||||
|
return new Vod(getVodId(tid), getName(), getPic(), getRemark(), getVodTag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.github.catvod.bean.alist;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Sorter implements Comparator<Item> {
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
public static void sort(String type, List<Item> items) {
|
||||||
|
Collections.sort(items, new Sorter(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sorter(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Item o1, Item o2) {
|
||||||
|
switch (type) {
|
||||||
|
case "name":
|
||||||
|
return o1.getName().compareTo(o2.getName());
|
||||||
|
case "size":
|
||||||
|
return Long.compare(o1.getSize(), o2.getSize());
|
||||||
|
case "date":
|
||||||
|
return o1.getDate().compareTo(o2.getDate());
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.github.catvod.bean.Class;
|
import com.github.catvod.bean.Class;
|
||||||
|
import com.github.catvod.bean.Filter;
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
|
import com.github.catvod.bean.alist.Item;
|
||||||
|
import com.github.catvod.bean.alist.Sorter;
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.net.OkHttpUtil;
|
import com.github.catvod.net.OkHttpUtil;
|
||||||
|
import com.github.catvod.utils.Misc;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
|
|
@ -14,17 +19,19 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AList extends Spider {
|
public class AList extends Spider {
|
||||||
|
|
||||||
|
private LinkedHashMap<String, String> ext;
|
||||||
|
private Map<String, List<String>> sub;
|
||||||
private Map<String, String> map;
|
private Map<String, String> map;
|
||||||
private JSONObject ext;
|
|
||||||
|
|
||||||
private boolean isJson(String json) {
|
private boolean isJson(String json) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -35,18 +42,6 @@ public class AList extends Spider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Context context, String extend) {
|
|
||||||
try {
|
|
||||||
map = new HashMap<>();
|
|
||||||
ext = new JSONObject();
|
|
||||||
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
|
||||||
if (isJson(extend)) parseJson(extend);
|
|
||||||
else parseText(extend);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void parseJson(String extend) throws Exception {
|
private void parseJson(String extend) throws Exception {
|
||||||
JSONObject object = new JSONObject(extend);
|
JSONObject object = new JSONObject(extend);
|
||||||
JSONArray array = object.names();
|
JSONArray array = object.names();
|
||||||
|
|
@ -56,106 +51,142 @@ public class AList extends Spider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseText(String extend) throws Exception {
|
private void parseText(String extend) {
|
||||||
String[] array = extend.split("#");
|
String[] array = extend.split("#");
|
||||||
for (String text : array) {
|
for (String text : array) {
|
||||||
String[] arr = text.split("\\$");
|
String[] arr = text.split("\\$");
|
||||||
if (arr.length == 1) {
|
if (arr.length == 2) ext.put(arr[0], arr[1]);
|
||||||
ext.put("alist", arr[0]);
|
|
||||||
} else if (arr.length == 2) {
|
|
||||||
ext.put(arr[0], arr[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getVersion(String name) throws Exception {
|
private String getVersion(String name) {
|
||||||
if (!map.containsKey(name)) map.put(name, OkHttpUtil.string(ext.getString(name) + "/api/public/settings").contains("v3.") ? "3" : "2");
|
if (!map.containsKey(name)) map.put(name, OkHttpUtil.string(ext.get(name) + "/api/public/settings").contains("v3.") ? "3" : "2");
|
||||||
return map.get(name);
|
return map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Context context, String extend) {
|
||||||
|
try {
|
||||||
|
map = new HashMap<>();
|
||||||
|
ext = new LinkedHashMap<>();
|
||||||
|
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
||||||
|
if (isJson(extend)) parseJson(extend);
|
||||||
|
else parseText(extend);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String homeContent(boolean filter) {
|
public String homeContent(boolean filter) {
|
||||||
List<Class> classes = new ArrayList<>();
|
List<Class> classes = new ArrayList<>();
|
||||||
Iterator<String> keys = this.ext.keys();
|
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
||||||
while (keys.hasNext()) {
|
for (String entry : ext.keySet()) classes.add(new Class(entry, entry, "1"));
|
||||||
String key = keys.next();
|
for (Class item : classes) filters.put(item.getTypeId(), Arrays.asList(new Filter("type", "排序", Arrays.asList(new Filter.Value("名稱", "name"), new Filter.Value("大小", "size"), new Filter.Value("修改時間", "date")))));
|
||||||
classes.add(new Class(key + "$/", key, "1"));
|
return Result.string(classes, filters);
|
||||||
}
|
|
||||||
return Result.string(classes, Collections.emptyList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) throws Exception {
|
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
||||||
int index = tid.indexOf('$');
|
String type = extend.containsKey("type") ? extend.get("type") : "";
|
||||||
String name = tid.substring(0, index);
|
List<Item> folders = new ArrayList<>();
|
||||||
String path = tid.substring(index + 1);
|
List<Item> files = new ArrayList<>();
|
||||||
boolean v3 = getVersion(name).equals("3");
|
|
||||||
String url = ext.getString(name) + (v3 ? "/api/fs/list" : "/api/public/path");
|
|
||||||
JSONObject params = new JSONObject();
|
|
||||||
params.put("path", path);
|
|
||||||
String response = OkHttpUtil.postJson(url, params.toString());
|
|
||||||
JSONArray array = new JSONObject(response).getJSONObject("data").getJSONArray(v3 ? "content" : "files");
|
|
||||||
List<Vod> list = new ArrayList<>();
|
List<Vod> list = new ArrayList<>();
|
||||||
for (int i = 0; i < array.length(); ++i) {
|
sub = new HashMap<>();
|
||||||
JSONObject o = array.getJSONObject(i);
|
for (Item item : getList(tid)) {
|
||||||
String pic = o.getString(v3 ? "thumb" : "thumbnail");
|
if (item.ignore()) continue;
|
||||||
boolean folder = o.getInt("type") == 1;
|
if (item.isSub()) addSub(tid, item);
|
||||||
if (pic.isEmpty() && folder) pic = "http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png";
|
else if (item.isFolder()) folders.add(item);
|
||||||
Vod vod = new Vod();
|
else files.add(item);
|
||||||
vod.setVodId(tid + (tid.charAt(tid.length() - 1) == '/' ? "" : "/") + o.getString("name"));
|
|
||||||
vod.setVodName(o.getString("name"));
|
|
||||||
vod.setVodPic(pic);
|
|
||||||
vod.setVodTag(folder ? "folder" : "file");
|
|
||||||
String size = getSize(o.getLong("size"));
|
|
||||||
vod.setVodRemarks(folder ? size + " 文件夹" : size);
|
|
||||||
list.add(vod);
|
|
||||||
}
|
}
|
||||||
|
Sorter.sort(type, folders);
|
||||||
|
Sorter.sort(type, files);
|
||||||
|
for (Item item : folders) list.add(item.getVod(tid));
|
||||||
|
for (Item item : files) list.add(item.getVod(tid));
|
||||||
return Result.string(list);
|
return Result.string(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String detailContent(List<String> ids) throws Exception {
|
public String detailContent(List<String> ids) {
|
||||||
String tid = ids.get(0);
|
String tid = ids.get(0);
|
||||||
int index = tid.indexOf('$');
|
Item item = getDetail(tid);
|
||||||
String name = tid.substring(0, index);
|
|
||||||
String path = tid.substring(index + 1);
|
|
||||||
boolean v3 = getVersion(name).equals("3");
|
|
||||||
String url = ext.getString(name) + (v3 ? "/api/fs/get" : "/api/public/path");
|
|
||||||
JSONObject params = new JSONObject();
|
|
||||||
params.put("path", path);
|
|
||||||
String response = OkHttpUtil.postJson(url, params.toString());
|
|
||||||
JSONObject data = v3 ? new JSONObject(response).getJSONObject("data") : new JSONObject(response).getJSONObject("data").getJSONArray("files").getJSONObject(0);
|
|
||||||
url = data.getString(v3 ? "raw_url" : "url");
|
|
||||||
if (url.indexOf("//") == 0) url = "http:" + url;
|
|
||||||
Vod vod = new Vod();
|
Vod vod = new Vod();
|
||||||
vod.setVodId(tid + "/" + data.getString("name"));
|
vod.setVodId(item.getVodId(tid));
|
||||||
vod.setVodName(data.getString("name"));
|
vod.setVodName(item.getName());
|
||||||
vod.setVodPic(data.getString(v3 ? "thumb" : "thumbnail"));
|
vod.setVodPic(item.getPic());
|
||||||
vod.setVodTag(data.getInt("type") == 1 ? "folder" : "file");
|
vod.setVodTag(item.getVodTag());
|
||||||
vod.setVodPlayFrom("播放");
|
vod.setVodPlayFrom("播放");
|
||||||
vod.setVodPlayUrl(data.getString("name") + "$" + url);
|
vod.setVodPlayUrl(item.getName() + "$" + item.getUrl() + findSubs(item.getName()));
|
||||||
return Result.string(vod);
|
return Result.string(vod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) {
|
public String playerContent(String flag, String id, List<String> vipFlags) {
|
||||||
return Result.get().url(id).string();
|
String[] ids = id.split("\\+");
|
||||||
|
return Result.get().url(ids[0]).sub(getSub(ids)).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSize(double size) {
|
private List<Item> getList(String tid) {
|
||||||
if (size == 0) return "";
|
try {
|
||||||
if (size > 1024 * 1024 * 1024 * 1024.0) {
|
String key = tid.contains("/") ? tid.substring(0, tid.indexOf("/")) : tid;
|
||||||
size /= (1024 * 1024 * 1024 * 1024.0);
|
String path = tid.contains("/") ? tid.substring(tid.indexOf("/") + 1) : "";
|
||||||
return String.format(Locale.getDefault(), "%.2f%s", size, "TB");
|
boolean v3 = getVersion(key).equals("3");
|
||||||
} else if (size > 1024 * 1024 * 1024.0) {
|
String url = ext.get(key) + (v3 ? "/api/fs/list" : "/api/public/path");
|
||||||
size /= (1024 * 1024 * 1024.0);
|
JSONObject params = new JSONObject();
|
||||||
return String.format(Locale.getDefault(), "%.2f%s", size, "GB");
|
params.put("path", path);
|
||||||
} else if (size > 1024 * 1024.0) {
|
String response = OkHttpUtil.postJson(url, params.toString());
|
||||||
size /= (1024 * 1024.0);
|
String json = new JSONObject(response).getJSONObject("data").getJSONArray(v3 ? "content" : "files").toString();
|
||||||
return String.format(Locale.getDefault(), "%.2f%s", size, "MB");
|
return Item.arrayFrom(json);
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
size /= 1024.0;
|
return Collections.emptyList();
|
||||||
return String.format(Locale.getDefault(), "%.2f%s", size, "KB");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Item getDetail(String tid) {
|
||||||
|
try {
|
||||||
|
String key = tid.contains("/") ? tid.substring(0, tid.indexOf("/")) : tid;
|
||||||
|
String path = tid.contains("/") ? tid.substring(tid.indexOf("/") + 1) : "";
|
||||||
|
boolean v3 = getVersion(key).equals("3");
|
||||||
|
String url = ext.get(key) + (v3 ? "/api/fs/get" : "/api/public/path");
|
||||||
|
JSONObject params = new JSONObject();
|
||||||
|
params.put("path", path);
|
||||||
|
String response = OkHttpUtil.postJson(url, params.toString());
|
||||||
|
String json = v3 ? new JSONObject(response).getJSONObject("data").toString() : new JSONObject(response).getJSONObject("data").getJSONArray("files").getJSONObject(0).toString();
|
||||||
|
return Item.objectFrom(json);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new Item();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSub(String tid, Item item) {
|
||||||
|
String name = item.getName().substring(0, item.getName().lastIndexOf("."));
|
||||||
|
if (!sub.containsKey(name)) sub.put(name, new ArrayList<>());
|
||||||
|
Objects.requireNonNull(sub.get(name)).add(item.getName() + "@" + item.getVodId(tid) + "@" + item.getExt());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String findSubs(String name) {
|
||||||
|
name = name.substring(0, name.lastIndexOf("."));
|
||||||
|
List<String> subs = sub.get(name);
|
||||||
|
if (subs != null && subs.size() > 0) return combineSubs(subs);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Map.Entry<String, List<String>> entry : sub.entrySet()) sb.append(combineSubs(entry.getValue()));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String combineSubs(List<String> subs) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String sub : subs) sb.append("+").append(sub);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSub(String[] ids) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String text : ids) {
|
||||||
|
if (!text.contains("@")) continue;
|
||||||
|
String[] arr = text.split("@");
|
||||||
|
String url = getDetail(arr[1]).getUrl();
|
||||||
|
if (TextUtils.isEmpty(url)) continue;
|
||||||
|
sb.append(arr[0]).append("#").append(Misc.getSubMimeType(arr[2])).append("#").append(url).append("$$$");
|
||||||
|
}
|
||||||
|
return Misc.substring(sb.toString(), 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +142,7 @@ public class Ali {
|
||||||
name2id.put(name, shareId + "+" + shareToken + "+" + fileId);
|
name2id.put(name, shareId + "+" + shareToken + "+" + fileId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isSubFile(ext)) {
|
if (Misc.isSub(ext)) {
|
||||||
name = name.replace("." + ext, "");
|
name = name.replace("." + ext, "");
|
||||||
if (!subMap.containsKey(name)) subMap.put(name, new ArrayList<>());
|
if (!subMap.containsKey(name)) subMap.put(name, new ArrayList<>());
|
||||||
Objects.requireNonNull(subMap.get(name)).add(name + "@" + fileId + "@" + ext);
|
Objects.requireNonNull(subMap.get(name)).add(name + "@" + fileId + "@" + ext);
|
||||||
|
|
@ -180,8 +180,9 @@ public class Ali {
|
||||||
name = name.substring(0, name.lastIndexOf("."));
|
name = name.substring(0, name.lastIndexOf("."));
|
||||||
List<String> subs = subMap.get(name);
|
List<String> subs = subMap.get(name);
|
||||||
if (subs != null && subs.size() > 0) return combineSubs(subs);
|
if (subs != null && subs.size() > 0) return combineSubs(subs);
|
||||||
for (Map.Entry<String, List<String>> entry : subMap.entrySet()) if (entry.getKey().contains(name)) return combineSubs(entry.getValue());
|
StringBuilder sb = new StringBuilder();
|
||||||
return "";
|
for (Map.Entry<String, List<String>> entry : subMap.entrySet()) sb.append(combineSubs(entry.getValue()));
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String combineSubs(List<String> subs) {
|
private String combineSubs(List<String> subs) {
|
||||||
|
|
@ -196,21 +197,10 @@ public class Ali {
|
||||||
if (!text.contains("@")) continue;
|
if (!text.contains("@")) continue;
|
||||||
String[] arr = text.split("@");
|
String[] arr = text.split("@");
|
||||||
String url = Proxy.getUrl() + "?do=ali&type=sub&share_id=" + shareId + "&share_token=" + shareToken + "&file_id=" + arr[1];
|
String url = Proxy.getUrl() + "?do=ali&type=sub&share_id=" + shareId + "&share_token=" + shareToken + "&file_id=" + arr[1];
|
||||||
sb.append(arr[0]).append("#").append(getSubMimeType(arr[2])).append("#").append(url).append("$$$");
|
sb.append(arr[0]).append("#").append(Misc.getSubMimeType(arr[2])).append("#").append(url).append("$$$");
|
||||||
|
}
|
||||||
return Misc.substring(sb.toString(), 3);
|
return Misc.substring(sb.toString(), 3);
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSubFile(String ext) {
|
|
||||||
return ext.equals("srt") || ext.equals("ass") || ext.equals("ssa");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getSubMimeType(String type) {
|
|
||||||
if (type.equals("srt")) return "application/x-subrip";
|
|
||||||
if (type.equals("ass") || type.equals("ssa")) return "text/x-ssa";
|
|
||||||
return "application/x-subrip";
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getShareToken(String shareId) {
|
private String getShareToken(String shareId) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Misc {
|
public class Misc {
|
||||||
|
|
@ -53,6 +54,33 @@ public class Misc {
|
||||||
return SNIFFER.matcher(url).find();
|
return SNIFFER.matcher(url).find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSub(String ext) {
|
||||||
|
return ext.equals("srt") || ext.equals("ass") || ext.equals("ssa");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSubMimeType(String type) {
|
||||||
|
if (type.equals("srt")) return "application/x-subrip";
|
||||||
|
if (type.equals("ass") || type.equals("ssa")) return "text/x-ssa";
|
||||||
|
return "application/x-subrip";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSize(double size) {
|
||||||
|
if (size == 0) return "";
|
||||||
|
if (size > 1024 * 1024 * 1024 * 1024.0) {
|
||||||
|
size /= (1024 * 1024 * 1024 * 1024.0);
|
||||||
|
return String.format(Locale.getDefault(), "%.2f%s", size, "TB");
|
||||||
|
} else if (size > 1024 * 1024 * 1024.0) {
|
||||||
|
size /= (1024 * 1024 * 1024.0);
|
||||||
|
return String.format(Locale.getDefault(), "%.2f%s", size, "GB");
|
||||||
|
} else if (size > 1024 * 1024.0) {
|
||||||
|
size /= (1024 * 1024.0);
|
||||||
|
return String.format(Locale.getDefault(), "%.2f%s", size, "MB");
|
||||||
|
} else {
|
||||||
|
size /= 1024.0;
|
||||||
|
return String.format(Locale.getDefault(), "%.2f%s", size, "KB");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String fixUrl(String base, String src) {
|
public static String fixUrl(String base, String src) {
|
||||||
try {
|
try {
|
||||||
if (src.startsWith("//")) {
|
if (src.startsWith("//")) {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
2238f733904942609bb90b337dee9713
|
5e45ee53bd37b87d71cc591d1a2c208b
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue