Skip to content

Commit

Permalink
fix: 尝试减小图片合集类型的风控概率
Browse files Browse the repository at this point in the history
  • Loading branch information
nICEnnnnnnnLee committed Jul 23, 2024
1 parent 632d84f commit d3ad6a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/nicelee/bilibili/parsers/impl/URL4PictureCVParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nicelee.bilibili.parsers.impl;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -10,6 +11,7 @@
import nicelee.bilibili.annotations.Bilibili;
import nicelee.bilibili.model.ClipInfo;
import nicelee.bilibili.model.VideoInfo;
import nicelee.bilibili.util.HttpCookies;
import nicelee.bilibili.util.HttpHeaders;
import nicelee.bilibili.util.Logger;

Expand Down Expand Up @@ -51,14 +53,15 @@ public VideoInfo result(String input, int videoFormat, boolean getVideoLink) {
return getCVDetail(cvIdNumber);
}

final static protected HashMap<String, String> headers = new HttpHeaders().getCommonHeaders("www.bilibili.com");
protected VideoInfo getCVDetail(String cvIdNumber) {
Logger.println("URL4PictureCVParser正在获取结果: cv" + cvIdNumber);
String cvIdStr = "cv" + cvIdNumber;
VideoInfo viInfo = new VideoInfo();
viInfo.setVideoId(cvIdStr);

String urlOpus = "https://www.bilibili.com/read/" + cvIdStr;
String html = util.getContent(urlOpus, new HttpHeaders().getCommonHeaders("www.bilibili.com"));
String html = util.getContent(urlOpus, headers, HttpCookies.globalCookiesWithFingerprint());
int begin = html.indexOf("window.__INITIAL_STATE__=");
int end = html.indexOf(";(function()", begin);
String json = html.substring(begin + 25, end);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ protected boolean query(int page, int min, int max, Object... obj) {
uniqeNumber = uniqeNumber.substring(2); // 防止超出long的范围
map.put(Long.parseLong(uniqeNumber), clip);
}
Thread.sleep(100); // 通过抠html得到的,太频繁容易风控,除了给cookie外,只能先sleep试试了
}
return true;
} catch (Exception e) {
Expand Down
4 changes: 2 additions & 2 deletions src/nicelee/bilibili/parsers/impl/URL4PictureOpusParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import nicelee.bilibili.annotations.Bilibili;
import nicelee.bilibili.model.ClipInfo;
import nicelee.bilibili.model.VideoInfo;
import nicelee.bilibili.util.HttpHeaders;
import nicelee.bilibili.util.HttpCookies;
import nicelee.bilibili.util.Logger;

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ protected VideoInfo getOpusDetail(String opusIdNumber) {
String opusIdStr = "opus" + opusIdNumber;

String urlOpus = "https://www.bilibili.com/opus/" + opusIdNumber;
String html = util.getContent(urlOpus, new HttpHeaders().getCommonHeaders("www.bilibili.com"));
String html = util.getContent(urlOpus, headers, HttpCookies.globalCookiesWithFingerprint());
int begin = html.indexOf("window.__INITIAL_STATE__=");
int end = html.indexOf(";(function()", begin);
String json = html.substring(begin + 25, end);
Expand Down
1 change: 1 addition & 0 deletions src/nicelee/bilibili/parsers/impl/URL4PictureRLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public VideoInfo result(int pageSize, int page, Object... obj) {
clip.setRemark(i);
clipMap.put(Long.parseLong(cvIdNumber + clip.getPage()), clip);
}
Thread.sleep(100); // 通过抠html得到的,太频繁容易风控,除了给cookie外,只能先sleep试试
}

} catch (Exception e) {
Expand Down

0 comments on commit d3ad6a0

Please sign in to comment.