Skip to content

Commit

Permalink
Merge pull request #156 from nICEnnnnnnnLee/dev
Browse files Browse the repository at this point in the history
V6.27 Update
  • Loading branch information
nICEnnnnnnnLee authored Aug 13, 2023
2 parents 1df7ed7 + 96c6638 commit 4d815b4
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 150 deletions.
11 changes: 5 additions & 6 deletions .github/release.info
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
* 修复: [issues 146](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/146),[issues 147](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/147) 解决api更换导致的UP主所有视频无法查询的问题
* 修复: [issues 149](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/149), 作品信息页面尝试兼容mac下的UI布局
* 优化: [issues 140](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/140) 卸载脚本增加更多提示
* 优化: [issues 141](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/141) 增加配置`bilibili.alert.qualityUnexpected`,可以开启/关闭对非期望的低画质清晰度视频的判断
* 优化: [issues 145](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/145) 增加相关配置,可以针对不同分辨率设置不同的视频编码优先级
* 优化: 现在可以直接在程序代码中刷新cookie,而不必再打开浏览器
* 修复: [issues 155](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/155) 重写对于UP主所有视频的分页查询逻辑
需要注意的是,若UP主上传有多BV的合集,此时自定义文件名中的参数`pDisplay`将不再准确。
* 修复: [issues 152](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/152) 考虑只有杜比视界而没有杜比音效的解析场景(e.g. BV1SN411A7KT)
* 优化: [issues 151](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/151) 增加配置`bilibili.tab.display.previewPic`,可以开启/关闭Tab页的视频封面预览
* 优化: 通过配置`bilibili.login.cookie.tryRefreshOnStartup`,可以使程序在每次打开时尝试刷新cookie。不再需要手动点击对应菜单。
<hr/>

如果你是Win64用户,且没有java环境,请下载附件`*.win_x64_jre11.release.zip`
9 changes: 0 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ jobs:
chmod +x .github/scripts/upload_imagekit.sh
./.github/scripts/upload_imagekit.sh
- name: Upload release to railway
env:
RAILWAY_AUTH: ${{ secrets.RAILWAY_AUTH }}
ZIP_FILE_NAME: BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip
SHA1_FILE_NAME: BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip.sha1
if: ${{ env.RAILWAY_AUTH != ''}}
run: |
chmod +x .github/scripts/upload_railway.sh
./.github/scripts/upload_railway.sh
- name: Sync Push to Gitee
env:
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/upload-manually.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ on:
type: boolean
default: true
required: false
railway:
description: 'Upload to railway?'
type: boolean
default: true
required: false
railwayFFmpeg:
description: 'Upload FFmpeg to railway?'
type: boolean
default: false
required: false
giteePush:
description: 'Push to gitee?'
type: boolean
Expand Down Expand Up @@ -93,25 +83,6 @@ jobs:
chmod +x .github/scripts/upload_imagekit.sh
./.github/scripts/upload_imagekit.sh
- name: Upload release to railway
env:
RAILWAY_AUTH: ${{ secrets.RAILWAY_AUTH }}
ZIP_FILE_NAME: BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip
SHA1_FILE_NAME: BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip.sha1
if: ${{ always() && env.RAILWAY_AUTH != '' && github.event.inputs.railway == 'true'}}
run: |
chmod +x .github/scripts/upload_railway.sh
./.github/scripts/upload_railway.sh
- name: Upload ffmpeg to railway
env:
RAILWAY_AUTH: ${{ secrets.RAILWAY_AUTH }}
if: ${{ always() && env.RAILWAY_AUTH != '' && github.event.inputs.railwayFFmpeg == 'true'}}
run: |
wget https://github.com/nICEnnnnnnnLee/BilibiliDown/releases/download/V4.5/ffmpeg_N-108857-g00b03331a0-20221027.exe
curl -X POST "https://bili.up.railway.app/upload" \
--cookie "auth=$RAILWAY_AUTH" \
-F "file=@ffmpeg_N-108857-g00b03331a0-20221027.exe;type=application/octet-stream"
- name: Sync Push to Gitee
env:
Expand Down
7 changes: 7 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## UPDATE
* V6.26 `2023-06-06`
* 修复: [issues 155](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/155) 重写对于UP主所有视频的分页查询逻辑
需要注意的是,若UP主上传有多BV的合集,此时自定义文件名中的参数`pDisplay`将不再准确。
* 修复: [issues 152](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/152) 考虑只有杜比视界而没有杜比音效的解析场景(e.g. BV1SN411A7KT)
* 优化: [issues 151](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/151) 增加配置`bilibili.tab.display.previewPic`,可以开启/关闭Tab页的视频封面预览
* 优化: 通过配置`bilibili.login.cookie.tryRefreshOnStartup`,可以使程序在每次打开时尝试刷新cookie。不再需要手动点击对应菜单。

