ximalaya-download

喜马拉雅音乐或视频下载

  1. // ==UserScript==
  2. // @name ximalaya-download
  3. // @namespace https://gf.qytechs.cn/zh-CN/users/135090
  4. // @grant none
  5. // @version 1.4.9
  6. // @author zwb83925462
  7. // @license BSD
  8. // @description 喜马拉雅音乐或视频下载
  9. // @run-at document-end
  10. // @require https://registry.npmmirror.com/ajax-hook/3.0.3/files/dist/ajaxhook.min.js
  11. // @require https://registry.npmmirror.com/crypto-js/4.2.0/files/crypto-js.js
  12. // @require https://registry.npmmirror.com/jquery/3.7.1/files/dist/jquery.min.js
  13. // @match https://www.ximalaya.com/sound/*
  14. // @match https://www.ximalaya.com/album/*
  15. // @match https://m.ximalaya.com/album/*
  16. // @match https://m.ximalaya.com/selfshare/album*
  17. // @match https://m.ximalaya.com/m-revision/common/album/*
  18. // ==/UserScript==
  19.  
  20. setTimeout(function () {
  21. 'use strict';
  22. //获取单曲解析结果
  23. if (location?.pathname?.indexOf("sound") > 0) {
  24. var playurl;
  25. if (window.location.pathname.indexOf("sound") > 0) {
  26. var trackid = window.location.pathname.split("/")[2];
  27. var stitle = "xm";
  28. var xmitem = {
  29. id: trackid,
  30. ttl: stitle
  31. };
  32. setTimeout(function () {
  33. var link = document.createElement("a");
  34. var container = document.body;
  35. link.id = "mp4";
  36. link.style = "position:fixed;top:10%;left:2%";
  37. link.style.display = "block";
  38. link.style.color = "#230de5";
  39. getAllMusicURL2(xmitem).then(result => {
  40. playurl = result?.toString();
  41. return playurl;
  42. }).then(data => {
  43. if (data == undefined) {
  44. link.textContent = "未购买,无法下载";
  45. link.style.fontSize = "20px";
  46. link.style.color = "#F00";
  47. } else {
  48. link.download = xmitem.ttl;
  49. link.textContent = xmitem.ttl;
  50. console.log(link.href = data);
  51. }
  52. });
  53. container.append(link);
  54. }, 2500);
  55. }
  56. async function getAllMusicURL2(item) {
  57. function decrypt(t) {
  58. return CryptoJS.AES.decrypt({
  59. ciphertext: CryptoJS.enc.Base64url.parse(t)
  60. }, CryptoJS.enc.Hex.parse('aaad3e4fd540b0f79dca95606e72bf93'), {
  61. mode: CryptoJS.mode.ECB,
  62. padding: CryptoJS.pad.Pkcs7
  63. }).toString(CryptoJS.enc.Utf8);
  64. }
  65. var res = null;
  66. var ares = null;
  67. const timestamp = Date.parse(new Date());
  68. var url = `https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/${timestamp}?device=web&trackId=${item.id}&forVideo=true&needMp4=true`;
  69. var aurl = `https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/${timestamp}?device=web&trackId=${item.id}`;
  70. $.ajax({
  71. type: 'get',
  72. url: aurl,
  73. async: false,
  74. dataType: "json",
  75. success: function (resp) {
  76. try {
  77. ares = decrypt(resp.trackInfo.playUrlList[0].url);
  78. item.ttl = resp.trackInfo.title;
  79. } catch (e) {
  80. console.log("无效");
  81. }
  82. }
  83. });
  84. $.ajax({
  85. type: 'get',
  86. url: url,
  87. async: false,
  88. dataType: "json",
  89. success: function (resp) {
  90. try {
  91. res = decrypt(resp.trackInfo.playUrlList[0].url);
  92. item.ttl += ".mp4";
  93. } catch (e) {
  94. console.log("解密错误,无视频");
  95. res = ares;
  96. item.ttl += ".m4a";
  97. }
  98. }
  99. });
  100. return res;
  101. }
  102. }
  103. //PC视图
  104. if (location.pathname.indexOf("/album/") == 0 && location.hostname == "www.ximalaya.com") {
  105. var abid = location.pathname.indexOf("/album/") == 0 ? location.pathname.split("/")[2] : "77545064";
  106. var abapi = `https://m.ximalaya.com/m-revision/common/album/queryAlbumTrackRecordsByPage?albumId=${abid}&page=1&pageSize=10&asc=true`;
  107. //setTimeout(function(){window.open(abapi);},2500);
  108. setTimeout(function () { window.location.href = abapi; }, 2500);
  109. }
  110. //移动版视图
  111. if (location.pathname.indexOf("/album/") == 0 && location.hostname == "m.ximalaya.com") {
  112. window.location.href = "https://www.ximalaya.com/album/" + location.pathname.split("/")[2];
  113. }
  114. //移动版分享视图
  115. if (location.pathname.indexOf("/selfshare/album") == 0 && location.hostname == "m.ximalaya.com") {
  116. window.location.href = "https://www.ximalaya.com/album/" + location.pathname.split("/")[3];
  117. }
  118. //API结果页解析
  119. if (location.pathname.indexOf("/m-revision/common/album/") == 0 && location.hostname == "m.ximalaya.com") {
  120. var alt = [];
  121. var ttls = [];
  122. var ttc = 0;
  123. var dbt = JSON.parse(document.body.textContent);
  124. if (dbt?.ret > 0) {
  125. document.body.textContent = "请刷新后重试";
  126. } else {
  127. var data = dbt?.data;
  128. var ttc = data?.totalCount;
  129. var pagenums = (ttc / 10 | 0) + (ttc % 10 > 0 ? 1 : 0);
  130. console.log(ttc + "个", pagenums + "页");
  131. var tracks = data?.trackDetailInfos;
  132. if (tracks == undefined) {
  133. alert("请刷新专辑页重试");
  134. } else {
  135. tracks.forEach(i => {
  136. alt.push(i.pageUriInfo.url);
  137. ttls.push(i.trackInfo.title);
  138. });
  139. var morehtm = `<p id=tip>专辑曲目共${ttc}条.</p>`;
  140. var pns = pagenums;
  141. if (pns > 1) {
  142. morehtm = `<p id=tip>专辑曲目共${ttc}条.最大页码为${pns}</p>`;
  143. var alink = document.createElement("p");
  144. alink.innerHTML = morehtm;
  145. document.body.append(alink);
  146. }
  147. var h2p = document.createElement("ul");
  148. h2p.id = "h2u";
  149. h2p.position = "absolute";
  150. h2p.style.display = "table";
  151. h2p.style.color = "#230de5";
  152. h2p.style.listStyle = 'decimal';
  153. h2p.style.paddingTop = "0";
  154. h2p.style.paddingBottom = "50px";
  155. document.body.append(h2p);
  156. ttls.forEach((it, n) => {
  157. console.log(it, n + 1);
  158. var ulli = document.createElement("li");
  159. var plink = document.createElement("a");
  160. plink.href = "https://www.ximalaya.com" + alt[n];
  161. plink.target = "_blank";
  162. plink.style.color = "#088";
  163. plink.style.fontSize = "20px";
  164. plink.textContent = String(n + 1).concat(".") + it;
  165. ulli.append(plink);
  166. document.querySelector("#h2u").append(ulli);
  167. });
  168. }
  169. }
  170. }
  171. /*
  172. //API结果页解析
  173. if (location.pathname.indexOf("/m-revision/common/album/") == 0 && location.hostname == "m.ximalaya.com"){
  174. var alt=[];
  175. var ttls=[];
  176. var trackcount=0;
  177. setTimeout(function () {
  178. fetch(location.href, { method: "get", headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }, accept: atob("Ki8q") })
  179. .then(res => { var jsondata = res?.json(); return jsondata; })
  180. .then(res => {
  181. var resdata = res?.data;
  182. trackcount = resdata?.totalCount;
  183. var pagenums = (trackcount / 10 | 0) + (trackcount % 10 > 0 ? 1 : 0);
  184. //var pagenums = (trackcount % 100 >0 ? trackcount+100 : trackcount) / 100 | 0;
  185. console.log(trackcount + "个", pagenums + "页");
  186. var tracks = resdata?.trackDetailInfos;
  187. if (tracks == undefined) {
  188. alert("请刷新专辑页重试");
  189. } else {
  190. tracks.forEach(i => {
  191. alt.push(i.pageUriInfo.url);
  192. ttls.push(i.trackInfo.title);
  193. });
  194. }
  195.  
  196. return pagenums;
  197. })
  198. .then(pns => {
  199. if (pns > 1) {
  200. var ttll = trackcount;
  201. if (ttll > 0) {
  202. var morehtm = `<p id=tip>专辑曲目共${ttll}条,请修改API参数后再访问.最大页码为${pns}</p>`;
  203. } else {
  204. ttll = ttls.length;
  205. var morehtm = `<p id=tip>专辑曲目超过${ttll}条,请修改API参数后再访问.最大页码为${pns}</p>`;
  206. }
  207. var alink = document.createElement("p");
  208. alink.innerHTML = morehtm;
  209. document.body.append(alink);
  210. }
  211. var h2p = document.createElement("ul");
  212. h2p.id = "h2u";
  213. h2p.position = "absolute";
  214. h2p.style.display = "table";
  215. h2p.style.color = "#230de5";
  216. h2p.style.listStyle = 'decimal';
  217. h2p.style.paddingTop = "0";
  218. h2p.style.paddingBottom = "50px";
  219. document.body.append(h2p);
  220. ttls.forEach((it, n) => {
  221. console.log(it, n + 1);
  222. var ulli = document.createElement("li");
  223. var plink = document.createElement("a");
  224. plink.href = "https://www.ximalaya.com" + alt[n];
  225. plink.target = "_blank";
  226. plink.style.color = "#088";
  227. plink.style.fontSize = "20px";
  228. plink.textContent = String(n + 1).concat(".") + it;
  229. ulli.append(plink);
  230. document.querySelector("#h2u").append(ulli);
  231. });
  232. });
  233. }, 2500);
  234. }
  235. */
  236. }, 200);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址