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==
|
// ==UserScript==
|
||||||
// @name Bilibili Evolved (Preview)
|
// @name Bilibili Evolved (Preview)
|
||||||
// @version 1.6.22
|
// @version 1.6.24
|
||||||
// @description 增强哔哩哔哩Web端体验(预览版分支): 修复界面瑕疵, 删除广告, 使用夜间模式浏览; 下载视频,封面,弹幕, 以及增加对触屏设备的支持等.
|
// @description 增强哔哩哔哩Web端体验(预览版分支): 修复界面瑕疵, 删除广告, 使用夜间模式浏览; 下载视频,封面,弹幕, 以及增加对触屏设备的支持等.
|
||||||
// @author Grant Howard, Coulomb-G
|
// @author Grant Howard, Coulomb-G
|
||||||
// @copyright 2018, Grant Howrad (https://github.com/the1812)
|
// @copyright 2018, Grant Howrad (https://github.com/the1812)
|
||||||
@ -456,7 +456,7 @@
|
|||||||
dependencies: [
|
dependencies: [
|
||||||
"downloadVideoDom",
|
"downloadVideoDom",
|
||||||
"downloadVideoStyle",
|
"downloadVideoStyle",
|
||||||
"videoInfo",
|
// "videoInfo",
|
||||||
],
|
],
|
||||||
displayNames: {
|
displayNames: {
|
||||||
"downloadVideo": "下载视频",
|
"downloadVideo": "下载视频",
|
||||||
@ -1522,6 +1522,7 @@
|
|||||||
ResourceManager,
|
ResourceManager,
|
||||||
Resource,
|
Resource,
|
||||||
ResourceType,
|
ResourceType,
|
||||||
|
GM_info
|
||||||
};
|
};
|
||||||
const resources = new ResourceManager();
|
const resources = new ResourceManager();
|
||||||
resources.fetch().catch(error => logError(error));
|
resources.fetch().catch(error => logError(error));
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Bilibili Evolved
|
// @name Bilibili Evolved
|
||||||
// @version 1.6.22
|
// @version 1.6.24
|
||||||
// @description 增强哔哩哔哩Web端体验: 修复界面瑕疵, 删除广告, 使用夜间模式浏览; 下载视频,封面,弹幕, 以及增加对触屏设备的支持等.
|
// @description 增强哔哩哔哩Web端体验: 修复界面瑕疵, 删除广告, 使用夜间模式浏览; 下载视频,封面,弹幕, 以及增加对触屏设备的支持等.
|
||||||
// @author Grant Howard, Coulomb-G
|
// @author Grant Howard, Coulomb-G
|
||||||
// @copyright 2018, Grant Howrad (https://github.com/the1812)
|
// @copyright 2018, Grant Howrad (https://github.com/the1812)
|
||||||
@ -456,7 +456,7 @@
|
|||||||
dependencies: [
|
dependencies: [
|
||||||
"downloadVideoDom",
|
"downloadVideoDom",
|
||||||
"downloadVideoStyle",
|
"downloadVideoStyle",
|
||||||
"videoInfo",
|
// "videoInfo",
|
||||||
],
|
],
|
||||||
displayNames: {
|
displayNames: {
|
||||||
"downloadVideo": "下载视频",
|
"downloadVideo": "下载视频",
|
||||||
@ -1522,6 +1522,7 @@
|
|||||||
ResourceManager,
|
ResourceManager,
|
||||||
Resource,
|
Resource,
|
||||||
ResourceType,
|
ResourceType,
|
||||||
|
GM_info
|
||||||
};
|
};
|
||||||
const resources = new ResourceManager();
|
const resources = new ResourceManager();
|
||||||
resources.fetch().catch(error => logError(error));
|
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) =>
|
return (_, resources) =>
|
||||||
{
|
{
|
||||||
const VideoInfo = resources.attributes.videoInfo.export.VideoInfo;
|
// const VideoInfo = resources.attributes.videoInfo.export.VideoInfo;
|
||||||
const BangumiInfo = resources.attributes.videoInfo.export.BangumiInfo;
|
// const BangumiInfo = resources.attributes.videoInfo.export.BangumiInfo;
|
||||||
const pageData = {
|
const pageData = {
|
||||||
aid: undefined,
|
aid: undefined,
|
||||||
cid: undefined,
|
cid: undefined,
|
||||||
isBangumi: false,
|
isBangumi: false,
|
||||||
isMovie: 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
|
class VideoFormat
|
||||||
{
|
{
|
||||||
constructor(quality, internalName, displayName)
|
constructor(quality, internalName, displayName)
|
||||||
@ -28,35 +37,53 @@
|
|||||||
{
|
{
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
{
|
{
|
||||||
const url = `https://api.bilibili.com/x/player/playurl?avid=${pageData.aid}&cid=${pageData.cid}&otype=json`;
|
function downloadFormats(url)
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
xhr.addEventListener("load", () =>
|
|
||||||
{
|
{
|
||||||
const json = JSON.parse(xhr.responseText);
|
const xhr = new XMLHttpRequest();
|
||||||
if (json.code !== 0)
|
xhr.addEventListener("load", () =>
|
||||||
{
|
{
|
||||||
reject("获取清晰度信息失败.");
|
const json = JSON.parse(xhr.responseText);
|
||||||
}
|
if (json.code !== 0)
|
||||||
const data = json.data;
|
{
|
||||||
const qualities = data.accept_quality;
|
reject("获取清晰度信息失败.");
|
||||||
const internalNames = data.accept_format.split(",");
|
}
|
||||||
const displayNames = data.accept_description;
|
const data = json.data;
|
||||||
const formats = [];
|
const qualities = data.accept_quality;
|
||||||
while (qualities.length > 0)
|
const internalNames = data.accept_format.split(",");
|
||||||
{
|
const displayNames = data.accept_description;
|
||||||
const format = new VideoFormat(
|
const formats = [];
|
||||||
qualities.pop(),
|
while (qualities.length > 0)
|
||||||
internalNames.pop(),
|
{
|
||||||
displayNames.pop()
|
const format = new VideoFormat(
|
||||||
);
|
qualities.pop(),
|
||||||
formats.push(format);
|
internalNames.pop(),
|
||||||
}
|
displayNames.pop()
|
||||||
resolve(formats);
|
);
|
||||||
});
|
formats.push(format);
|
||||||
xhr.addEventListener("error", () => reject(`获取清晰度信息失败.`));
|
}
|
||||||
xhr.withCredentials = true;
|
resolve(formats);
|
||||||
xhr.open("GET", url);
|
});
|
||||||
xhr.send();
|
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()
|
async function loadPageData()
|
||||||
{
|
{
|
||||||
const result = await (async () =>
|
const aid = await SpinQuery.select(() => (unsafeWindow || window).aid);
|
||||||
{
|
const cid = await SpinQuery.select(() => (unsafeWindow || window).cid);
|
||||||
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;
|
|
||||||
pageData.aid = aid;
|
pageData.aid = aid;
|
||||||
pageData.cid = cid;
|
pageData.cid = cid;
|
||||||
|
if (document.URL.indexOf("bangumi") !== -1)
|
||||||
|
{
|
||||||
|
pageData.isBangumi = true;
|
||||||
|
}
|
||||||
return aid !== undefined && cid !== undefined;
|
return aid !== undefined && cid !== undefined;
|
||||||
}
|
}
|
||||||
async function loadWidget()
|
async function loadWidget()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user