Update ali
This commit is contained in:
parent
d60c632ca4
commit
264aabe21c
|
|
@ -2,25 +2,77 @@ package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
|
||||||
private String id;
|
@SerializedName("items")
|
||||||
|
private List<Item> items;
|
||||||
|
@SerializedName("next_marker")
|
||||||
|
private String nextMarker;
|
||||||
|
|
||||||
|
@SerializedName("file_id")
|
||||||
|
private String fileId;
|
||||||
|
@SerializedName("share_id")
|
||||||
|
private String shareId;
|
||||||
|
@SerializedName("name")
|
||||||
private String name;
|
private String name;
|
||||||
|
@SerializedName("type")
|
||||||
|
private String type;
|
||||||
|
@SerializedName("file_extension")
|
||||||
|
private String fileExtension;
|
||||||
|
@SerializedName("category")
|
||||||
|
private String category;
|
||||||
|
|
||||||
public Item(String id) {
|
public static Item objectFrom(String str) {
|
||||||
this.id = id;
|
return new Gson().fromJson(str, Item.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item(String id, String name) {
|
public Item(String fileId) {
|
||||||
this.id = id;
|
this.fileId = fileId;
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public List<Item> getItems() {
|
||||||
return id;
|
return items == null ? Collections.emptyList() : items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(String fileName) {
|
public String getNextMarker() {
|
||||||
return TextUtils.isEmpty(name) ? fileName : "[" + name + "] " + fileName;
|
return TextUtils.isEmpty(nextMarker) ? "" : nextMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileId() {
|
||||||
|
return TextUtils.isEmpty(fileId) ? "" : fileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShareId() {
|
||||||
|
return TextUtils.isEmpty(shareId) ? "" : shareId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return TextUtils.isEmpty(name) ? "" : name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return TextUtils.isEmpty(type) ? "" : type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExt() {
|
||||||
|
return TextUtils.isEmpty(fileExtension) ? "" : fileExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return TextUtils.isEmpty(category) ? "" : category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName(String fileName) {
|
||||||
|
return getName().isEmpty() ? fileName : "[" + getName() + "] " + fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String removeExt() {
|
||||||
|
return getName().indexOf(".") > 0 ? getName().substring(0, getName().lastIndexOf(".")) : getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,35 +128,36 @@ public class Ali {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listFiles(Item folder, LinkedHashMap<String, String> name2id, Map<String, List<String>> subMap, String shareId, String shareToken) throws Exception {
|
private void listFiles(Item folder, LinkedHashMap<String, String> name2id, Map<String, List<String>> subMap, String shareId, String shareToken) throws Exception {
|
||||||
|
listFiles(folder, name2id, subMap, shareId, shareToken, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listFiles(Item folder, LinkedHashMap<String, String> name2id, Map<String, List<String>> subMap, String shareId, String shareToken, String marker) throws Exception {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("share_id", shareId);
|
|
||||||
body.put("parent_file_id", folder.getId());
|
|
||||||
body.put("limit", 200);
|
body.put("limit", 200);
|
||||||
|
body.put("share_id", shareId);
|
||||||
|
body.put("parent_file_id", folder.getFileId());
|
||||||
body.put("order_by", "name");
|
body.put("order_by", "name");
|
||||||
body.put("order_direction", "ASC");
|
body.put("order_direction", "ASC");
|
||||||
String json = post("adrive/v3/file/list", body, shareToken);
|
if (marker.length() > 0) body.put("marker", marker);
|
||||||
JSONArray items = new JSONObject(json).getJSONArray("items");
|
Item item = Item.objectFrom(post("adrive/v3/file/list", body, shareToken));
|
||||||
for (int j = 0; j < items.length(); ++j) {
|
for (Item file : item.getItems()) {
|
||||||
JSONObject item = items.getJSONObject(j);
|
if (file.getType().equals("folder")) {
|
||||||
String type = item.optString("type");
|
listFiles(file, name2id, subMap, shareId, shareToken);
|
||||||
String name = item.optString("name");
|
|
||||||
String fileId = item.optString("file_id");
|
|
||||||
String category = item.optString("category", "");
|
|
||||||
String ext = item.optString("file_extension", "");
|
|
||||||
if (type.equals("folder")) {
|
|
||||||
listFiles(new Item(fileId, name), name2id, subMap, shareId, shareToken);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (category.equals("video")) {
|
if (file.getCategory().equals("video")) {
|
||||||
name2id.put(folder.getName(name), shareId + "+" + shareToken + "+" + fileId);
|
name2id.put(folder.getDisplayName(file.getName()), shareId + "+" + shareToken + "+" + file.getFileId());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Misc.isSub(ext)) {
|
if (Misc.isSub(file.getExt())) {
|
||||||
name = name.replace("." + ext, "");
|
String name = file.removeExt();
|
||||||
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 + "@" + file.getFileId() + "@" + file.getExt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (item.getNextMarker().length() > 0) {
|
||||||
|
listFiles(folder, name2id, subMap, shareId, shareToken, item.getNextMarker());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParentFileId(String fileId, JSONObject shareInfo) throws Exception {
|
private String getParentFileId(String fileId, JSONObject shareInfo) throws Exception {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
bc6e5b7707f34cfff705465420176d2f
|
e1ce4a638a2dbef8dd09c6ce07ba7da1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue