B-HTML5-Video
// ==UserScript==
// @name B-HTML5-Video
// @version 0.9.2
// @description 获取B站视频地址,Dash
// @author zwb
// @license CC
// @match https://www.bilibili.com/video/BV*
// @match https://www.bilibili.com/video/av*
// @run-at document-start
// @grant unsafeWindow
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAC4jAAAuIwF4pT92AAAIVklEQVR4Xu2bWYwVRRSGzyzIBYwbAmpwFzPigqCi0ZgoJooa3GKMGBg3VMAIcY3xQREFNW5xfXAF1AiKPrhEURl3E6O4srggojCCIIIgIuIM/t+cauZ6p293j3jDZZiHL5lkpk7956/q6upTNdbY2GgNDQ1bLHbjZ0tszKc/Z6FC7CmOF0PEKHGxOEv0F9uL6gxxNpbq0Ff/0PclYrQYOsa1obEiQ5wmrGrSbKuaOCsLlWKAuFNME3PFR2KquEzsJXKiIkOs/0pF6GOv0Cd9zxDzxGtVrg2NlRliNWE2cbbZhFlpdBX7i9FiuvhW/CrqxUwxWVwpjhPdRHWGmK2lOsQ+LvQ1JfT9k1gu5oo3zDWitWuGmJkN2FecKR4Vv4h1okH8HX5eKD4QY0SNyImKDHGzUhFi1oQ+6Ks+9I2GhvDzUnONaN03Q9zMBtDx2WKCuduNBawUC8SL4mr7f2dC/sgT+4XQ10prqYNZOdFca02G2K0yYHAIHmdANBMYlffFjaK3bfxMiEa+d4hJ7IXWPAPjDJgkzhH7ZYif2YAe4lBxg/gydPRXjABG5UfzmXCVGCC6m49ia42oDm0HhFgvhthxI48WNKENjWjdKUMfmQ1ATGfzqfWy+E6ssZZCmAmIYZTeNR+1g0QnUZmhn4ho5A8MMYi1IMT+O6ZftKAJbWhEa7bHL6MBCCKBfmKk+aPwlRWfCavMR+sla54JzKK0mcDvqsLfHmvZRx4tTP1LzTVWpvTTagMiuoidxXnmbvPqSZsJ74ixoo+lzwR+lwt/Oza0TRr5P8w1oOV8c21bJ8TPZA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J8Gj8CUECv/EYgKG/Rdm9C+5AawAH1iXsMvXARZqVkED0xon0bSIrgq9H1OQvuSG3CSeNZ8MfrNml9T1OQRx6FEr4T2afQKMVjtqe6sDfFXhD6nipMT2pfcAEZ3uHjCvJzO7RE2KhRSKLVxENEjoX0aHI+fHmIRc5k1b4Q47OAYLOktU3IDEEgJijM9NiXTjDLThFl3mVeRKFN1SWifRpcQAxP4rH1NUMKj9jc89N09oX3JDciZf3NTi+MjhV0Z9bjDzYsR21rWc/p4qkOMPcQRIf7A0FdN6DuX0L7kBpQ77QZYuwHtBrQbYO0GJBvAD8XK4rzPqbuV82lQMdCMdnKIS35DWTz/vm3hH90ndrPkd225guZdzXOIM8DvC8gAPirYX8cZQN2NTQ3Xz9Lu+JULaOxgfj7Y37xeGTf6HI0tw4ComBlnwNvmV09PNN9y5qy8TYgOR/n+QPP15jnEGcCB8BwMqDO/MRF3PD5fvBkCsRWl/r+LubvlCNr4gjzSfODQTg6FeZErN2KmY8C95kfIcRck+Oz8wbwkzSnrQ+JB8UCZgjYucaKVuwFoJ4c4A8j5HgzggIHS1Rorvhi2FaIrdH+a5zwMA/ik5NSFqbLc2v4lqWhWk3M/DNjK/PLgW+ZrAe60tZkQjTwVpXnmCyOnSk3X5DiAPMy8ukJl53trezOBXBh5ZjnrA7nyimy6KMnrgyvmrKJUdurMy1vR3eD8jVKxHWO5kK8RzX4LxHNh1eetwP8UkKtfq7fmy9KUn/hXk1rzQiQFR1ZKZgT7hCy3wzc1Ubl8tbnmeeY5kAs5nWs+28mVnM1yT8yx3KTZERWiWhwqLhL3ijoxSywWK8TvYnWZgjY0LhIzxfSc50Au5ERu5LghZxv3xVIb9/mSfCrFzqKvOEEMFcPFFeIacW2Zg8bLx7lmtJMDuZATuf0rX1u/fr3xD9RbKu0GYMCWzD+zDS/KNPfarwAAAABJRU5ErkJggg==
// @namespace https://greasyfork.org/zh-CN/users/135090
// ==/UserScript==
(function loop() {
if (!document.querySelector("#app")) { return setTimeout(loop, 2000); }
var appdiv = document.body;
var vm = document.createElement("a");
vm.setAttribute("id", "bvm");
var am = document.createElement("a");
am.setAttribute("id", "bam");
vm.style = "position:fixed;top:64px;right:1px;";
vm.style.display.margin = "1em 1em";
vm.style.display.color = "#23ade5";
am.style = "position:fixed;top:80px;right:1px;";
am.style.display.margin = "1em 1em";
am.style.display.color = "#23ade5";
am.download = __INITIAL_STATE__.bvid + ".m4a";
vm.download = __INITIAL_STATE__.bvid + ".m4v";
var pdata = unsafeWindow?.__playinfo__?.data;
pdata.dash.video.sort(function(a,b){return b.id-a.id});
pdata.dash.video.sort(function(a,b){return b.codecid-a.codecid});
var pddv = pdata?.dash?.video;
var pdda = pdata?.dash?.audio;
var len = 0;
vm.href = pddv[len].base_url;
am.href = pdda[0].base_url;
vm.textContent = pddv[len].codecs.substring(0, 4) + "-" + pdata?.accept_description[0];
am.textContent = pdda[0].codecs.substring(0, 4) + "-" + pdda[0].id;
appdiv.append(vm);
appdiv.append(am);
var dvd = document.createElement("a");
dvd.id = "bdvd";
dvd.style = "position:fixed;top:160px;right:1px;";
dvd.style.display.margin = "1em 1em";
dvd.style.display.color = "#23ade5";
dvd.textContent = "一步到位"
dvd.onclick = function () {
download(am.href, am.download);
download(vm.href, vm.download);
}
appdiv.append(dvd);
function download(durl, thename) {
fetch(durl, {method: "GET",referrer: location.href,mode: "cors"})
.then(res => res.blob())
.then(blob => {
let a = document.createElement('a');
if (navigator.userAgent.includes("Firefox")) appdiv.append(a);
let url = URL.createObjectURL(blob);
a.download = thename;
a.href = url;
a.click();
URL.revokeObjectURL(url);
a.remove();
}).catch(err => {
console.error(err);
})
}
})();