Update ali
This commit is contained in:
parent
2bc87bccf6
commit
9d6201cb6f
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Item(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item(String id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(String fileName) {
|
||||||
|
return TextUtils.isEmpty(name) ? fileName : "[" + name + "] " + fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import android.text.TextUtils;
|
||||||
|
|
||||||
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.ali.Item;
|
||||||
import com.github.catvod.net.OkHttpUtil;
|
import com.github.catvod.net.OkHttpUtil;
|
||||||
import com.github.catvod.utils.Misc;
|
import com.github.catvod.utils.Misc;
|
||||||
import com.github.catvod.utils.Trans;
|
import com.github.catvod.utils.Trans;
|
||||||
|
|
@ -92,7 +93,7 @@ public class Ali {
|
||||||
JSONObject object = new JSONObject(json);
|
JSONObject object = new JSONObject(json);
|
||||||
Map<String, String> name2id = new HashMap<>();
|
Map<String, String> name2id = new HashMap<>();
|
||||||
Map<String, List<String>> subMap = new HashMap<>();
|
Map<String, List<String>> subMap = new HashMap<>();
|
||||||
listFiles(0, name2id, subMap, shareId, shareToken, getParentFileId(fileId, object));
|
listFiles(new Item(getParentFileId(fileId, object)), name2id, subMap, shareId, shareToken);
|
||||||
List<String> playUrls = new ArrayList<>();
|
List<String> playUrls = new ArrayList<>();
|
||||||
List<String> names = new ArrayList<>(name2id.keySet());
|
List<String> names = new ArrayList<>(name2id.keySet());
|
||||||
Collections.sort(names);
|
Collections.sort(names);
|
||||||
|
|
@ -111,12 +112,12 @@ public class Ali {
|
||||||
return vod;
|
return vod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listFiles(int level, Map<String, String> name2id, Map<String, List<String>> subMap, String shareId, String shareToken, String parentFileId) throws Exception {
|
private void listFiles(Item folder, Map<String, String> name2id, Map<String, List<String>> subMap, String shareId, String shareToken) throws Exception {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("marker", "");
|
body.put("marker", "");
|
||||||
body.put("limit", 200);
|
body.put("limit", 200);
|
||||||
body.put("share_id", shareId);
|
body.put("share_id", shareId);
|
||||||
body.put("parent_file_id", parentFileId);
|
body.put("parent_file_id", folder.getId());
|
||||||
body.put("order_by", "updated_at");
|
body.put("order_by", "updated_at");
|
||||||
body.put("order_direction", "DESC");
|
body.put("order_direction", "DESC");
|
||||||
body.put("image_url_process", "image/resize,w_1920/format,jpeg");
|
body.put("image_url_process", "image/resize,w_1920/format,jpeg");
|
||||||
|
|
@ -124,7 +125,6 @@ public class Ali {
|
||||||
body.put("video_thumbnail_process", "video/snapshot,t_1000,f_jpg,ar_auto,w_300");
|
body.put("video_thumbnail_process", "video/snapshot,t_1000,f_jpg,ar_auto,w_300");
|
||||||
String json = post("adrive/v3/file/list", body, shareToken);
|
String json = post("adrive/v3/file/list", body, shareToken);
|
||||||
JSONArray items = new JSONObject(json).getJSONArray("items");
|
JSONArray items = new JSONObject(json).getJSONArray("items");
|
||||||
List<String> folders = new ArrayList<>();
|
|
||||||
for (int j = 0; j < items.length(); ++j) {
|
for (int j = 0; j < items.length(); ++j) {
|
||||||
JSONObject item = items.getJSONObject(j);
|
JSONObject item = items.getJSONObject(j);
|
||||||
String type = item.optString("type");
|
String type = item.optString("type");
|
||||||
|
|
@ -133,11 +133,11 @@ public class Ali {
|
||||||
String category = item.optString("category", "");
|
String category = item.optString("category", "");
|
||||||
String ext = item.optString("file_extension", "");
|
String ext = item.optString("file_extension", "");
|
||||||
if (type.equals("folder")) {
|
if (type.equals("folder")) {
|
||||||
folders.add(fileId);
|
listFiles(new Item(fileId, name), name2id, subMap, shareId, shareToken);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (category.equals("video")) {
|
if (category.equals("video")) {
|
||||||
name2id.put(name, shareId + "+" + shareToken + "+" + fileId);
|
name2id.put(folder.getName(name), shareId + "+" + shareToken + "+" + fileId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Misc.isSub(ext)) {
|
if (Misc.isSub(ext)) {
|
||||||
|
|
@ -146,10 +146,6 @@ public class Ali {
|
||||||
Objects.requireNonNull(subMap.get(name)).add(name + "@" + fileId + "@" + ext);
|
Objects.requireNonNull(subMap.get(name)).add(name + "@" + fileId + "@" + ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String folder : folders) {
|
|
||||||
if (level == 2) break;
|
|
||||||
listFiles(++level, name2id, subMap, shareId, shareToken, folder);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParentFileId(String fileId, JSONObject shareInfo) throws Exception {
|
private String getParentFileId(String fileId, JSONObject shareInfo) throws Exception {
|
||||||
|
|
@ -248,6 +244,7 @@ public class Ali {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("file_id", fileId);
|
body.put("file_id", fileId);
|
||||||
body.put("share_id", shareId);
|
body.put("share_id", shareId);
|
||||||
|
body.put("expire_sec", 600);
|
||||||
String json = post("v2/file/get_share_link_download_url", body, shareToken);
|
String json = post("v2/file/get_share_link_download_url", body, shareToken);
|
||||||
String url = new JSONObject(json).optString("download_url");
|
String url = new JSONObject(json).optString("download_url");
|
||||||
Map<String, List<String>> respHeaders = new HashMap<>();
|
Map<String, List<String>> respHeaders = new HashMap<>();
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
5c71cb0dd237522712e08afea49d8cf1
|
f3c52e97a91a4d972225a8e2f8c2d81e
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue