// 按F12
// 先拷贝下面这段到 console 运行, 注入 jquery 功能
var body = document.getElementsByTagName('body')[0];
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', 'https://code.jquery.com/jquery-3.2.1.min.js');
body.appendChild(s);
//上面执行成功再拷贝执行下面的:
var sectionCount = 100; // 每次从豆瓣拉取几条歌曲详情
var outputCount = 150; // 每个区块输出几首歌曲, 超过150条QQ音乐无法识别
var limit = 0; // 只获取前 limit 首歌曲
var songIds = [];
var songSection = [];
var songInfos = []
start();
function start() {
$.get("https://douban.fm/j/v2/redheart/basic", function (data) {
for (var i in data.songs) {
songIds.push(data.songs[i].sid);
}
if (limit > 0) {
songIds = songIds.slice(0, limit);
}
console.log("获取到歌曲id " + songIds.length + "条");
loadSection();
});
}
function loadSection() {
songSection = [];
var count = (songIds.length < sectionCount) ? songIds.length : sectionCount;
songSection = songIds.slice(0, count);
songIds.splice(0, count);
var sectionIds = songSection.join("|");
console.log("开始抓取歌曲 " + songSection.length + "条");
console.log("剩余歌曲 " + songIds.length + "条");
$.post("https://douban.fm/j/v2/redheart/songs", {
sids: sectionIds,
kbps: 192,
ck: "lM1o"
}, function (data) {
// console.log(data);
for (var i in data) {
var songInfo = {};
songInfo.title = data[i].title;
songInfo.artist = data[i].artist;
songInfo.album = data[i].albumtitle;
songInfos.push(songInfo);
}
//console.log(songInfos);
if (songSection.length < sectionCount) {
processInfos();
} else {
setTimeout(loadSection, 3 * 1000);
}
});
}
function processInfos() {
$("body").html("");
console.log("准备展示数据: " + songInfos.length + "条");
while (songInfos.length > 0) {
outputSection = [];
var count = (songInfos.length < outputCount) ? songInfos.length : outputCount;
outputSection = songInfos.slice(0, count);
songInfos.splice(0, count);
var content = [];
content.push("歌曲标题<br>时长<br>歌手<br>专辑<br><br>");
for (var i = 0; i < outputSection.length; i++) {
content.push(outputSection[i].title);
content.push("<br><br>");
content.push(outputSection[i].artist);
content.push("<br>");
content.push(outputSection[i].album);
content.push("<br><br>");
}
$("body").append("<div contenteditable=\"true\" style=\"border: 1px solid black;" +
"padding: 1rem;margin: 1rem;max-height: 150px;overflow-y: scroll;\"><div>");
$("body > div:last").html(content.join(""));
}
console.log("数据展示完成");
alert("完成, 请剪切区块内容到导入页面");
}
// 最后, 将页面中出现的每个区块内容分别剪切到QQ音乐的网易云导入页面:
// PS. 记得登录.
posted on 2017-08-11 16:13
ApolloDeng 阅读(1468)
评论(0) 编辑 收藏 所属分类:
Js/JQuery/Ajax