Fix ali sort
This commit is contained in:
parent
ed386ca5a2
commit
ac78447018
|
|
@ -103,15 +103,6 @@ public class AliYun {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void setShareId(String shareId) {
|
||||
if (!getUserCache().exists()) user.clean().save();
|
||||
if (!getOAuthCache().exists()) oauth.clean().save();
|
||||
if (!getDriveCache().exists()) drive.clean().save();
|
||||
if (shareId.equals(this.shareId)) return;
|
||||
this.shareId = shareId;
|
||||
refreshShareToken();
|
||||
}
|
||||
|
||||
public HashMap<String, String> getHeader() {
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", Utils.CHROME);
|
||||
|
|
@ -153,7 +144,7 @@ public class AliYun {
|
|||
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
||||
OkResult result = OkHttp.postJson(url, json, getHeaderAuth());
|
||||
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
||||
if (retry && result.getCode() == 400 && refreshShareToken()) return auth(url, json, false);
|
||||
if (retry && result.getBody().contains("InvalidParameterNotMatch.ShareId") && refreshShareToken()) return auth(url, json, false);
|
||||
if (retry && result.getCode() == 401 && refreshAccessToken()) return auth(url, json, false);
|
||||
if (retry && result.getCode() == 429) return auth(url, json, false);
|
||||
return result.getBody();
|
||||
|
|
@ -179,6 +170,13 @@ public class AliYun {
|
|||
return false;
|
||||
}
|
||||
|
||||
private String check(String shareId) {
|
||||
if (shareId.equals(this.shareId)) return shareId;
|
||||
this.shareId = shareId;
|
||||
refreshShareToken();
|
||||
return shareId;
|
||||
}
|
||||
|
||||
private boolean refreshShareToken() {
|
||||
SpiderDebug.log("refreshShareToken...");
|
||||
JsonObject param = new JsonObject();
|
||||
|
|
@ -248,18 +246,18 @@ public class AliYun {
|
|||
return alist("token", param);
|
||||
}
|
||||
|
||||
public Vod getVod(String url, String fileId) {
|
||||
public Vod getVod(String url, String shareId, String fileId) {
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("share_id", shareId);
|
||||
param.addProperty("share_id", check(shareId));
|
||||
Share share = Share.objectFrom(post("adrive/v3/share_link/get_share_by_anonymous", param));
|
||||
List<Item> files = new ArrayList<>();
|
||||
List<Item> subs = new ArrayList<>();
|
||||
listFiles(new Item(getParentFileId(fileId, share)), files, subs);
|
||||
listFiles(shareId, new Item(getParentFileId(fileId, share)), files, subs);
|
||||
Collections.sort(files);
|
||||
List<String> playFrom = Arrays.asList("原畫", "普畫");
|
||||
List<String> episode = new ArrayList<>();
|
||||
List<String> playUrl = new ArrayList<>();
|
||||
for (Item file : files) episode.add(file.getDisplayName() + "$" + shareId + "@" + file.getFileId() + findSubs(file.getName(), subs));
|
||||
for (Item file : files) episode.add(file.getDisplayName() + "$" + shareId + "+" + file.getFileId() + findSubs(file.getName(), subs));
|
||||
for (int i = 0; i < playFrom.size(); i++) playUrl.add(TextUtils.join("#", episode));
|
||||
Vod vod = new Vod();
|
||||
vod.setVodId(url);
|
||||
|
|
@ -272,11 +270,11 @@ public class AliYun {
|
|||
return vod;
|
||||
}
|
||||
|
||||
private void listFiles(Item folder, List<Item> files, List<Item> subs) {
|
||||
listFiles(folder, files, subs, "");
|
||||
private void listFiles(String shareId, Item folder, List<Item> files, List<Item> subs) {
|
||||
listFiles(shareId, folder, files, subs, "");
|
||||
}
|
||||
|
||||
private void listFiles(Item parent, List<Item> files, List<Item> subs, String marker) {
|
||||
private void listFiles(String shareId, Item parent, List<Item> files, List<Item> subs, String marker) {
|
||||
List<Item> folders = new ArrayList<>();
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("limit", 200);
|
||||
|
|
@ -296,10 +294,10 @@ public class AliYun {
|
|||
}
|
||||
}
|
||||
if (item.getNextMarker().length() > 0) {
|
||||
listFiles(parent, files, subs, item.getNextMarker());
|
||||
listFiles(shareId, parent, files, subs, item.getNextMarker());
|
||||
}
|
||||
for (Item folder : folders) {
|
||||
listFiles(folder, files, subs);
|
||||
listFiles(shareId, folder, files, subs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -333,16 +331,16 @@ public class AliYun {
|
|||
String[] split = text.split("@@@");
|
||||
String name = split[0];
|
||||
String ext = split[1];
|
||||
String url = Proxy.getUrl() + "?do=ali&type=sub&file_id=" + split[2];
|
||||
String url = Proxy.getUrl() + "?do=ali&type=sub&shareId=" + ids[0] + "&fileId=" + split[2];
|
||||
sub.add(Sub.create().name(name).ext(ext).url(url));
|
||||
}
|
||||
return sub;
|
||||
}
|
||||
|
||||
public String getDownloadUrl(String fileId) {
|
||||
public String getDownloadUrl(String shareId, String fileId) {
|
||||
try {
|
||||
SpiderDebug.log("getDownloadUrl..." + fileId);
|
||||
tempIds.add(0, copy(fileId));
|
||||
tempIds.add(0, copy(shareId, fileId));
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("file_id", tempIds.get(0));
|
||||
param.addProperty("drive_id", drive.getDriveId());
|
||||
|
|
@ -356,10 +354,10 @@ public class AliYun {
|
|||
}
|
||||
}
|
||||
|
||||
public Preview.Info getVideoPreviewPlayInfo(String fileId) {
|
||||
public Preview.Info getVideoPreviewPlayInfo(String shareId, String fileId) {
|
||||
try {
|
||||
SpiderDebug.log("getVideoPreviewPlayInfo..." + fileId);
|
||||
tempIds.add(0, copy(fileId));
|
||||
tempIds.add(0, copy(shareId, fileId));
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("file_id", tempIds.get(0));
|
||||
param.addProperty("drive_id", drive.getDriveId());
|
||||
|
|
@ -376,12 +374,12 @@ public class AliYun {
|
|||
}
|
||||
|
||||
public String playerContent(String[] ids, boolean original) {
|
||||
if (original) return Result.get().url(getDownloadUrl(ids[0])).octet().subs(getSubs(ids)).header(getHeader()).string();
|
||||
if (original) return Result.get().url(getDownloadUrl(ids[0], ids[1])).octet().subs(getSubs(ids)).header(getHeader()).string();
|
||||
else return getPreviewContent(ids);
|
||||
}
|
||||
|
||||
private String getPreviewContent(String[] ids) {
|
||||
Preview.Info info = getVideoPreviewPlayInfo(ids[0]);
|
||||
Preview.Info info = getVideoPreviewPlayInfo(ids[0], ids[1]);
|
||||
List<String> url = getPreviewUrl(info);
|
||||
List<Sub> subs = getSubs(ids);
|
||||
subs.addAll(getSubs(info));
|
||||
|
|
@ -404,11 +402,11 @@ public class AliYun {
|
|||
return subs;
|
||||
}
|
||||
|
||||
private String copy(String fileId) {
|
||||
private String copy(String shareId, String fileId) {
|
||||
if (drive.getDriveId().isEmpty()) getDriveId();
|
||||
SpiderDebug.log("Copy..." + fileId + "," + shareId + "," + drive.getDriveId());
|
||||
SpiderDebug.log("Copy..." + fileId);
|
||||
String json = "{\"requests\":[{\"body\":{\"file_id\":\"%s\",\"share_id\":\"%s\",\"auto_rename\":true,\"to_parent_file_id\":\"root\",\"to_drive_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"0\",\"method\":\"POST\",\"url\":\"/file/copy\"}],\"resource\":\"file\"}";
|
||||
json = String.format(json, fileId, shareId, drive.getDriveId());
|
||||
json = String.format(json, fileId, check(shareId), drive.getDriveId());
|
||||
Res res = Res.objectFrom(auth("adrive/v2/batch", json, true));
|
||||
return res.getResponse().getBody().getFileId();
|
||||
}
|
||||
|
|
@ -430,8 +428,9 @@ public class AliYun {
|
|||
}
|
||||
|
||||
public Object[] proxySub(Map<String, String> params) throws Exception {
|
||||
String fileId = params.get("file_id");
|
||||
Response res = OkHttp.newCall(getDownloadUrl(fileId), getHeaderAuth());
|
||||
String fileId = params.get("fileId");
|
||||
String shareId = params.get("shareId");
|
||||
Response res = OkHttp.newCall(getDownloadUrl(shareId, fileId), getHeaderAuth());
|
||||
byte[] body = Utils.toUtf8(res.body().bytes());
|
||||
Object[] result = new Object[3];
|
||||
result[0] = 200;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.github.catvod.bean.ali;
|
|||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.catvod.utils.ChineseComparator;
|
||||
import com.github.catvod.utils.Utils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
|
@ -87,8 +86,12 @@ public class Item implements Comparable<Item> {
|
|||
return TextUtils.join(" ", Arrays.asList(getParent(), getName(), getSize())).trim();
|
||||
}
|
||||
|
||||
public String getSortName() {
|
||||
return TextUtils.join(" ", Arrays.asList(getParent(), getName())).trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
return ChineseComparator.compare(this.getDisplayName(), item.getDisplayName());
|
||||
return Integer.compare(Utils.getDigit(getSortName()), Utils.getDigit(item.getSortName()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,15 +37,13 @@ public class Ali extends Spider {
|
|||
|
||||
@Override
|
||||
public String playerContent(String flag, String id, List<String> vipFlags) {
|
||||
AliYun.get().setShareId(id.split("@")[0]);
|
||||
return AliYun.get().playerContent(id.split("@")[1].split("\\+"), flag.split("#")[0].equals("原畫"));
|
||||
return AliYun.get().playerContent(id.split("\\+"), flag.split("#")[0].equals("原畫"));
|
||||
}
|
||||
|
||||
private Vod parseVod(Matcher matcher, String id) {
|
||||
String shareId = matcher.group(1);
|
||||
String fileId = matcher.groupCount() == 3 ? matcher.group(3) : "";
|
||||
AliYun.get().setShareId(shareId);
|
||||
return AliYun.get().getVod(id, fileId);
|
||||
return AliYun.get().getVod(id, shareId, fileId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 按照 Windows 排序风格,对给定的数字、字母、汉字字符串进行排序
|
||||
*
|
||||
* @author Oiltea
|
||||
*/
|
||||
public class ChineseComparator {
|
||||
|
||||
private static final Integer TYPE_NUMBER = 0;
|
||||
private static final Integer TYPE_CHARACTER = 1;
|
||||
|
||||
public static int compare(String o1, String o2) {
|
||||
// 根据字符数组生成带分类的字符列表
|
||||
// List<Object>的第一位为该字符的类型(TYPE_NUMBER, TYPE_CHARACTER)
|
||||
// List<Object>的第二位为该字符的内容(一位数字, 一位非数字, 多位数字)
|
||||
List<List<Object>> o1CharList = getCharList(o1);
|
||||
List<List<Object>> o2CharList = getCharList(o2);
|
||||
|
||||
// 统一CharList的长度
|
||||
int max = Math.max(o1CharList.size(), o2CharList.size());
|
||||
while (o1CharList.size() < max) {
|
||||
o1CharList.add(new ArrayList<>());
|
||||
}
|
||||
while (o2CharList.size() < max) {
|
||||
o2CharList.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
// 开始比较
|
||||
int compare = 0;
|
||||
for (int i = 0; i < max; i++) {
|
||||
List<Object> o1list = o1CharList.get(i);
|
||||
List<Object> o2list = o2CharList.get(i);
|
||||
|
||||
// CharList短的,排在前面
|
||||
if (o1list.size() == 0) {
|
||||
compare = -1;
|
||||
break;
|
||||
}
|
||||
if (o2list.size() == 0) {
|
||||
compare = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// 先比较类型
|
||||
Integer o1Type = (Integer) o1list.get(0);
|
||||
Integer o2Type = (Integer) o2list.get(0);
|
||||
int typeCompare = Integer.compare(o1Type, o2Type);
|
||||
if (typeCompare != 0) {
|
||||
// 类型不同,则数字在前,非数字在后
|
||||
compare = typeCompare;
|
||||
break;
|
||||
} else {
|
||||
// 类型相同,则比较内容
|
||||
if (TYPE_NUMBER.equals(o1Type)) {
|
||||
// 比较数字
|
||||
int o1Content = Integer.parseInt(o1list.get(1).toString());
|
||||
int o2Content = Integer.parseInt(o2list.get(1).toString());
|
||||
compare = Integer.compare(o1Content, o2Content);
|
||||
} else if (TYPE_CHARACTER.equals(o1Type)) {
|
||||
// 比较非数字
|
||||
String o1Content = (String) o1list.get(1);
|
||||
String o2Content = (String) o2list.get(1);
|
||||
compare = Collator.getInstance(Locale.CHINESE).compare(o1Content, o2Content);
|
||||
}
|
||||
// 如果不相等,则退出比较
|
||||
if (compare != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return compare;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字符数组生成带分类的字符列表
|
||||
*
|
||||
* @param text 字符串
|
||||
* @return 带分类的字符列表,List<Object>的第一位为该字符的类型(TYPE_NUMBER, TYPE_CHARACTER),第二位为该字符的内容
|
||||
*/
|
||||
private static List<List<Object>> getCharList(String text) {
|
||||
char[] chars = text.toCharArray();
|
||||
List<List<Object>> charList = new ArrayList<>();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
// 是否为数字
|
||||
char c = chars[i];
|
||||
if ((int) c >= '0' && (int) c <= '9') {
|
||||
StringBuilder str = new StringBuilder();
|
||||
// 下一位是否为数字,如果为数字则组成多位数
|
||||
do {
|
||||
str.append(c);
|
||||
if (i + 1 < chars.length) {
|
||||
c = chars[++i];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while ((int) c >= '0' && (int) c <= '9');
|
||||
if (!(i + 1 == chars.length) || !((int) c >= '0' && (int) c <= '9')) {
|
||||
i--;
|
||||
}
|
||||
list.add(TYPE_NUMBER);
|
||||
list.add(str.toString());
|
||||
} else {
|
||||
list.add(TYPE_CHARACTER);
|
||||
list.add(String.valueOf(c));
|
||||
}
|
||||
charList.add(list);
|
||||
}
|
||||
return charList;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ import java.security.MessageDigest;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Utils {
|
||||
|
|
@ -28,11 +29,7 @@ public class Utils {
|
|||
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36";
|
||||
public static final String ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
|
||||
public static final List<String> MEDIA = Arrays.asList("mp4", "mkv", "wmv", "flv", "avi", "mp3", "aac", "flac", "m4a", "ape", "ogg");
|
||||
public static final Pattern RULE = Pattern.compile(
|
||||
"http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|" +
|
||||
"http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|" +
|
||||
"http((?!http).)*?video/tos*"
|
||||
);
|
||||
public static final Pattern RULE = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|" + "http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|" + "http((?!http).)*?video/tos*");
|
||||
|
||||
public static boolean isVip(String url) {
|
||||
List<String> hosts = Arrays.asList("iqiyi.com", "v.qq.com", "youku.com", "le.com", "tudou.com", "mgtv.com", "sohu.com", "acfun.cn", "bilibili.com", "baofeng.com", "pptv.com");
|
||||
|
|
@ -194,4 +191,14 @@ public class Utils {
|
|||
webView.loadUrl(url);
|
||||
});
|
||||
}
|
||||
|
||||
public static int getDigit(String text) {
|
||||
try {
|
||||
Matcher matcher = Pattern.compile(".*(1080|720|2160|4k|4K).*").matcher(text);
|
||||
if (matcher.find()) text = matcher.group(1) + text;
|
||||
return Integer.parseInt(text.replaceAll("\\D+", ""));
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
22b3579498649b93fdfa3aab84792568
|
||||
d6c739a2667fdb4ca2c014821641a001
|
||||
|
|
|
|||
Loading…
Reference in New Issue