BV <-> AV
// ==UserScript==
// @name bilibili bv2av
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*.bilibili.com/**
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
const bvs = new URLSearchParams(location.search).get('bvs')?.split(',').filter(Boolean) || [];
if (bvs.length) {
const avs = [];
const div = document.createElement('div');
Object.assign(div.style, {
zIndex: 9999,
position: 'fixed',
top: 0,
right: 0,
fontSize: '40px',
backgroundColor: 'white',
padding: '20px',
left: 0,
textAlign: 'center'
})
document.body.append(div);
const update = (str) => {
div.innerText = str;
};
let i = 0;
update(`bv2av -> ${i}/${bvs.length}`)
bvs.reduce(async (p, bv) => {
await p;
const res = await fetch('/video/' + bv).then(res => res.text());
const [, aid] = res.match(/"aid":(\d+)/) || []
if (aid) { avs.push(`${bv}\t${aid}`) }
await new Promise(r => setTimeout(r, 200));
i ++;
update(`bv2av -> ${i}/${bvs.length}`)
}, 1).then(() => {
update(avs.join('\n'))
})
}
})();
相关视频,可以的话求个赞!👍
更新记录: 📅 2023-02-15:修复 bv 转 av 后负数问题, av 转 bv 可能还有问题。 📅 2023-02-11:支持批量转换,一行一个号,增加快捷复制功能。 📅 2024-01-30:支持添加快捷键到书签栏以快捷复制 AV 号。
算法来源: 作者:mcfx 链接:https://www.zhihu.com/question/381784377/answer/1099438784