隨筆 - 22  文章 - 467  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(25)

          隨筆分類(74)

          文章分類(1)

          收藏夾(277)

          在線工具

          在線資料

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 218127
          • 排名 - 261

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          // 打開(kāi)豆瓣電臺(tái) https://douban.fm/mine/# , 記得登錄, 看到自己的紅心列表就行
          // 按F12
          // 先拷貝下面這段到 console 運(yùn)行, 注入 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);

          //上面執(zhí)行成功再拷貝執(zhí)行下面的:

          var sectionCount = 100; // 每次從豆瓣拉取幾條歌曲詳情
          var outputCount = 150; // 每個(gè)區(qū)塊輸出幾首歌曲, 超過(guò)150條QQ音樂(lè)無(wú)法識(shí)別
          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("開(kāi)始抓取歌曲 " + 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("準(zhǔn)備展示數(shù)據(jù): " + 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("歌曲標(biāo)題<br>時(shí)長(zhǎng)<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("數(shù)據(jù)展示完成");
              alert("完成, 請(qǐng)剪切區(qū)塊內(nèi)容到導(dǎo)入頁(yè)面");
          }

          // 最后, 將頁(yè)面中出現(xiàn)的每個(gè)區(qū)塊內(nèi)容分別剪切到QQ音樂(lè)的網(wǎng)易云導(dǎo)入頁(yè)面:
          // https://y.qq.com/portal/songlist_import.html?tab=2 
          // PS. 記得登錄.
          posted on 2017-08-11 16:13 ApolloDeng 閱讀(1493) 評(píng)論(0)  編輯  收藏 所屬分類: Js/JQuery/Ajax
          主站蜘蛛池模板: 双峰县| 平潭县| 长子县| 新泰市| 梧州市| 铜山县| 山西省| 阿坝县| 磴口县| 新泰市| 当阳市| 衡南县| 巴南区| 平利县| 六盘水市| 闽侯县| 虹口区| 潼南县| 株洲县| 博爱县| 新邵县| 盱眙县| 和龙市| 怀仁县| 玛纳斯县| 若尔盖县| 汶川县| 泽州县| 禹城市| 灵宝市| 达尔| 莱西市| 渭南市| 光山县| 雷波县| 伊宁县| 门源| 贵州省| 兴和县| 邻水| 文化|