阿里云盘相关接口
public static class AliDriver {
/**
* 阿里云盘-总存储信息
* {"drive_used_size":854945910430,"drive_total_size":9440338116608,"default_drive_used_size":854945910430,"album_drive_used_size":0,"share_album_drive_used_size":0,"note_drive_used_size":0,"sbox_drive_used_size":0}
*/
public static Map<String, Object> aliDriverCapacityDetails(String auth) throws IOException {
String refreshUrl = " https://api.aliyundrive.com/adrive/v1/user/driveCapacityDetails";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, JSON.toJSONString(new ReqeustMapBuilder().build()));
Request.Builder request = getRequest(refreshUrl)
.addHeader("Authorization", auth)
.post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
return JSONUtil.toBean(responseStr, HashMap.class);
}
/**
* 阿里云盘-单个文件删除
*
* @return {"domain_id":"bj29","drive_id":"523799202","file_id":"63e0b3aa5450b94286944be7befadda9f7da56e8","async_task_id":"63e0b3aa5450b94286944be7befadda9f7da56e8trash77fe1b1751754ff4b4881bea3921c4be"}
*/
public static Map<String, Object> aliDriverRecyclebinTrash(String auth, String driveId, String fileId) throws IOException {
String refreshUrl = "https://api.aliyundrive.com/v2/recyclebin/trash";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, JSON.toJSONString(new ReqeustMapBuilder().put("drive_id", driveId).put("file_id", fileId).build()));
Request.Builder request = getRequest(refreshUrl)
.addHeader("Authorization", auth)
.post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
return JSONUtil.toBean(responseStr, HashMap.class);
}
/**
* 阿里云盘-批量 删除
* @param auth
* @param driveId
* @param fileIds
* @return
* @throws IOException
*/
public static Map<String, Object> aliDriverRecyclebinTrashBatch(String auth, String driveId, List<String> fileIds) throws IOException {
while (!fileIds.isEmpty()){
List<String> name = fileIds.stream().limit(20).collect(Collectors.toList());
fileIds.removeAll(name);
splitTrashBatch(auth,driveId,name);
}
return splitTrashBatch(auth, driveId, fileIds);
}
private static HashMap splitTrashBatch(String auth, String driveId, List<String> fileIds) throws IOException {
String refreshUrl = "https://api.aliyundrive.com/v2/batch";
if (fileIds == null || fileIds.size() ==0){
return null;
}
final String singleNativeJsonStr="{\"body\":{\"drive_id\":\"xxx\",\"file_id\":\"xxx\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"xxx\",\"method\":\"POST\",\"url\":\"/recyclebin/trash\"}";
JSONArray requests = new JSONArray();
for (String fileId : fileIds) {
JSONObject request = new JSONObject();
JSONObject body = new JSONObject();
JSONObject heads = new JSONObject();
body.put("drive_id", driveId);
body.put("file_id",fileId);
heads.put("Content-Type","application/json");
request.put("body",body);
request.put("headers",heads);
request.put("id",fileId);
request.put("method","POST");
request.put("url","/recyclebin/trash");
requests.add(request);
}
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, JSON.toJSONString(new ReqeustMapBuilder().put("requests", requests).put("resource", "file").build()));
Request.Builder request = getRequest(refreshUrl)
.addHeader("Authorization", auth)
.post(requestBody);
Response response = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT)).readTimeout(3, TimeUnit.MINUTES).build().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
return JSONUtil.toBean(responseStr, HashMap.class);
}
/**
* 阿里云盘-刷新token
*/
public static Map<String, Object> aliDriverRefresh(String refreshToken) throws IOException {
String refreshUrl = "https://api.aliyundrive.com/token/refresh";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, JSON.toJSONString(new ReqeustMapBuilder().put("refresh_token", refreshToken).build()));
Request.Builder request = getRequest(refreshUrl)
.post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
return JSONUtil.toBean(responseStr, HashMap.class);
}
/**
* 阿里云盘-列表
*
* @param driveId
* @return
* @throws IOException {
* "drive_id": "38050990",
* "domain_id": "bj29",
* "file_id": "623c867d3a21129cd096482ba8aa7480f650cefd",
* "name": "计算机课程",
* "type": "folder",
* "created_at": "2022-03-24T14:55:57.463Z",
* "updated_at": "2022-12-04T06:59:44.489Z",
* "hidden": false,
* "starred": false,
* "status": "available",
* "parent_file_id": "638c43cc66b07aab20db423ca6f9da305969c3ed",
* "encrypt_mode": "none",
* "creator_type": "User",
* "creator_id": "d65525acf3de444e91fd67cf2bcafd0d",
* "last_modifier_type": "User",
* "last_modifier_id": "d65525acf3de444e91fd67cf2bcafd0d",
* "sync_flag": false,
* "sync_device_flag": false,
* "sync_meta": ""
* }
*/
public static Pair<List<JSONObject>, String> listInfo(String auth, String pathId, String driveId) throws IOException {
String url = "https://api.aliyundrive.com/adrive/v3/file/list?jsonmask=next_marker%2Citems(name%2Cfile_id%2Cdrive_id%2Ctype%2Csize%2Ccreated_at%2Cupdated_at%2Ccategory%2Cfile_extension%2Cparent_file_id%2Cmime_type%2Cstarred%2Cthumbnail%2Curl%2Cstreams_info%2Ccontent_hash%2Cuser_tags%2Cuser_meta%2Ctrashed%2Cvideo_media_metadata%2Cvideo_preview_metadata%2Csync_meta%2Csync_device_flag%2Csync_flag%2Cpunish_flag)";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, "{\"drive_id\":\"" + driveId + "\",\"parent_file_id\":\"" + pathId + "\",\"limit\":100,\"all\":false,\"url_expire_sec\":14400,\"image_thumbnail_process\":\"image/resize,w_256/format,jpeg\",\"image_url_process\":\"image/resize,w_1920/format,jpeg/interlace,1\",\"video_thumbnail_process\":\"video/snapshot,t_1000,f_jpg,ar_auto,w_256\",\"fields\":\"*\",\"order_by\":\"updated_at\",\"order_direction\":\"DESC\"}"); // TODO
Request.Builder request = getRequest(url)
.addHeader("Authorization", auth)
.post(requestBody);
Response response = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT)).readTimeout(5, TimeUnit.MINUTES).build().newCall(request.build()).execute(); // 获取列表超时
String responseStr = new String(response.body().bytes(), "UTF-8");
JSONObject data = JSON.parseObject(responseStr);
return new Pair(new Result<JSONObject>().getResultArry(responseStr, "items", JSONObject.class), new Result<String>().getResulType(responseStr, String.class, "next_marker"));
}
/**
* @param auth
* @param pathId
* @param driveId
* @return
* @throws IOException
*/
public static List<JSONObject> listInfoAll(String auth, String pathId, String driveId) throws IOException {
List<JSONObject> allFiles = Lists.newArrayList();
Pair<List<JSONObject>, String> initPage = listInfo(auth, pathId, driveId);
allFiles.addAll(initPage.getValue0());
if (StringUtils.isBlank(initPage.getValue1())) {
return allFiles;
}
// 翻页
StringBuilder mark = new StringBuilder(initPage.getValue1());
while (!StringUtils.isBlank(mark)) {
initPage = alidriverPeerPageInfo(auth, pathId, driveId, initPage.getValue1());
mark = new StringBuilder(initPage.getValue1());
allFiles.addAll(initPage.getValue0());
}
return allFiles;
}
private static Pair<List<JSONObject>, String> alidriverPeerPageInfo(String auth, String pathId, String driveId, String marker) throws IOException {
String url = "https://api.aliyundrive.com/adrive/v3/file/list?jsonmask=next_marker%2Citems(name%2Cfile_id%2Cdrive_id%2Ctype%2Csize%2Ccreated_at%2Cupdated_at%2Ccategory%2Cfile_extension%2Cparent_file_id%2Cmime_type%2Cstarred%2Cthumbnail%2Curl%2Cstreams_info%2Ccontent_hash%2Cuser_tags%2Cuser_meta%2Ctrashed%2Cvideo_media_metadata%2Cvideo_preview_metadata%2Csync_meta%2Csync_device_flag%2Csync_flag%2Cpunish_flag)";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, "{\"drive_id\":\"" + driveId + "\",\"parent_file_id\":\"" + pathId + "\",\"limit\":" + 100 + ",\"all\":" + false + ",\"url_expire_sec\":14400,\"image_thumbnail_process\":\"image/resize,w_256/format,jpeg\",\"image_url_process\":\"image/resize,w_1920/format,jpeg/interlace,1\",\"video_thumbnail_process\":\"video/snapshot,t_1000,f_jpg,ar_auto,w_256\",\"fields\":\"*\",\"order_by\":\"updated_at\",\"order_direction\":\"DESC\",\"marker\":\"" + marker + "\"}"); // TODO
Request.Builder request = getRequest(url)
.addHeader("Authorization", auth)
.post(requestBody);
Response response = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT)).readTimeout(5, TimeUnit.MINUTES).build().newCall(request.build()).execute(); // 获取列表超时
String responseStr = new String(response.body().bytes(), "UTF-8");
JSONObject data = JSON.parseObject(responseStr);
List<JSONObject> items = new Result<JSONObject>().getResultArry(responseStr, "items", JSONObject.class);
final String nextMarker = new Result<String>().getResulType(responseStr, String.class, "next_marker");
return new Pair(items, nextMarker);
}
/**
* 阿里云盘-回收站回收
*
* @param driveId
* @return
* @throws IOException
*/
public static boolean aliDriverRecycleClear(String auth, String driveId) throws IOException {
String url = "https://api.aliyundrive.com/v2/recyclebin/clear";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, "{\"drive_id\":\"" + driveId + "\"}"); // TODO
Request.Builder request = getRequest(url)
.addHeader("Authorization", auth)
.post(requestBody);
Response response = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT)).readTimeout(5, TimeUnit.MINUTES).build().newCall(request.build()).execute(); // 获取列表超时
String responseStr = new String(response.body().bytes(), "UTF-8");
JSONObject data = JSON.parseObject(responseStr);
return data.containsKey("task_id");
}
/**
* 阿里云盘-链接转存
*
* @param link 链接地址
* @param auth 认证code
* @param savePath 保存路径
* @param driveId driveId
* @return
* @throws IOException
*/
public static boolean aliDriverSaveShareUrl(String link, String auth, String savePath, String driveId) throws IOException {
//获取分享链接code
String shareCode = getShareCodStr(link);
// 获取保存文件的id 集合
ArrayList<String> listFileIds = getAliDriverShareFileIds(auth, shareCode);
String shareToken = getShareToken(shareCode); // 保存文件的token获取
for (String fileId : listFileIds) {
// 保存fileId
try {
String navieRequestStr = "{\"requests\": [{\"body\":{\"file_id\":\"" + fileId + "\",\"share_id\":\"" + shareCode + "\",\"auto_rename\":true,\"to_parent_file_id\":\"" + savePath + "\",\"to_drive_id\":\"" + driveId + "\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"0\",\"method\":\"POST\",\"url\":\"/file/copy\"}],\"resource\":\"file\"}";
String saveRequestUrl = "https://api.aliyundrive.com/adrive/v2/batch";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, navieRequestStr);
Request.Builder request = getRequest(saveRequestUrl).addHeader("Authorization", auth)
.addHeader("Accept-Encoding", "gzip,deflate,br")
.addHeader("x-share-token", shareToken)
.post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
System.out.println(responseStr);
//example:
// {"responses": [{"id":"0","status":202,"body":{"async_task_id":"07730dfe-4eb3-436b-bafc-9d770248d8ed","domain_id":"bj29","drive_id":"38050990","file_id":"63de7a0b234d53c0c2c749418d0230d6bebd05ab"}}]}
// Integer status = new Result<Integer>().getResulType(responseStr, Integer.class, "responses.status");
} catch (IOException e) {
return false;
}
}
return true;
}
public static String getShareCodStr(String link) {
String shareCode = StrUtil.subAfter(link, "/", true);
return shareCode;
}
public static String getShareToken(String shareCode) throws IOException {
String shareTokenUrl = "https://api.aliyundrive.com/v2/share_link/get_share_token";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, "{\"share_id\":\"" + shareCode + "\",\"share_pwd\":\"\"}"); // TODO
Request.Builder request = getRequest(shareTokenUrl)
.addHeader("Accept-Encoding", "gzip,deflate,br")
.post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
System.out.println(responseStr);
return new Result<String>().getResulType(responseStr, String.class, "share_token");
// return shareToken;
}
/**
* {
* "creator_id": "7d9a030de34c47b9ae5491627cf28a11",
* "creator_name": "n***s",
* "creator_phone": "180***026",
* "expiration": "",
* "updated_at": "2023-02-05T10:41:40.752Z",
* "vip": "non-vip",
* "avatar": "https://img.aliyundrive.com/avatar/acfd692d37494462a75dec69872d74c9.jpeg",
* "share_name": "欧美",
* "file_count": 1,
* "is_creator_followable": true,
* "is_following_creator": false,
* "display_name": "欧美",
* "share_title": "欧美",
* "has_pwd": false,
* "save_button": {
* "text": "保存到我的云盘",
* "select_all_text": "全部保存到我的云盘"
* },
* "file_infos": [
* {
* "type": "folder",
* "file_id": "6183d6882da976b637ad4dc2a91e38b39cee4b26",
* "file_name": "欧美"
* }
* ]
* }
*
* @param auth
* @param shareCode
* @return
* @throws IOException
*/
public static List<Map<String, String>> getAliDriverShareFileInfo(String auth, String shareCode) throws IOException {
// 获取分享链接信息
String getShareInfo = "https://api.aliyundrive.com/adrive/v3/share_link/get_share_by_anonymous?share_id=" + shareCode;
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, JSON.toJSONString(new ReqeustMapBuilder().put("share_id", shareCode).build()));
Request.Builder request = getRequest(getShareInfo).addHeader("Authorization", auth).post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
List<Map<String, String>> fileInfos = new Result<Map<String, String>>().getResultArryByKeySplitDone(responseStr, Map.class, "file_infos");
return fileInfos;
}
public static ArrayList<String> getAliDriverShareFileIds(String auth, String shareCode) throws IOException {
final List<Map<String, String>> fileInfos = getAliDriverShareFileInfo(auth, shareCode);
/*保存文件的文件id集合*/
final ArrayList<String> listFileIds = Lists.newArrayList();
fileInfos.forEach(item -> {
listFileIds.add(item.get("file_id"));
});
return listFileIds;
}
}
网盘资源接口
/**
* 云盘-资源搜索
*
* @param keyword
* @return
*/
public static List<String> searchCloud(String keyword) {
final ArrayList<String> result = Lists.newArrayList();
try {
searchAliPanCloud(keyword, result);
} catch (Exception e) {
log.error(e.getMessage());
}
try {
result.addAll(searchCloudWebsiteInNmmeCC(keyword)); // searchCloudWebsiteInNmmeCC 下一个平台
} catch (Exception e) {
log.error(e.getMessage());
}
if (CollectionUtil.isEmpty(result)) {
try {
result.addAll(searchCloudWebsiteInlzpan(keyword));// searchCloudWebsiteInlzpan 下一个平台
} catch (Exception e) {
log.error(e.getMessage());
}
}
try {
checkCloudPanShareLink(result);// 过滤无效 链接
} catch (Exception e) {
log.error(e.getMessage());
}
return result;
}
public static void searchAliPanCloud(String keyword, List<String> result) {
String url = main_url + "/search?k=" + keyword;
Document jsoupDocument = getJsoupDocument(HttpUtil.get(url));
try {
final Elements select = jsoupDocument.body().select("van-row a");
for (Element element : select) {
String href = element.attr("href");
if (href.startsWith("https") || href.startsWith("http")) continue;
final String downUrl = main_url + href;
Document jsoupDocument2 = getJsoupDocument(HttpUtil.get(downUrl));
Elements scripts = jsoupDocument2.body().getElementsByTag("script");
for (Element script : scripts) {
if (script.toString().contains("window.open(") && script.toString().contains("target")) {
final String s = StrUtil.subBetween(script.toString(), "window.open(\"", "\",\"target\");");
final String getdirectUrl = main_url + s;
// 请求和的request对象获得云盘具体链接
OkHttpClient httpClient = new OkHttpClient();
Request request = new Request.Builder().get().url(getdirectUrl).removeHeader("User-Agent")
.addHeader("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36")
.addHeader("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.9")
.addHeader("X-Requested-With", "XMLHttpRequest")
.addHeader("Referer", getdirectUrl)
.addHeader("Cookie", "no_show_donate=1")
.build();
Response response = httpClient.newCall(request).execute();
String resultJSJson = response.request().url().toString();
response.close();
if (!resultJSJson.startsWith(main_url)) {
result.add(resultJSJson);
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage());
}
}
public static List<String> searchCloudWebsiteInNmmeCC(String keyword) {
String main_url = "https://www.nmme.cc/s/1/";
String url = main_url + URLUtil.encode(keyword);
final ArrayList<String> result = Lists.newArrayList();
try {
Request.Builder request = getRequestBuilder(url);
request.removeHeader("Referer").addHeader("Referer", url).removeHeader("Host").addHeader("Host", "www.nmme.cc");
Response execute = getOkHttp().newCall(request.get().build()).execute();
final byte [] bytes = execute.body().bytes();
execute.close();
Document jsoupDocument = getJsoupDocument(new String(bytes));
final Elements select = jsoupDocument.body().select(".wrapper a");
for (Element element : select) {
if (!element.hasAttr("data-url")) continue;
try {
// 请求获取搜索结果 链接
String attr = element.attr("data-url");
String password = element.attr("data-code");
// String type = element.attr("data-type");
// String title = element.attr("data-title");
request.removeHeader("Referer").removeHeader("Cookie").addHeader("Referer", url)
.url("https://www.nmme.cc/open/other/" + attr).addHeader("Cookie", "no_show_donate=1").get();
Response response = getOkHttp().newCall(request.build()).execute();
byte [] urldownload = response.body().bytes();
response.close();
Document jsoupDocument1 = getJsoupDocument(new String(urldownload));
if (null == jsoupDocument1.head()) continue;
Elements children = jsoupDocument1.head().children().select("meta");
if (children.size() == 0) continue;
Optional<String> content = children.stream().filter(item -> item.hasAttr("http-equiv") && item.hasAttr("content") && item.attr("http-equiv").equals("refresh")).map(item -> item.attr("content").toString()).findFirst();
StringBuilder sb = new StringBuilder();
sb.append(content.get().replace("0;url=", ""));
if (StringUtils.isNotBlank(password) && !password.equals("无")) {
sb.append(" \t密码:");
sb.append(password);
}
result.add(sb.toString());
} catch (IOException e) {
log.error(e.getMessage());
}
}
} catch (Exception e) {
log.error(e.getMessage());
}
return result;
}
/**
* 懒盘搜索
*
* @param keyword
* @return
*/
public static List<String> searchCloudWebsiteInlzpan(String keyword) {
String main_url = "https://www.zhaokeya.com/search?q=" + keyword;
final ArrayList<String> result = Lists.newArrayList();
try {
Request.Builder request = getRequestBuilder(main_url);
request.removeHeader("Host");
Response response = getOkHttp().newCall(request.get().build()).execute();
final byte [] bytes = response.body().bytes();
response.close();
Document jsoupDocument = getJsoupDocument(new String(bytes));
final Elements select = jsoupDocument.body().select(".search ul li a");
for (Element element : select) {
if (!element.hasAttr("href")) continue;
try {
// 请求获取搜索结果 链接
String href = element.attr("href");
String title = element.attr("title");
try {
URI host = URLUtil.getHost(new URL(href));
} catch (Exception e) {
href = URLUtil.getHost(new URL(main_url)).toString() + href;
}
request.removeHeader("Referer").removeHeader("Cookie")
.url(href).get();
response = getOkHttp().newCall(request.build()).execute();
byte [] urldownload = response.body().bytes();
response.close();
Document jsoupDocument1 = getJsoupDocument(new String(urldownload));
if (null == jsoupDocument1.head()) continue;
Element children = jsoupDocument1.select(".content-hide-tips i div").first();
if (children == null) continue;
String resultText = children.text();
result.add(HtmlUtil.cleanHtmlTag(title) +
StringUtils.LF +
StrUtil.subBefore(resultText, "资源推荐", false));
} catch (IOException e) {
log.debug(e.getMessage());
}
}
} catch (Exception e) {
log.error(e.getMessage());
}
return result;
}
/**
* https://pan666.cn/
*
* @param type
* @return
*/
public static List<String> aliyunResosurceShareGet(String type) {
String address = "https://pan666.cn/";
if (type != null) {
address += type;
}
String main_url = address + "?sort=newest";
final ArrayList<String> result = Lists.newArrayList();
try {
Request.Builder request = getRequestBuilder(main_url);
request.removeHeader("Host");
Response response = getOkHttp().newCall(request.get().build()).execute();
final byte [] bytes = response.body().bytes();
response.close();
Document jsoupDocument = getJsoupDocument(new String(bytes));
final Elements select = jsoupDocument.body().select(".container ul li a");
for (Element element : select) {
if (!element.hasAttr("href")) continue;
try {
// 请求获取搜索结果 链接
String href = element.attr("href");
String title = element.text();
try {
URI host = URLUtil.getHost(new URL(href));
} catch (Exception e) {
href = URLUtil.getHost(new URL(main_url)).toString() + href;
}
request.removeHeader("Referer").removeHeader("Cookie")
.url(href).get();
response = getOkHttp().newCall(request.build()).execute();
byte [] urldownload = response.body().bytes();
response.close();
Document jsoupDocument1 = getJsoupDocument(new String(urldownload));
if (null == jsoupDocument1.head()) continue;
result.add(HtmlUtil.cleanHtmlTag(title) +
StringUtils.LF +
StrUtil.subBefore(jsoupDocument1.select(".Post-body").text(), "资源推荐", false));
} catch (IOException e) {
log.debug(e.getMessage());
}
}
} catch (Exception e) {
log.error(e.getMessage());
}
return result;
}
补充 Alist 接口
public static class AlistUtil {
private String websiteUrl; // 网站地址
private String authToken; // 登录认证token
public AlistUtil websiteUrl(String websiteUrl) {
this.websiteUrl = websiteUrl;
return this;
}
public AlistUtil authToken(String token) {
this.authToken = token;
return this;
}
/**
* alist 登录
*
* @param userName
* @param password
* @return
*/
public String getToken(String userName, String password) throws IOException {
String url = websiteUrl + "/api/auth/login";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, "{\"username\":\"" + userName + "\",\"password\":\"" + password + "\",\"otp_code\":\"\"}"); // TODO
Request.Builder request = getRequest(url)
.post(requestBody);
Response response = getSimpleOkHttp().newCall(request.build()).execute();
String responseStr = new String(response.body().bytes(), "UTF-8");
final JSONObject data = new Result<JSONObject>().getResultByKeySplitDone(responseStr, JSONObject.class, "data");
return data.getString("token");
}
/**
* alist 获取目录 -用于刷新目录
*
* @param path
* @param refresh 是否刷新目录
* @param pathPassword
* @return {
* "name": "2023春晚",
* "size": 0,
* "is_dir": true,
* "modified": "2023-01-23T02:19:24.373Z",
* "sign": "",
* "thumb": "",
* "type": 1
* }
*/
public List<JSONObject> dirList(String path, boolean refresh, String pathPassword) throws IOException {
String url = websiteUrl + "/api/fs/list";
RequestBody requestBody = FormBody.create(
MediaType.parse("application/json; charset=utf-8")
, "{\"path\":\"" + path + "\",\"password\":\"" + pathPassword + "\",\"page\":1,\"per_page\":0,\"refresh\":" + refresh + "}"); // TODO
Request.Builder request = getRequest(url)
.addHeader("Authorization", this.authToken)
.post(requestBody);
Response response = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT)).readTimeout(5, TimeUnit.MINUTES).build().newCall(request.build()).execute(); // 获取列表超时
String responseStr = new String(response.body().bytes(), "UTF-8");
List<JSONObject> data = new Result<JSONObject>().getResultArryByKeySplitDone(responseStr, JSONObject.class, "data.content");
return data;
}
}
最后于 2023-2-7
被wangfei编辑
,原因: 添加alist接口
这家伙太懒了,什么也没留下。
➦
收藏的用户(1)
X
正在加载信息~
相关推荐
实现阿里云盘自动存储网络资源2023-02-07
群红包可以自动抢吗?2022-09-17
线报url内容获取2022-12-14
网购线报(hxm5.com)抓取 java,群里看到的。感觉还可以2022-12-10
java 对于图片撤退的实现。小弟实现的复杂,有大佬可以指点下2022-10-11
发新帖
主题数 5 |
帖子数 8 |
0 精华数 |
注册排名 256 |