This commit is contained in:
QAIU
2024-10-29 18:36:51 +08:00
parent 39b2612840
commit ecf4441946
4 changed files with 192 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
package cn.qaiu.entity;
import java.util.Map;
public class ShareLinkInfo {
private String shareKey; // 分享键
@@ -10,6 +12,8 @@ public class ShareLinkInfo {
private String shareUrl; // 原始分享链接
private String standardUrl; // 规范化的标准链接
private Map<String, Object> otherParam; // 其他参数
private ShareLinkInfo(Builder builder) {
this.shareKey = builder.shareKey;
this.panName = builder.panName;
@@ -88,6 +92,7 @@ public class ShareLinkInfo {
private String sharePassword = ""; // 分享密码(如果存在)
private String shareUrl; // 原始分享链接
private String standardUrl; // 规范化的标准链接
private Map<String, Object> otherParam; // 其他参数
public Builder shareKey(String shareKey) {
this.shareKey = shareKey;
@@ -119,6 +124,11 @@ public class ShareLinkInfo {
return this;
}
public Builder otherParam(Map<String, Object> otherParam) {
this.otherParam = otherParam;
return this;
}
public ShareLinkInfo build() {
return new ShareLinkInfo(this);
}
@@ -133,6 +143,7 @@ public class ShareLinkInfo {
", sharePassword='" + sharePassword + '\'' +
", shareUrl='" + shareUrl + '\'' +
", standardUrl='" + standardUrl + '\'' +
", otherParam='" + otherParam + '\'' +
'}';
}
}

View File

@@ -0,0 +1,114 @@
package cn.qaiu.parser.impl;
import cn.qaiu.entity.ShareLinkInfo;
import cn.qaiu.parser.PanBase;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* t.cn 短链生成
*/
public class GenShortUrl extends PanBase {
private static final Logger log = LoggerFactory.getLogger(GenShortUrl.class);
private static final String COMMENT_URL = "https://www.weibo.com/aj/v6/comment/add";
private static final String DELETE_COMMENT_URL = "https://www.weibo.com/aj/comment/del";
private static final String MID = "5094736413852129"; // 微博的mid
public GenShortUrl(ShareLinkInfo build) {
super(build);
}
@Override
public Future<String> parse() {
String longUrl = shareLinkInfo.getStandardUrl();
return addComment(longUrl)
.compose(commentId -> deleteComment(commentId).map(v -> longUrl));
}
private Future<String> addComment(String longUrl) {
Promise<String> promise = Promise.promise();
String payload = "mid=" + MID + "&content=" + longUrl;
clientSession.postAbs(COMMENT_URL)
.putHeader("Content-Type", "application/x-www-form-urlencoded")
.sendBuffer(Buffer.buffer(payload))
.onSuccess(res -> {
String shortUrl = extractShortUrl(res);
if (shortUrl != null) {
log.info("生成的短链:{}", shortUrl);
String commentId = extractCommentId(res);
if (commentId != null) {
promise.complete(commentId);
} else {
promise.fail("未能提取评论ID");
}
} else {
promise.fail("未能生成短链");
}
})
.onFailure(err -> {
log.error("添加评论失败", err);
promise.fail(err);
});
return promise.future();
}
private Future<Void> deleteComment(String commentId) {
Promise<Void> promise = Promise.promise();
String payload = "mid=" + MID + "&cid=" + commentId;
clientSession.postAbs(DELETE_COMMENT_URL)
.putHeader("Content-Type", "application/x-www-form-urlencoded")
.sendBuffer(Buffer.buffer(payload))
.onSuccess(res -> {
JsonObject responseJson = res.bodyAsJsonObject();
if (responseJson.getString("code").equals("100000")) {
log.info("评论已删除: {}", commentId);
promise.complete();
} else {
promise.fail("删除评论失败,返回码:" + responseJson.getString("code"));
}
})
.onFailure(err -> {
log.error("删除评论失败", err);
promise.fail(err);
});
return promise.future();
}
private String extractShortUrl(HttpResponse<Buffer> response) {
Pattern pattern = Pattern.compile("(https?)://t.cn/\\w+");
Matcher matcher = pattern.matcher(response.bodyAsString());
if (matcher.find()) {
return matcher.group(0);
}
return null;
}
private String extractCommentId(HttpResponse<Buffer> response) {
Pattern pattern = Pattern.compile("comment_id=\"(\\d+)\"");
Matcher matcher = pattern.matcher(response.bodyAsString());
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
public static void main(String[] args) {
new GenShortUrl(ShareLinkInfo.newBuilder().build());
}
}

View File

@@ -0,0 +1,63 @@
import requests
import urllib.parse
import re
import base64
"""
"""
headers = {
'Cookie': 'SUB=',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Referer': 'https://www.weibo.com',
'Content-Type': 'application/x-www-form-urlencoded'
}
def get_short_url(long_url):
url = "https://www.weibo.com/aj/v6/comment/add"
payload = urllib.parse.urlencode({
'mid': '5094736413852129',
'content': long_url
})
response = requests.post(url, headers=headers, data=payload)
try:
# print(response.json())
data = response.json()['data']['comment']
short_url = re.search(r'(https?)://t.cn/\w+', data).group(0)
comment_id = re.findall(r'comment_id="(.+\d)"', data)[-1] # 评论id
print('微博短链:' + short_url)
del_comment(comment_id) # 需要删除评论,可以取消该行注释
except:
print('失败')
pass
# 删除评论
def del_comment(comment_id):
url = 'https://www.weibo.com/aj/comment/del'
payload = urllib.parse.urlencode({
'mid': '微博mid',
'cid': comment_id # 评论id
})
response = requests.post(url, headers=headers, data=payload)
try:
if response.json()['code'] == '100000':
print('评论已删除')
except:
pass
if __name__ == '__main__':
# https://so.toutiao.com/search/jump?url=https%3A%2F%2Fblog.qaiu.top%2Farchives%2Fpydroidall&aid=4916&jtoken=297f06127cb010274213422b1967bdc2ae8469b627205941dc287173b58a2a8439ea0d813d24ada8780047d33f37d7e82c6a620760de1ca37640c1dc143b4e01
# https://so.toutiao.com/search/jump?url=https%3A%2F%2Fblog.qaiu.top%2Farchives%2Fpydroidall1&aid=4916&jtoken=297f06127cb010274213422b1967bdc2ae8469b627205941dc287173b58a2a8439ea0d813d24ada8780047d33f37d7e82c6a620760de1ca37640c1dc143b4e01
# 原始 URL
url = "https://lz.qaiu.top/json/lz/i5vOm0xho2cj"
# 将 URL 编码为 Base64
encoded_url = base64.b64encode(url.encode("utf-8")).decode("utf-8")
get_short_url('https://www.so.com/link?m=ewgUSYiFWXIoTybC3fJH8YoJy8y10iRquo6cazgINwWjTn3HvVJ92TrCJu0PmMUR0RMDfOAucP3wa4G8j64SrhNH9Z0Cr0PEyn9ASuvpkUGmAjjUEGJkO5%2BIDGWVrEkPHsL7UsoKO6%2BlT%2BD6r&ccc=' + encoded_url)

View File

@@ -9,6 +9,10 @@
content="Netdisk fast download,网盘直链解析工具">
<meta name="description"
content="Netdisk fast download 网盘直链解析工具">
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({id:"K8zkCkZMgFA6ShZK",ck:"K8zkCkZMgFA6ShZK"})</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9851170484804006"
crossorigin="anonymous"></script>
<style>
.page-loading-wrap {
padding: 120px;