mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-08-26 19:42:02 +00:00
Compare commits
11 Commits
v0.4.2
...
b5f7d9694b
| Author | SHA1 | Date | |
|---|---|---|---|
| b5f7d9694b | |||
| f75d9f687b | |||
| 703bfa3061 | |||
| 6c709fde65 | |||
| 449fd741ac | |||
| c18b8d80e1 | |||
| 06ba0aff52 | |||
| 74e401d99c | |||
| 4995bca901 | |||
| 7299fd8762 | |||
| efbadde4ed |
@@ -28,25 +28,31 @@ QQ交流群:1017480890
|
|||||||
[公益解析,lz0站](https://lz0.qaiu.top)
|
[公益解析,lz0站](https://lz0.qaiu.top)
|
||||||
[专业版](https://189.qaiu.top)
|
[专业版](https://189.qaiu.top)
|
||||||
|
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
命令行下载分享文件:
|
|
||||||
```shell
|
|
||||||
curl -LOJ "https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/Tk1F2kGQ&pwd=1234"
|
|
||||||
```
|
|
||||||
或者使用wget:
|
|
||||||
```shell
|
|
||||||
wget -O bilibili.mp4 "https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/Tk1F2kGQ&pwd=1234"
|
|
||||||
```
|
|
||||||
或者使用浏览器[直接访问](https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fparser%3Furl%3Dhttps%3A%2F%2Fwww.ilanzou.com%2Fs%2FCDx6xKbT&name=bilibili.mp4&ext=mp4):
|
|
||||||
```
|
|
||||||
### 调用演示站下载:
|
|
||||||
https://lz.qaiu.top/parser?url=https://www.ilanzou.com/s/CDx6xKbT&pwd=1234
|
|
||||||
### 调用演示站预览:
|
|
||||||
https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fparser%3Furl%3Dhttps%3A%2F%2Fwww.ilanzou.com%2Fs%2FCDx6xKbT&name=bilibili.mp4&ext=mp4
|
|
||||||
|
|
||||||
|
以带提取码的分享链接为例(提取码 `1234`),链接中含 `#`、`&`,作为 `url` 参数传入前必须做 URL 编码:
|
||||||
|
|
||||||
|
`https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data=70017ece572737b12b30709b7f029308eJD0&isShare=1`
|
||||||
|
|
||||||
|
**命令行下载**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# curl
|
||||||
|
curl -LOJ "https://lz.qaiu.top/parser?url=https%3A%2F%2Fwww.ecpan.cn%2Fweb%2F%23%2FyunpanProxy%3Fpath%3D%252F%2523%252Fdrive%252Foutside%26data%3D70017ece572737b12b30709b7f029308eJD0%26isShare%3D1&pwd=1234"
|
||||||
|
|
||||||
|
# wget
|
||||||
|
wget -O v01 "https://lz.qaiu.top/parser?url=https%3A%2F%2Fwww.ecpan.cn%2Fweb%2F%23%2FyunpanProxy%3Fpath%3D%252F%2523%252Fdrive%252Foutside%26data%3D70017ece572737b12b30709b7f029308eJD0%26isShare%3D1&pwd=1234"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**短链方式**(key 取分享链接的 `data` 参数,提取码用 `@` 拼接)
|
||||||
|
|
||||||
|
| 用途 | 地址 |
|
||||||
|
| --- | --- |
|
||||||
|
| 下载 | `https://lz.qaiu.top/ec/70017ece572737b12b30709b7f029308eJD0@1234` |
|
||||||
|
| 在线预览 | [点击访问](https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fec%2F70017ece572737b12b30709b7f029308eJD0%401234&name=v01&ext=mp4) |
|
||||||
|
|
||||||
|
> 无提取码时去掉 `&pwd=1234` / `@1234` 即可;预览页 `src` 需编码(`@` → `%40`),用短链可避免二次编码。
|
||||||
|
|
||||||
**解析器模块文档:** [parser/README.md](parser/README.md)
|
**解析器模块文档:** [parser/README.md](parser/README.md)
|
||||||
|
|
||||||
**JavaScript解析器文档:** [JavaScript解析器开发指南](parser/doc/JAVASCRIPT_PARSER_GUIDE.md) | [自定义解析器扩展指南](parser/doc/CUSTOM_PARSER_GUIDE.md) | [快速开始](parser/doc/CUSTOM_PARSER_QUICKSTART.md)
|
**JavaScript解析器文档:** [JavaScript解析器开发指南](parser/doc/JAVASCRIPT_PARSER_GUIDE.md) | [自定义解析器扩展指南](parser/doc/CUSTOM_PARSER_GUIDE.md) | [快速开始](parser/doc/CUSTOM_PARSER_QUICKSTART.md)
|
||||||
@@ -133,6 +139,7 @@ GET /json/parser?url={分享链接}&pwd={密码}
|
|||||||
```
|
```
|
||||||
GET /json/{网盘标识}/{分享key}@{密码}
|
GET /json/{网盘标识}/{分享key}@{密码}
|
||||||
```
|
```
|
||||||
|
注意: 移动云云空间的 `分享key` 取分享链接中的 `data` 参数值
|
||||||
|
|
||||||
#### 3. 文件夹解析(v0.1.8fixed3+)
|
#### 3. 文件夹解析(v0.1.8fixed3+)
|
||||||
|
|
||||||
@@ -230,11 +237,6 @@ auths:
|
|||||||
|
|
||||||
如果只是临时调用一次,不想改动服务端配置,也可以用上面提到的 `auth` 参数临时传递(`authType` 可选 `password`/`accesstoken`/`authorization`),无需重启服务,仅本次请求生效。
|
如果只是临时调用一次,不想改动服务端配置,也可以用上面提到的 `auth` 参数临时传递(`authType` 可选 `password`/`accesstoken`/`authorization`),无需重启服务,仅本次请求生效。
|
||||||
|
|
||||||
### 特殊说明
|
|
||||||
|
|
||||||
- 移动云云空间的 `分享key` 取分享链接中的 `data` 参数值
|
|
||||||
- 移动云云空间、小飞机网盘的加密分享可忽略密码参数
|
|
||||||
|
|
||||||
### 示例
|
### 示例
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -455,8 +457,8 @@ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtow
|
|||||||
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
||||||
```shell
|
```shell
|
||||||
cd ~
|
cd ~
|
||||||
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v3.0.2/netdisk-fast-download-bin.zip
|
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v0.4.2/netdisk-fast-download-linux-amd64.zip
|
||||||
unzip netdisk-fast-download-bin.zip
|
unzip netdisk-fast-download.zip
|
||||||
cd netdisk-fast-download
|
cd netdisk-fast-download
|
||||||
bash service-install.sh
|
bash service-install.sh
|
||||||
```
|
```
|
||||||
@@ -544,11 +546,22 @@ Core模块集成Vert.x实现类似spring的注解式路由API
|
|||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## **免责声明**
|
|
||||||
- 用户在使用本项目时,应自行承担风险,并确保其行为符合当地法律法规。开发者不对用户因使用本项目而导致的任何后果负责。
|
|
||||||
|
|
||||||
## 支持该项目
|
## **声明**
|
||||||
开源不易,用爱发电,本项目长期维护如果觉得有帮助, 可以请作者喝杯咖啡, 感谢支持
|
|
||||||
|
- 本项目**仅供个人学习与技术交流使用**,请勿用于商业用途或大规模滥用。
|
||||||
|
- 所用接口均来自各网盘**官方开放平台**、官方公开接口及**已知开源项目**,仅解析用户主动提供的分享链接,**不涉及破解或绕过版权保护**。
|
||||||
|
- 本项目**相当于自动化程序代替用户发起请求**,**不会提升或绕过任何会员权限**,也**不会突破网盘的限速策略**;我们**鼓励用户开通官方 VIP/SVIP**以获得更好的下载与加速体验。
|
||||||
|
- 使用者应遵守各网盘服务商的**用户协议与使用条款**,以及所在地区的**法律法规**,违反所产生的后果自行承担。
|
||||||
|
- **高频调用可能触发网盘风控**,导致**账号限流、封禁**或**来源 IP 被屏蔽**,请合理控制请求频率,避免高并发与批量请求。
|
||||||
|
- 网盘接口调整、风控策略变更等因素可能导致功能失效,本项目**不对可用性与稳定性作任何担保**。
|
||||||
|
- 开发者**不对**使用本项目产生的**任何直接或间接损失**(账号封禁、数据丢失、法律纠纷等)**承担责任**。
|
||||||
|
- 开发者保留**随时修改本免责声明**的权利,恕不另行通知。
|
||||||
|
- **下载、部署或使用本项目,即视为您已阅读并接受上述全部条款。**
|
||||||
|
|
||||||
|
|
||||||
|
## 赞助该项目
|
||||||
|
开源不易,用爱发电,本项目长期维护如果觉得有帮助, 可以请开发者[喝杯咖啡](https://blog.qaiu.top/archives/da-shang-zhuan-yong), 感谢支持。
|
||||||
|
|
||||||
本项目的服务器由林枫云提供赞助<br>
|
本项目的服务器由林枫云提供赞助<br>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -382,9 +382,10 @@ public abstract class PanBase implements IPanTool, Closeable {
|
|||||||
log.error("响应gzip解压或JSON解析失败: {}", e.getMessage());
|
log.error("响应gzip解压或JSON解析失败: {}", e.getMessage());
|
||||||
fail("响应gzip解压或JSON解析失败: {}", e.getMessage());
|
fail("响应gzip解压或JSON解析失败: {}", e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
|
// 上游响应体可能来自内网探测目标,仅写日志,避免经 HTTP 500 回传给调用方
|
||||||
String bodyPreview = responseBodyPreview(res);
|
String bodyPreview = responseBodyPreview(res);
|
||||||
log.error("解析失败: json格式异常: {}", bodyPreview);
|
log.error("解析失败: json格式异常: {}", bodyPreview);
|
||||||
fail("解析失败: json格式异常: {}", bodyPreview);
|
fail("解析失败: json格式异常");
|
||||||
}
|
}
|
||||||
return JsonObject.of();
|
return JsonObject.of();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,9 +121,9 @@ public enum PanDomainTemplate {
|
|||||||
"https://lecloud.lenovo.com/share/{shareKey}",
|
"https://lecloud.lenovo.com/share/{shareKey}",
|
||||||
LeTool.class),
|
LeTool.class),
|
||||||
|
|
||||||
// https://v2.fangcloud.com/s/
|
// https://v2.fangcloud.com/s/ https://v2.fangcloud.cn/h5/share/ (移动端H5落地页)
|
||||||
FC("亿方云",
|
FC("亿方云",
|
||||||
compile("https://v2\\.fangcloud\\.(com|cn)/(s|share|sharing)/(?<KEY>.+)"),
|
compile("https://v2\\.fangcloud\\.(com|cn)/(?:h5/)?(s|share|sharing)/(?<KEY>.+)"),
|
||||||
"https://v2.fangcloud.com/s/{shareKey}",
|
"https://v2.fangcloud.com/s/{shareKey}",
|
||||||
"https://www.fangcloud.com/",
|
"https://www.fangcloud.com/",
|
||||||
FcTool.class),
|
FcTool.class),
|
||||||
|
|||||||
@@ -111,7 +111,8 @@ public class Ce4Tool extends PanBase {
|
|||||||
private void requestShareDetail(String baseUrl, String key, String pwd, String path) {
|
private void requestShareDetail(String baseUrl, String key, String pwd, String path) {
|
||||||
String shareApiUrl = baseUrl + SHARE_API_PATH + key;
|
String shareApiUrl = baseUrl + SHARE_API_PATH + key;
|
||||||
|
|
||||||
HttpRequest<Buffer> httpRequest = clientSession.getAbs(shareApiUrl);
|
// 禁止跟随重定向:防止公网 host 302 到内网/元数据绕过 assertPublicHost
|
||||||
|
HttpRequest<Buffer> httpRequest = clientNoRedirects.getAbs(shareApiUrl);
|
||||||
if (pwd != null && !pwd.isEmpty()) {
|
if (pwd != null && !pwd.isEmpty()) {
|
||||||
httpRequest.addQueryParam("password", pwd);
|
httpRequest.addQueryParam("password", pwd);
|
||||||
}
|
}
|
||||||
@@ -232,7 +233,7 @@ public class Ce4Tool extends PanBase {
|
|||||||
.put("uris", new JsonArray().add(filePath))
|
.put("uris", new JsonArray().add(filePath))
|
||||||
.put("download", true);
|
.put("download", true);
|
||||||
|
|
||||||
clientSession.postAbs(fileUrlApi)
|
clientNoRedirects.postAbs(fileUrlApi)
|
||||||
.putHeader("Content-Type", "application/json")
|
.putHeader("Content-Type", "application/json")
|
||||||
.sendJsonObject(requestBody)
|
.sendJsonObject(requestBody)
|
||||||
.onSuccess(res -> {
|
.onSuccess(res -> {
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ public class CeTool extends PanBase {
|
|||||||
private void tryV4Ping(String baseUrl, String key, String pwd) {
|
private void tryV4Ping(String baseUrl, String key, String pwd) {
|
||||||
String pingUrlV4 = baseUrl + PING_API_V4_PATH;
|
String pingUrlV4 = baseUrl + PING_API_V4_PATH;
|
||||||
|
|
||||||
clientSession.getAbs(pingUrlV4).send().onSuccess(res -> {
|
// 禁止跟随重定向:assertPublicHost 只校验初始 host,自动 30x 会绕过 SSRF 防护
|
||||||
|
clientNoRedirects.getAbs(pingUrlV4).send().onSuccess(res -> {
|
||||||
if (res.statusCode() == 200) {
|
if (res.statusCode() == 200) {
|
||||||
try {
|
try {
|
||||||
JsonObject json = asJson(res);
|
JsonObject json = asJson(res);
|
||||||
@@ -108,7 +109,7 @@ public class CeTool extends PanBase {
|
|||||||
private void tryV3Ping(String baseUrl, String key, String pwd) {
|
private void tryV3Ping(String baseUrl, String key, String pwd) {
|
||||||
String pingUrlV3 = baseUrl + PING_API_V3_PATH;
|
String pingUrlV3 = baseUrl + PING_API_V3_PATH;
|
||||||
|
|
||||||
clientSession.getAbs(pingUrlV3).send().onSuccess(res -> {
|
clientNoRedirects.getAbs(pingUrlV3).send().onSuccess(res -> {
|
||||||
if (res.statusCode() == 200) {
|
if (res.statusCode() == 200) {
|
||||||
try {
|
try {
|
||||||
JsonObject json = asJson(res);
|
JsonObject json = asJson(res);
|
||||||
@@ -139,7 +140,7 @@ public class CeTool extends PanBase {
|
|||||||
*/
|
*/
|
||||||
private void verifyV3AndParse(String baseUrl, String key, String pwd) {
|
private void verifyV3AndParse(String baseUrl, String key, String pwd) {
|
||||||
String shareApiUrl = baseUrl + SHARE_API_PATH + key;
|
String shareApiUrl = baseUrl + SHARE_API_PATH + key;
|
||||||
HttpRequest<Buffer> httpRequest = clientSession.getAbs(shareApiUrl);
|
HttpRequest<Buffer> httpRequest = clientNoRedirects.getAbs(shareApiUrl);
|
||||||
if (pwd != null && !pwd.isEmpty()) {
|
if (pwd != null && !pwd.isEmpty()) {
|
||||||
httpRequest.addQueryParam("password", pwd);
|
httpRequest.addQueryParam("password", pwd);
|
||||||
}
|
}
|
||||||
@@ -175,7 +176,7 @@ public class CeTool extends PanBase {
|
|||||||
*/
|
*/
|
||||||
private void tryV4ShareApi(String baseUrl, String key, String pwd) {
|
private void tryV4ShareApi(String baseUrl, String key, String pwd) {
|
||||||
String shareApiUrl = baseUrl + "/api/v4/share/info/" + key;
|
String shareApiUrl = baseUrl + "/api/v4/share/info/" + key;
|
||||||
HttpRequest<Buffer> httpRequest = clientSession.getAbs(shareApiUrl);
|
HttpRequest<Buffer> httpRequest = clientNoRedirects.getAbs(shareApiUrl);
|
||||||
if (pwd != null && !pwd.isEmpty()) {
|
if (pwd != null && !pwd.isEmpty()) {
|
||||||
httpRequest.addQueryParam("password", pwd);
|
httpRequest.addQueryParam("password", pwd);
|
||||||
}
|
}
|
||||||
@@ -291,7 +292,8 @@ public class CeTool extends PanBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getDownURL(String shareApiUrl) {
|
private void getDownURL(String shareApiUrl) {
|
||||||
clientSession.putAbs(shareApiUrl)
|
// PUT 默认不跟随重定向,但仍统一使用 no-redirect 客户端避免配置漂移
|
||||||
|
clientNoRedirects.putAbs(shareApiUrl)
|
||||||
.putHeader("Referer", shareLinkInfo.getShareUrl())
|
.putHeader("Referer", shareLinkInfo.getShareUrl())
|
||||||
.send().onSuccess(res -> {
|
.send().onSuccess(res -> {
|
||||||
JsonObject jsonObject = asJson(res);
|
JsonObject jsonObject = asJson(res);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class FcTool extends PanBase {
|
|||||||
|
|
||||||
public static final String SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/";
|
public static final String SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/";
|
||||||
public static final String SHARE_URL_PREFIX2 = "https://v2.fangcloud.cn/sharing/";
|
public static final String SHARE_URL_PREFIX2 = "https://v2.fangcloud.cn/sharing/";
|
||||||
|
private static final String SHARE_INFO_URL = "https://v2.fangcloud.cn/apps/share_links/info/";
|
||||||
private static final String DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download?file_id={fid}" +
|
private static final String DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download?file_id={fid}" +
|
||||||
"&scenario=share&unique_name={uname}";
|
"&scenario=share&unique_name={uname}";
|
||||||
|
|
||||||
@@ -38,6 +39,25 @@ public class FcTool extends PanBase {
|
|||||||
final String dataKey = shareLinkInfo.getShareKey();
|
final String dataKey = shareLinkInfo.getShareKey();
|
||||||
final String pwd = shareLinkInfo.getSharePassword();
|
final String pwd = shareLinkInfo.getSharePassword();
|
||||||
WebClientSession sClient = WebClientSession.create(client);
|
WebClientSession sClient = WebClientSession.create(client);
|
||||||
|
// 先查询分享有效性, 避免分享已失效/已过期时仍去解析HTML, 报出令人困惑的技术错误
|
||||||
|
sClient.getAbs(SHARE_INFO_URL + dataKey).send().onSuccess(infoRes -> {
|
||||||
|
JsonObject infoJson = asJson(infoRes);
|
||||||
|
if (promise.future().isComplete()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JsonObject process = infoJson.getJsonObject("process");
|
||||||
|
boolean isClosed = process != null && Boolean.TRUE.equals(process.getBoolean("is_closed"));
|
||||||
|
boolean isExpired = process != null && Boolean.TRUE.equals(process.getBoolean("is_expired"));
|
||||||
|
if (process == null || isClosed || isExpired) {
|
||||||
|
fail("分享已失效或不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doParse(dataKey, pwd, sClient);
|
||||||
|
}).onFailure(handleFail(SHARE_INFO_URL + dataKey));
|
||||||
|
return promise.future();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doParse(String dataKey, String pwd, WebClientSession sClient) {
|
||||||
// 第一次请求 自动重定向
|
// 第一次请求 自动重定向
|
||||||
sClient.getAbs(SHARE_URL_PREFIX + dataKey).send().onSuccess(res -> {
|
sClient.getAbs(SHARE_URL_PREFIX + dataKey).send().onSuccess(res -> {
|
||||||
|
|
||||||
@@ -67,7 +87,6 @@ public class FcTool extends PanBase {
|
|||||||
}
|
}
|
||||||
getDownURL(dataKey, promise, res, sClient);
|
getDownURL(dataKey, promise, res, sClient);
|
||||||
}).onFailure(handleFail(SHARE_URL_PREFIX + dataKey));
|
}).onFailure(handleFail(SHARE_URL_PREFIX + dataKey));
|
||||||
return promise.future();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDownURL(String dataKey, Promise<String> promise, HttpResponse<Buffer> res,
|
private void getDownURL(String dataKey, Promise<String> promise, HttpResponse<Buffer> res,
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package cn.qaiu.parser;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GHSA-997r-7xx2-p9x6 regression: Cloudreve generic parser must reject
|
||||||
|
* hosts that resolve to loopback / private / link-local / metadata ranges
|
||||||
|
* before any outbound request.
|
||||||
|
*/
|
||||||
|
public class AssertPublicHostTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rejectsLoopbackAndPrivateHosts() throws Exception {
|
||||||
|
String[] blocked = {
|
||||||
|
"http://127.0.0.1.nip.io/s/poc",
|
||||||
|
"http://localhost/s/poc",
|
||||||
|
"http://10.0.0.1/s/poc",
|
||||||
|
"http://192.168.1.1/s/poc",
|
||||||
|
"http://172.16.0.1/s/poc",
|
||||||
|
"http://169.254.169.254/s/poc",
|
||||||
|
"http://[::1]/s/poc"
|
||||||
|
};
|
||||||
|
for (String raw : blocked) {
|
||||||
|
try {
|
||||||
|
PanBase.assertPublicHost(new URL(raw));
|
||||||
|
fail("expected block for " + raw);
|
||||||
|
} catch (IOException expected) {
|
||||||
|
assertTrue(expected.getMessage().contains("不允许访问")
|
||||||
|
|| expected.getMessage().contains("无法解析"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allowsPublicHost() throws Exception {
|
||||||
|
PanBase.assertPublicHost(new URL("https://example.com/s/demo"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
亿方云 (FangCloud) 分享链接有效性验证脚本
|
||||||
|
|
||||||
|
用法: 直接 `python3 verify_fangcloud_share.py` 运行, 分享链接已写死在 SHARE_URL
|
||||||
|
里 (不走命令行传参), 要换链接就直接改这个常量。
|
||||||
|
|
||||||
|
根因(已用真实分享链接验证确认)
|
||||||
|
--------------------------------
|
||||||
|
GET https://v2.fangcloud.cn/apps/share_links/info/{uname}
|
||||||
|
返回的是 200 + JSON, 结构形如:
|
||||||
|
|
||||||
|
{
|
||||||
|
"process": {
|
||||||
|
"is_closed": false,
|
||||||
|
"is_expired": false,
|
||||||
|
"item": {"type": "file", "id": 45006535173, "name": "..."},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FcTool.java 原来的实现判断有效性时读的是响应体**顶层**的 "is_valid" 字段
|
||||||
|
(`json.getBoolean("is_valid")`), 但这个字段根本不存在于该接口的实际响应里
|
||||||
|
(有效性信息实际上是 process.is_closed / process.is_expired, 且没有任何
|
||||||
|
名叫 "is_valid" 的字段) —— 所以旧的判断逻辑其实从未真正读取过这个接口的
|
||||||
|
有效性判断, 而是走的另一套 HTML 抓取 typed_id 的流程, 分享失效时会得到一个
|
||||||
|
"未匹配到文件id(typed_id)" 这种令人困惑的技术报错, 而不是清晰的"分享已失效"。
|
||||||
|
|
||||||
|
修复方案(已同步到 FcTool.java): 解析前先请求一次
|
||||||
|
https://v2.fangcloud.cn/apps/share_links/info/{uname}, 用
|
||||||
|
process.is_closed / process.is_expired 判断分享是否有效, 无效则直接返回
|
||||||
|
"分享已失效或不存在", 有效再继续走原来的 HTML + files/download 流程。
|
||||||
|
|
||||||
|
本脚本用于本地复现/回归验证这条判断逻辑, 并顺带跑一遍完整的取直链流程。
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# 直接写死分享链接, 不通过命令行参数传入
|
||||||
|
SHARE_URL = "https://v2.fangcloud.cn/h5/share/ded6dc6b9c3672b40b769804bf"
|
||||||
|
|
||||||
|
# 如果分享有密码, 在这里填上, 没有就留空字符串
|
||||||
|
SHARE_PASSWORD = ""
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
"User-Agent": (
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||||
|
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
||||||
|
),
|
||||||
|
"Accept": "application/json, text/html;q=0.9, */*;q=0.8",
|
||||||
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
||||||
|
}
|
||||||
|
|
||||||
|
# 修复后的正则, 额外兼容 /h5/share/ 移动端落地页路径 (对齐 PanDomainTemplate.FC)
|
||||||
|
FC_REGEX = re.compile(r"https://v2\.fangcloud\.(com|cn)/(?:h5/)?(s|share|sharing)/(?P<KEY>.+)")
|
||||||
|
|
||||||
|
SHARE_INFO_URL = "https://v2.fangcloud.cn/apps/share_links/info/{key}"
|
||||||
|
SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/{key}"
|
||||||
|
DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download"
|
||||||
|
|
||||||
|
TYPED_ID_RE = re.compile(r'id="typed_id"\s+value="file_(\d+)"')
|
||||||
|
|
||||||
|
|
||||||
|
def extract_share_key(url: str) -> str:
|
||||||
|
m = FC_REGEX.search(url)
|
||||||
|
if not m:
|
||||||
|
raise ValueError(f"无法从链接中提取 shareKey (正则不匹配): {url}")
|
||||||
|
return m.group("KEY")
|
||||||
|
|
||||||
|
|
||||||
|
def check_is_valid(share_key: str, session: requests.Session) -> bool:
|
||||||
|
print("=" * 70)
|
||||||
|
print("Step 1. 请求 share_links/info 判断分享有效性 (对齐 FcTool.java 修复后的逻辑)")
|
||||||
|
print("=" * 70)
|
||||||
|
url = SHARE_INFO_URL.format(key=share_key)
|
||||||
|
r = session.get(url, timeout=15)
|
||||||
|
print(f"GET {url}")
|
||||||
|
print(f"状态码: {r.status_code}")
|
||||||
|
try:
|
||||||
|
data = r.json()
|
||||||
|
except Exception:
|
||||||
|
print("响应不是合法JSON => 判定分享已失效或不存在\n")
|
||||||
|
return False
|
||||||
|
|
||||||
|
process = data.get("process")
|
||||||
|
if not process:
|
||||||
|
print("响应中没有 process 字段 => 判定分享已失效或不存在\n")
|
||||||
|
return False
|
||||||
|
|
||||||
|
is_closed = bool(process.get("is_closed"))
|
||||||
|
is_expired = bool(process.get("is_expired"))
|
||||||
|
item = process.get("item")
|
||||||
|
print(f"is_closed = {is_closed}, is_expired = {is_expired}, item = {item}")
|
||||||
|
|
||||||
|
if is_closed or is_expired:
|
||||||
|
print("=> 分享已失效或不存在\n")
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("=> 分享有效\n")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_download_url(share_key: str, pwd: str, session: requests.Session) -> str:
|
||||||
|
print("=" * 70)
|
||||||
|
print("Step 2. 走原有 HTML + files/download 流程取直链")
|
||||||
|
print("=" * 70)
|
||||||
|
r = session.get(SHARE_URL_PREFIX.format(key=share_key), timeout=15)
|
||||||
|
print(f"GET {SHARE_URL_PREFIX.format(key=share_key)} -> {r.status_code}, 最终URL: {r.url}")
|
||||||
|
|
||||||
|
html = r.text
|
||||||
|
if pwd:
|
||||||
|
# 加密分享: 提交密码换取跳转后的落地页 (此处仅示意, 具体见 FcTool.java)
|
||||||
|
m = re.search(r'name="requesttoken"\s+value="([a-zA-Z0-9_+=]+)"', html)
|
||||||
|
if not m:
|
||||||
|
raise RuntimeError("未匹配到加密分享的密码输入页面的 requesttoken")
|
||||||
|
token = m.group(1)
|
||||||
|
r2 = session.post(
|
||||||
|
"https://v2.fangcloud.cn/sharing/" + share_key,
|
||||||
|
data={"requesttoken": token, "password": pwd},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
html = r2.text
|
||||||
|
|
||||||
|
m = TYPED_ID_RE.search(html)
|
||||||
|
if not m:
|
||||||
|
raise RuntimeError("未匹配到文件id(typed_id), 分享可能是文件夹或页面结构有变化")
|
||||||
|
fid = m.group(1)
|
||||||
|
print(f"提取到 file_id = {fid}")
|
||||||
|
|
||||||
|
r3 = session.get(
|
||||||
|
DOWN_REQUEST_URL,
|
||||||
|
params={"file_id": fid, "scenario": "share", "unique_name": share_key},
|
||||||
|
timeout=15,
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
print(f"GET {DOWN_REQUEST_URL} -> {r3.status_code}")
|
||||||
|
if r3.status_code in (301, 302) and r3.headers.get("Location"):
|
||||||
|
return r3.headers["Location"]
|
||||||
|
data = r3.json()
|
||||||
|
if not data.get("success"):
|
||||||
|
raise RuntimeError(f"取直链失败: {data}")
|
||||||
|
return data["download_url"]
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
share_key = extract_share_key(SHARE_URL)
|
||||||
|
print(f"分享链接: {SHARE_URL}")
|
||||||
|
print(f"提取到的 shareKey: {share_key}\n")
|
||||||
|
|
||||||
|
session = requests.Session()
|
||||||
|
session.headers.update(HEADERS)
|
||||||
|
|
||||||
|
if not check_is_valid(share_key, session):
|
||||||
|
print("结论: 分享无效, 不再继续取直链。")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = get_download_url(share_key, SHARE_PASSWORD, session)
|
||||||
|
print(f"\n>>> 直链: {url}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n取直链失败: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user