* V6.26 `2023-06-06`
* 修复: [issues 146](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/146),[issues 147](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/147) 解决api更换导致的UP主所有视频无法查询的问题
* 修复: [issues 149](https://github.com/nICEnnnnnnnLee/BilibiliDown/issues/149), 作品信息页面尝试兼容mac下的UI布局
Expand Down
8 changes: 5 additions & 3 deletions src/nicelee/bilibili/parsers/impl/AbstractBaseParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ protected String parseType1(JSONObject jObj, int linkQN, HashMap<String, String>
}
JSONObject dolby = dash.optJSONObject("dolby");// 杜比
if (dolby != null && linkQN == 126) {
audios = dolby.getJSONArray("audio");
for (int i = 0; i < audios.length(); i++) {
listAudios.add(audios.getJSONObject(i));
audios = dolby.optJSONArray("audio");
if (audios != null) {
for (int i = 0; i < audios.length(); i++) {
listAudios.add(audios.getJSONObject(i));
}
}
}
JSONObject flac = dash.optJSONObject("flac");// flac
Expand Down
198 changes: 123 additions & 75 deletions src/nicelee/bilibili/parsers/impl/URL4UPAllMedialistParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import nicelee.bilibili.util.HttpCookies;
import nicelee.bilibili.util.HttpHeaders;
import nicelee.bilibili.util.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

/**
*
Expand Down Expand Up @@ -124,8 +125,17 @@ public void initPageQueryParam() {
pageQueryResult.setClips(new LinkedHashMap<>());
}

@Override
protected boolean query(int page, int min, int max, Object... obj) {
/**
* 分页查询
*
* @param pageSize
* @param page
* @param obj
* @return 以pageSize 进行分页查询,获取第page页的结果
*/
public VideoInfo result(int pageSize, int page, Object... obj) {
initPageQueryParam();
Logger.printf("pageSize: %d, page: %d", pageSize, page);
int videoFormat = (int) obj[0];
boolean getVideoLink = (boolean) obj[1];
String sortField = params.get("sort_field");
Expand All @@ -145,97 +155,135 @@ protected boolean query(int page, int min, int max, Object... obj) {
pageQueryResult.setAuthor(jobj.getJSONObject("upper").getString("name"));
}
// 获取oid(返回结果的第一个视频id)
String oid = "";
if (page > 1) {
String sortFieldParam = paramDicts[0][1];
for (int i = 0; i < paramDicts.length; i++) {
if (paramDicts[i][0].equals(sortField)) {
sortFieldParam = paramDicts[i][1];
break;
}
String sortFieldParam = paramDicts[0][1];
for (int i = 0; i < paramDicts.length; i++) {
if (paramDicts[i][0].equals(sortField)) {
sortFieldParam = paramDicts[i][1];
break;
}
int lastPageNumber = (page - 1) * API_PMAX + 1;
// String urlFormat = "https://api.bilibili.com/x/space/arc/search?mid=%s&ps=%d&tid=%s&pn=%d&keyword=&order=%s&jsonp=jsonp";
String urlFormat = "https://api.bilibili.com/x/space/wbi/arc/search?mid=%s&ps=%d&tid=%s&special_type=&pn=%d&keyword=&order=%s&platform=web"; // &web_location=1550101&order_avoided=true
String url = String.format(urlFormat, spaceID, 1, params.get("tid"), lastPageNumber, sortFieldParam);
url = API.encWbi(url);
String json = util.getContent(url, headers, HttpCookies.globalCookiesWithFingerprint());
Logger.println(url);
Logger.println(json);
oid = new JSONObject(json).getJSONObject("data").getJSONObject("list").getJSONArray("vlist")
.getJSONObject(0).optString("aid");
Logger.printf("page: %d, lastPageNumber: %d, oid: %s\n", page, lastPageNumber, oid);
}
String firstOid = position2Oid((page - 1) * pageSize + 1, headers, sortFieldParam);
if(firstOid.equals("end"))
return pageQueryResult;
String lastOidPlus1 = position2Oid(page * pageSize + 1, headers, sortFieldParam);

// 根据oid查询分页的详细信息
String urlFormat = "https://api.bilibili.com/x/v2/medialist/resource/list?type=1&oid=%s&otype=2&biz_id=%s&bvid=&with_current=true&mobi_app=web&ps=%d&direction=false&sort_field=%d&tid=%s&desc=true";
String urlFormat = "https://api.bilibili.com/x/v2/medialist/resource/list?type=1&oid=%s&otype=2&biz_id=%s&bvid=&with_current=%s&mobi_app=web&ps=%d&direction=false&sort_field=%d&tid=%s&desc=true";
boolean withCurrent = true;
int sortFieldIndex = 1;
for (int i = 0; i < paramDicts.length; i++) {
if (paramDicts[i][0].equals(sortField)) {
sortFieldIndex = i + 1;
break;
}
}
String url = String.format(urlFormat, oid, spaceID, API_PMAX, sortFieldIndex, params.get("tid"));
Logger.println(url);
String json = util.getContent(url, headers);
JSONObject jobj = new JSONObject(json);
JSONArray arr = jobj.getJSONObject("data").getJSONArray("media_list");

if (pageQueryResult.getVideoPreview() == null) {
pageQueryResult.setVideoPreview(arr.getJSONObject(0).getString("cover"));
}

LinkedHashMap<Long, ClipInfo> map = pageQueryResult.getClips();
for (int i = min - 1; i < arr.length() && i < max; i++) {
JSONObject jAV = arr.getJSONObject(i);
String avId = jAV.getString("bv_id");
String avTitle = jAV.getString("title");
String upName = jAV.getJSONObject("upper").getString("name");
String upId = jAV.getJSONObject("upper").optString("mid");
long cTime = jAV.optLong("pubtime") * 1000;
JSONArray jClips = jAV.optJSONArray("pages");
if (jClips == null) {
continue;
boolean findLastOid = false;
String currentOid = firstOid;
int pageRemark = (page - 1) * pageSize;
while(!findLastOid) {
String url = String.format(urlFormat, currentOid, spaceID, withCurrent, API_PMAX, sortFieldIndex, params.get("tid"));
Logger.println(url);
withCurrent = false; // 接下来的查询不需要包括定位的 oid
String json = util.getContent(url, headers);
JSONObject jobj = new JSONObject(json);
JSONArray arr = jobj.getJSONObject("data").getJSONArray("media_list");

if (pageQueryResult.getVideoPreview() == null) {
pageQueryResult.setVideoPreview(arr.getJSONObject(0).getString("cover"));
}
for (int pointer = 0; pointer < jClips.length(); pointer++) {
JSONObject jClip = jClips.getJSONObject(pointer);
ClipInfo clip = new ClipInfo();
clip.setAvId(avId);
clip.setcId(jClip.getLong("id"));
clip.setPage(jClip.getInt("page"));
clip.setRemark((page - 1) * API_PMAX + i + 1);
clip.setPicPreview(jAV.getString("cover"));
// >= V3.6, ClipInfo 增加可选ListXXX字段,将收藏夹信息移入其中
clip.setListName(listName.replaceAll("[/\\\\]", "_"));
clip.setListOwnerName(pageQueryResult.getAuthor().replaceAll("[/\\\\]", "_"));
clip.setUpName(upName);
clip.setUpId(upId);
clip.setAvTitle(avTitle);
clip.setTitle(jClip.getString("title"));
clip.setcTime(cTime);

LinkedHashMap<Integer, String> links = new LinkedHashMap<Integer, String>();
try {
for (VideoQualityEnum VQ : VideoQualityEnum.values()) {
if (getVideoLink) {
String link = getVideoLink(avId, String.valueOf(clip.getcId()), VQ.getQn(),
videoFormat);
links.put(VQ.getQn(), link);
} else {
links.put(VQ.getQn(), "");

LinkedHashMap<Long, ClipInfo> map = pageQueryResult.getClips();
for (int i = 0; i < arr.length(); i++) {
pageRemark++;
JSONObject jAV = arr.getJSONObject(i);
String oid = jAV.optString("id");
if(oid.equals(lastOidPlus1)) {
findLastOid = true;
break;
}
currentOid = oid;
String avId = jAV.getString("bv_id");
String avTitle = jAV.getString("title");
String upName = jAV.getJSONObject("upper").getString("name");
String upId = jAV.getJSONObject("upper").optString("mid");
long cTime = jAV.optLong("pubtime") * 1000;
JSONArray jClips = jAV.optJSONArray("pages");
if (jClips == null) {
continue;
}
for (int pointer = 0; pointer < jClips.length(); pointer++) {
JSONObject jClip = jClips.getJSONObject(pointer);
ClipInfo clip = new ClipInfo();
clip.setAvId(avId);
clip.setcId(jClip.getLong("id"));
clip.setPage(jClip.getInt("page"));
clip.setRemark(pageRemark); //这个已经没法计算准确了
clip.setPicPreview(jAV.getString("cover"));
// >= V3.6, ClipInfo 增加可选ListXXX字段,将收藏夹信息移入其中
clip.setListName(listName.replaceAll("[/\\\\]", "_"));
clip.setListOwnerName(pageQueryResult.getAuthor().replaceAll("[/\\\\]", "_"));
clip.setUpName(upName);
clip.setUpId(upId);
clip.setAvTitle(avTitle);
clip.setTitle(jClip.getString("title"));
clip.setcTime(cTime);

LinkedHashMap<Integer, String> links = new LinkedHashMap<Integer, String>();
try {
for (VideoQualityEnum VQ : VideoQualityEnum.values()) {
if (getVideoLink) {
String link = getVideoLink(avId, String.valueOf(clip.getcId()), VQ.getQn(),
videoFormat);
links.put(VQ.getQn(), link);
} else {
links.put(VQ.getQn(), "");
}
}
} catch (Exception e) {
}
} catch (Exception e) {
clip.setLinks(links);

map.put(clip.getcId(), clip);
}
clip.setLinks(links);

map.put(clip.getcId(), clip);
}
}
return true;
} catch (Exception e) {
// e.printStackTrace();
return false;
}
return pageQueryResult;
}

/**
* 返回 "" 表示开头
* 返回 "end" 表示结尾
* 返回 数字 表示具体id
* @param pageNumber
* @param headers
* @param sortFieldParam
*/
private String position2Oid(int pageNumber, HashMap<String, String> headers, String sortFieldParam) {
if(pageNumber == 1)
return "";
// String urlFormat = "https://api.bilibili.com/x/space/arc/search?mid=%s&ps=%d&tid=%s&pn=%d&keyword=&order=%s&jsonp=jsonp";
String urlFormat = "https://api.bilibili.com/x/space/wbi/arc/search?mid=%s&ps=%d&tid=%s&special_type=&pn=%d&keyword=&order=%s&platform=web"; // &web_location=1550101&order_avoided=true
String url = String.format(urlFormat, spaceID, 1, params.get("tid"), pageNumber, sortFieldParam);
url = API.encWbi(url);
String json = util.getContent(url, headers, HttpCookies.globalCookiesWithFingerprint());
Logger.println(url);
Logger.println(json);
JSONArray vlist = new JSONObject(json).getJSONObject("data").getJSONObject("list").getJSONArray("vlist");
if(vlist.length() == 0) {
Logger.printf("position: %d, oid: search till end", pageNumber);
return "end";
} else {
String oid = vlist.getJSONObject(0).optString("aid");
Logger.printf("position: %d, oid: %s", pageNumber, oid);
return oid;
}
}

@Override
protected boolean query(int page, int min, int max, Object... obj) {
throw new NotImplementedException();
}
}
19 changes: 17 additions & 2 deletions src/nicelee/ui/FrameMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import nicelee.bilibili.model.VideoInfo;
import nicelee.bilibili.util.CmdUtil;
import nicelee.bilibili.util.ConfigUtil;
import nicelee.bilibili.util.HttpCookies;
import nicelee.bilibili.util.Logger;
import nicelee.bilibili.util.RepoUtil;
import nicelee.bilibili.util.ResourcesUtil;
import nicelee.ui.item.MJTitleBar;
import nicelee.ui.thread.CookieRefreshThread;
import nicelee.ui.thread.DownloadRunnable;
import nicelee.ui.thread.LoginThread;
import nicelee.ui.thread.MonitoringThread;
Expand Down Expand Up @@ -85,11 +87,24 @@ public static void main(String[] args) {
MonitoringThread th = new MonitoringThread();
th.start();

// 初始化 - 登录
// 尝试刷新cookie
INeedLogin inl = new INeedLogin();
if (inl.readCookies() != null) {
String cookiesStr = inl.readCookies();
if (cookiesStr != null) {
Global.needToLogin = true;
if(Global.tryRefreshCookieOnStartup && !Global.runWASMinBrowser) {
HttpCookies.setGlobalCookies(HttpCookies.convertCookies(cookiesStr));
CookieRefreshThread.showTips = false;
CookieRefreshThread thCR = CookieRefreshThread.newInstance();
thCR.start();
try {
thCR.join();
} catch (InterruptedException e1) {
}
CookieRefreshThread.showTips = true;
}
}
// 初始化 - 登录
LoginThread loginTh = new LoginThread();
loginTh.start();

Expand Down
Loading

0 comments on commit 4d815b4

Please sign in to comment.