随笔 - 22  文章 - 467  trackbacks - 0
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(25)

随笔分类(74)

文章分类(1)

收藏夹(277)

在线工具

在线资料

最新随笔

搜索

  •  

积分与排名

  • 积分 - 210701
  • 排名 - 263

最新评论

阅读排行榜

评论排行榜

// 打开豆瓣电台 https://douban.fm/mine/# , 记得登录, 看到自己的红心列表就行
// 按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音乐的网易云导入页面:
// https://y.qq.com/portal/songlist_import.html?tab=2 
// PS. 记得登录.
posted on 2017-08-11 16:13 ApolloDeng 阅读(1413) 评论(0)  编辑  收藏 所属分类: Js/JQuery/Ajax

只有注册用户登录后才能发表评论。


网站导航: