// ==UserScript== // @name ximalaya-download // @namespace https://greasyfork.org/zh-CN/users/135090 // @grant none // @version 1.4.9 // @author zwb83925462 // @license BSD // @description 喜马拉雅音乐或视频下载 // @run-at document-end // @require https://registry.npmmirror.com/ajax-hook/3.0.3/files/dist/ajaxhook.min.js // @require https://registry.npmmirror.com/crypto-js/4.2.0/files/crypto-js.js // @require https://registry.npmmirror.com/jquery/3.7.1/files/dist/jquery.min.js // @match https://www.ximalaya.com/sound/* // @match https://www.ximalaya.com/album/* // @match https://m.ximalaya.com/album/* // @match https://m.ximalaya.com/selfshare/album* // @match https://m.ximalaya.com/m-revision/common/album/* // @downloadURL https://update.greasyfork.icu/scripts/438365/ximalaya-download.user.js // @updateURL https://update.greasyfork.icu/scripts/438365/ximalaya-download.meta.js // ==/UserScript== setTimeout(function () { 'use strict'; //获取单曲解析结果 if (location?.pathname?.indexOf("sound") > 0) { var playurl; if (window.location.pathname.indexOf("sound") > 0) { var trackid = window.location.pathname.split("/")[2]; var stitle = "xm"; var xmitem = { id: trackid, ttl: stitle }; setTimeout(function () { var link = document.createElement("a"); var container = document.body; link.id = "mp4"; link.style = "position:fixed;top:10%;left:2%"; link.style.display = "block"; link.style.color = "#230de5"; getAllMusicURL2(xmitem).then(result => { playurl = result?.toString(); return playurl; }).then(data => { if (data == undefined) { link.textContent = "未购买,无法下载"; link.style.fontSize = "20px"; link.style.color = "#F00"; } else { link.download = xmitem.ttl; link.textContent = xmitem.ttl; console.log(link.href = data); } }); container.append(link); }, 2500); } async function getAllMusicURL2(item) { function decrypt(t) { return CryptoJS.AES.decrypt({ ciphertext: CryptoJS.enc.Base64url.parse(t) }, CryptoJS.enc.Hex.parse('aaad3e4fd540b0f79dca95606e72bf93'), { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString(CryptoJS.enc.Utf8); } var res = null; var ares = null; const timestamp = Date.parse(new Date()); var url = `https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/${timestamp}?device=web&trackId=${item.id}&forVideo=true&needMp4=true`; var aurl = `https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/${timestamp}?device=web&trackId=${item.id}`; $.ajax({ type: 'get', url: aurl, async: false, dataType: "json", success: function (resp) { try { ares = decrypt(resp.trackInfo.playUrlList[0].url); item.ttl = resp.trackInfo.title; } catch (e) { console.log("无效"); } } }); $.ajax({ type: 'get', url: url, async: false, dataType: "json", success: function (resp) { try { res = decrypt(resp.trackInfo.playUrlList[0].url); item.ttl += ".mp4"; } catch (e) { console.log("解密错误,无视频"); res = ares; item.ttl += ".m4a"; } } }); return res; } } //PC视图 if (location.pathname.indexOf("/album/") == 0 && location.hostname == "www.ximalaya.com") { var abid = location.pathname.indexOf("/album/") == 0 ? location.pathname.split("/")[2] : "77545064"; var abapi = `https://m.ximalaya.com/m-revision/common/album/queryAlbumTrackRecordsByPage?albumId=${abid}&page=1&pageSize=10&asc=true`; //setTimeout(function(){window.open(abapi);},2500); setTimeout(function () { window.location.href = abapi; }, 2500); } //移动版视图 if (location.pathname.indexOf("/album/") == 0 && location.hostname == "m.ximalaya.com") { window.location.href = "https://www.ximalaya.com/album/" + location.pathname.split("/")[2]; } //移动版分享视图 if (location.pathname.indexOf("/selfshare/album") == 0 && location.hostname == "m.ximalaya.com") { window.location.href = "https://www.ximalaya.com/album/" + location.pathname.split("/")[3]; } //API结果页解析 if (location.pathname.indexOf("/m-revision/common/album/") == 0 && location.hostname == "m.ximalaya.com") { var alt = []; var ttls = []; var ttc = 0; var dbt = JSON.parse(document.body.textContent); if (dbt?.ret > 0) { document.body.textContent = "请刷新后重试"; } else { var data = dbt?.data; var ttc = data?.totalCount; var pagenums = (ttc / 10 | 0) + (ttc % 10 > 0 ? 1 : 0); console.log(ttc + "个", pagenums + "页"); var tracks = data?.trackDetailInfos; if (tracks == undefined) { alert("请刷新专辑页重试"); } else { tracks.forEach(i => { alt.push(i.pageUriInfo.url); ttls.push(i.trackInfo.title); }); var morehtm = `
专辑曲目共${ttc}条.
`; var pns = pagenums; if (pns > 1) { morehtm = `专辑曲目共${ttc}条.最大页码为${pns}
`; var alink = document.createElement("p"); alink.innerHTML = morehtm; document.body.append(alink); } var h2p = document.createElement("ul"); h2p.id = "h2u"; h2p.position = "absolute"; h2p.style.display = "table"; h2p.style.color = "#230de5"; h2p.style.listStyle = 'decimal'; h2p.style.paddingTop = "0"; h2p.style.paddingBottom = "50px"; document.body.append(h2p); ttls.forEach((it, n) => { console.log(it, n + 1); var ulli = document.createElement("li"); var plink = document.createElement("a"); plink.href = "https://www.ximalaya.com" + alt[n]; plink.target = "_blank"; plink.style.color = "#088"; plink.style.fontSize = "20px"; plink.textContent = String(n + 1).concat(".") + it; ulli.append(plink); document.querySelector("#h2u").append(ulli); }); } } } /* //API结果页解析 if (location.pathname.indexOf("/m-revision/common/album/") == 0 && location.hostname == "m.ximalaya.com"){ var alt=[]; var ttls=[]; var trackcount=0; setTimeout(function () { fetch(location.href, { method: "get", headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }, accept: atob("Ki8q") }) .then(res => { var jsondata = res?.json(); return jsondata; }) .then(res => { var resdata = res?.data; trackcount = resdata?.totalCount; var pagenums = (trackcount / 10 | 0) + (trackcount % 10 > 0 ? 1 : 0); //var pagenums = (trackcount % 100 >0 ? trackcount+100 : trackcount) / 100 | 0; console.log(trackcount + "个", pagenums + "页"); var tracks = resdata?.trackDetailInfos; if (tracks == undefined) { alert("请刷新专辑页重试"); } else { tracks.forEach(i => { alt.push(i.pageUriInfo.url); ttls.push(i.trackInfo.title); }); } return pagenums; }) .then(pns => { if (pns > 1) { var ttll = trackcount; if (ttll > 0) { var morehtm = `专辑曲目共${ttll}条,请修改API参数后再访问.最大页码为${pns}
`; } else { ttll = ttls.length; var morehtm = `专辑曲目超过${ttll}条,请修改API参数后再访问.最大页码为${pns}
`; } var alink = document.createElement("p"); alink.innerHTML = morehtm; document.body.append(alink); } var h2p = document.createElement("ul"); h2p.id = "h2u"; h2p.position = "absolute"; h2p.style.display = "table"; h2p.style.color = "#230de5"; h2p.style.listStyle = 'decimal'; h2p.style.paddingTop = "0"; h2p.style.paddingBottom = "50px"; document.body.append(h2p); ttls.forEach((it, n) => { console.log(it, n + 1); var ulli = document.createElement("li"); var plink = document.createElement("a"); plink.href = "https://www.ximalaya.com" + alt[n]; plink.target = "_blank"; plink.style.color = "#088"; plink.style.fontSize = "20px"; plink.textContent = String(n + 1).concat(".") + it; ulli.append(plink); document.querySelector("#h2u").append(ulli); }); }); }, 2500); } */ }, 200);