ximalaya-download

喜马拉雅音乐或视频下载

目前为 2024-07-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name ximalaya-download
  3. // @namespace https://gf.qytechs.cn/zh-CN/users/135090
  4. // @grant none
  5. // @version 1.3.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. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. if (location.pathname.includes("/sound/")){
  20. var playurl;
  21. var title=document.querySelector("h1.title")?.textContent || document.querySelector("h1.title-wrapper")?.textContent;
  22. if (window?.location?.pathname?.includes("sound")){
  23. var trackid=window?.location?.pathname?.split("/")[2];
  24. var item={
  25. id:trackid
  26. };
  27. setTimeout(function(){
  28. var link = document.createElement("a");
  29. var container = document.body;
  30. link.id="mp4";
  31. link.download=title.concat(".mp4");
  32. link.style="position:fixed;top:8%;left:8%";
  33. link.style.display = "block";
  34. link.style.color = "#230de5";
  35. link.textContent=title.concat("-MP4");
  36. getAllMusicURL2(item).then(result=>{
  37. playurl=result?.toString();
  38. return playurl;
  39. }).then(data=>{console.log(link.href=data)});
  40. container.append(link);
  41. },2000);
  42. }
  43. async function getAllMusicURL2(item) {
  44. function decrypt(t) {
  45. return CryptoJS.AES.decrypt({
  46. ciphertext: CryptoJS.enc.Base64url.parse(t)
  47. }, CryptoJS.enc.Hex.parse('aaad3e4fd540b0f79dca95606e72bf93'), {
  48. mode: CryptoJS.mode.ECB,
  49. padding: CryptoJS.pad.Pkcs7
  50. }).toString(CryptoJS.enc.Utf8);
  51. }
  52. var res = null;
  53. var ares = null;
  54. const timestamp = Date.parse(new Date());
  55. var url = `https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/${timestamp}?device=web&trackId=${item.id}&forVideo=true&needMp4=true`;
  56. var aurl =`https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/${timestamp}?device=web&trackId=${item.id}`;
  57. $.ajax({
  58. type: 'get',
  59. url: aurl,
  60. async: false,
  61. dataType: "json",
  62. success: function(resp) {
  63. try {
  64. ares = decrypt(resp.trackInfo.playUrlList[0].url);
  65. } catch (e) {
  66. console.log("无效");
  67. }
  68. }
  69. });
  70. $.ajax({
  71. type: 'get',
  72. url: url,
  73. async: false,
  74. dataType: "json",
  75. success: function(resp) {
  76. try {
  77. res = decrypt(resp.trackInfo.playUrlList[0].url);
  78. } catch (e) {
  79. console.log("解密错误,无视频");
  80. res=ares;
  81. }
  82. }
  83. });
  84. return res;
  85. }
  86. }
  87. //获取专辑列表
  88. // https://www.ximalaya.com/revision/album/v1/getTracksList?albumId=77545064&pageNum=1&pageSize=100
  89. if (location.pathname.includes("/album/")){
  90. var alt=[];
  91. var ttls=[];
  92. var abid=location.pathname.includes("/album/") ? location.pathname.split("/")[2] : "77545064";
  93. var abapi=`https://www.ximalaya.com/revision/album/v1/getTracksList?albumId=${abid}&pageNum=1&pageSize=100`;
  94. fetch(abapi,{method:"get"})
  95. .then(res=>{return res?.json()})
  96. .then(res=>{
  97. var tracks=res?.data?.tracks;
  98. tracks.forEach(i=>{
  99. /*alt.push(i.url.split("/")[2]);ttls.push(i.title);*/
  100. alt.push(i.url);ttls.push(i.title);
  101. })
  102. })
  103. .then(function(){
  104. if (document.querySelector("div.download-more")){
  105. document.querySelector("div.download-more").remove();
  106. }
  107. document.querySelector(".sound-list>ul").innerHTML=null;
  108. document.querySelector(".sound-list>ul").style.listStyle = 'decimal';
  109. ttls.forEach((it,n)=>{
  110. console.log(it,n);
  111. var ulli=document.createElement("li");
  112. var plink=document.createElement("a");
  113. plink.href=alt[n];
  114. plink.target="_blank";
  115. plink.style.color="#088";
  116. plink.style.fontSize="20px";
  117. plink.textContent=it;
  118. ulli.append(plink);
  119. document.querySelector(".sound-list>ul").append(ulli);
  120. });
  121. });
  122. }
  123. })();

QingJ © 2025

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