mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add download video for bangumi
This commit is contained in:
parent
1048c8830f
commit
b9267f0a41
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
// ==UserScript==
|
||||
// @name Bilibili Evolved (Preview)
|
||||
// @version 1.6.22
|
||||
// @version 1.6.24
|
||||
// @description 增强哔哩哔哩Web端体验(预览版分支): 修复界面瑕疵, 删除广告, 使用夜间模式浏览; 下载视频,封面,弹幕, 以及增加对触屏设备的支持等.
|
||||
// @author Grant Howard, Coulomb-G
|
||||
// @copyright 2018, Grant Howrad (https://github.com/the1812)
|
||||
@ -456,7 +456,7 @@
|
||||
dependencies: [
|
||||
"downloadVideoDom",
|
||||
"downloadVideoStyle",
|
||||
"videoInfo",
|
||||
// "videoInfo",
|
||||
],
|
||||
displayNames: {
|
||||
"downloadVideo": "下载视频",
|
||||
@ -1522,6 +1522,7 @@
|
||||
ResourceManager,
|
||||
Resource,
|
||||
ResourceType,
|
||||
GM_info
|
||||
};
|
||||
const resources = new ResourceManager();
|
||||
resources.fetch().catch(error => logError(error));
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// ==UserScript==
|
||||
// @name Bilibili Evolved
|
||||
// @version 1.6.22
|
||||
// @version 1.6.24
|
||||
// @description 增强哔哩哔哩Web端体验: 修复界面瑕疵, 删除广告, 使用夜间模式浏览; 下载视频,封面,弹幕, 以及增加对触屏设备的支持等.
|
||||
// @author Grant Howard, Coulomb-G
|
||||
// @copyright 2018, Grant Howrad (https://github.com/the1812)
|
||||
@ -456,7 +456,7 @@
|
||||
dependencies: [
|
||||
"downloadVideoDom",
|
||||
"downloadVideoStyle",
|
||||
"videoInfo",
|
||||
// "videoInfo",
|
||||
],
|
||||
displayNames: {
|
||||
"downloadVideo": "下载视频",
|
||||
@ -1522,6 +1522,7 @@
|
||||
ResourceManager,
|
||||
Resource,
|
||||
ResourceType,
|
||||
GM_info
|
||||
};
|
||||
const resources = new ResourceManager();
|
||||
resources.fetch().catch(error => logError(error));
|
||||
|
||||
2
min/download-video.min.js
vendored
2
min/download-video.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
1.6.22
|
||||
1.6.24
|
||||
@ -2,14 +2,23 @@
|
||||
{
|
||||
return (_, resources) =>
|
||||
{
|
||||
const VideoInfo = resources.attributes.videoInfo.export.VideoInfo;
|
||||
const BangumiInfo = resources.attributes.videoInfo.export.BangumiInfo;
|
||||
// const VideoInfo = resources.attributes.videoInfo.export.VideoInfo;
|
||||
// const BangumiInfo = resources.attributes.videoInfo.export.BangumiInfo;
|
||||
const pageData = {
|
||||
aid: undefined,
|
||||
cid: undefined,
|
||||
isBangumi: false,
|
||||
isMovie: false
|
||||
};
|
||||
|
||||
const bangumiUrls = [];
|
||||
$(document).ajaxSend((event, request, params) =>
|
||||
{
|
||||
if (params.url.indexOf("https://bangumi.bilibili.com/player/web_api/v2/playurl") !== -1)
|
||||
{
|
||||
bangumiUrls.unshift(params.url);
|
||||
}
|
||||
});
|
||||
class VideoFormat
|
||||
{
|
||||
constructor(quality, internalName, displayName)
|
||||
@ -28,35 +37,53 @@
|
||||
{
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
const url = `https://api.bilibili.com/x/player/playurl?avid=${pageData.aid}&cid=${pageData.cid}&otype=json`;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", () =>
|
||||
function downloadFormats(url)
|
||||
{
|
||||
const json = JSON.parse(xhr.responseText);
|
||||
if (json.code !== 0)
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", () =>
|
||||
{
|
||||
reject("获取清晰度信息失败.");
|
||||
}
|
||||
const data = json.data;
|
||||
const qualities = data.accept_quality;
|
||||
const internalNames = data.accept_format.split(",");
|
||||
const displayNames = data.accept_description;
|
||||
const formats = [];
|
||||
while (qualities.length > 0)
|
||||
{
|
||||
const format = new VideoFormat(
|
||||
qualities.pop(),
|
||||
internalNames.pop(),
|
||||
displayNames.pop()
|
||||
);
|
||||
formats.push(format);
|
||||
}
|
||||
resolve(formats);
|
||||
});
|
||||
xhr.addEventListener("error", () => reject(`获取清晰度信息失败.`));
|
||||
xhr.withCredentials = true;
|
||||
xhr.open("GET", url);
|
||||
xhr.send();
|
||||
const json = JSON.parse(xhr.responseText);
|
||||
if (json.code !== 0)
|
||||
{
|
||||
reject("获取清晰度信息失败.");
|
||||
}
|
||||
const data = json.data;
|
||||
const qualities = data.accept_quality;
|
||||
const internalNames = data.accept_format.split(",");
|
||||
const displayNames = data.accept_description;
|
||||
const formats = [];
|
||||
while (qualities.length > 0)
|
||||
{
|
||||
const format = new VideoFormat(
|
||||
qualities.pop(),
|
||||
internalNames.pop(),
|
||||
displayNames.pop()
|
||||
);
|
||||
formats.push(format);
|
||||
}
|
||||
resolve(formats);
|
||||
});
|
||||
xhr.addEventListener("error", () => reject(`获取清晰度信息失败.`));
|
||||
xhr.withCredentials = true;
|
||||
xhr.open("GET", url);
|
||||
xhr.send();
|
||||
}
|
||||
let url = `https://api.bilibili.com/x/player/playurl?avid=${pageData.aid}&cid=${pageData.cid}&otype=json`;
|
||||
if (pageData.isBangumi)
|
||||
{
|
||||
SpinQuery.select(() => bangumiUrls[0],
|
||||
bangumiUrl =>
|
||||
{
|
||||
url = bangumiUrl;
|
||||
downloadFormats(url);
|
||||
},
|
||||
() => logError("获取番剧下载链接失败."),
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
downloadFormats(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -257,33 +284,14 @@
|
||||
}
|
||||
async function loadPageData()
|
||||
{
|
||||
const result = await (async () =>
|
||||
{
|
||||
let aid = (unsafeWindow || window).aid;
|
||||
let cid = (unsafeWindow || window).cid;
|
||||
if (aid === undefined || cid === undefined)
|
||||
{
|
||||
const aidMatch = document.URL.match(/\/av(\d+)/);
|
||||
const epMatch = document.URL.match(/\/ep(\d+)/);
|
||||
if (aidMatch && aidMatch[1])
|
||||
{
|
||||
const info = await new VideoInfo(aidMatch[1]).fetchInfo();
|
||||
aid = info.aid;
|
||||
cid = info.cid;
|
||||
}
|
||||
// TODO: Download bangumi, the legacy method not work...
|
||||
// else if (epMatch && epMatch[1])
|
||||
// {
|
||||
// const info = await new BangumiInfo(epMatch[1]).fetchInfo();
|
||||
// aid = info.aid;
|
||||
// cid = info.cid;
|
||||
// }
|
||||
}
|
||||
return [aid, cid];
|
||||
})();
|
||||
const [aid, cid] = result;
|
||||
const aid = await SpinQuery.select(() => (unsafeWindow || window).aid);
|
||||
const cid = await SpinQuery.select(() => (unsafeWindow || window).cid);
|
||||
pageData.aid = aid;
|
||||
pageData.cid = cid;
|
||||
if (document.URL.indexOf("bangumi") !== -1)
|
||||
{
|
||||
pageData.isBangumi = true;
|
||||
}
|
||||
return aid !== undefined && cid !== undefined;
|
||||
}
|
||||
async function loadWidget()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user