// ==UserScript== // @name ximalaya-download // @namespace https://greasyfork.org/zh-CN/users/135090 // @grant none // @version 1.3.8 // @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/* // @downloadURL none // ==/UserScript== (function() { 'use strict'; var playurl; var title=document.querySelector("h1.title")?.textContent || document.querySelector("h1.title-wrapper")?.textContent; if (window?.location?.pathname?.includes("sound")){ var trackid=window?.location?.pathname?.split("/")[2]; var item={ id:trackid }; setTimeout(function(){ var link = document.createElement("a"); var container = document.body; link.id="mp4"; link.download=title.concat(".mp4"); link.style="position:fixed;top:8%;left:8%"; link.style.display = "block"; link.style.color = "#230de5"; link.textContent=title.concat("-MP4"); getAllMusicURL2(item).then(result=>{ playurl=result?.toString(); return playurl; }).then(data=>{console.log(link.href=data)}); container.append(link); },2000); } 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); } catch (e) { console.log("无效"); } } }); $.ajax({ type: 'get', url: url, async: false, dataType: "json", success: function(resp) { try { res = decrypt(resp.trackInfo.playUrlList[0].url); } catch (e) { console.log("解密错误,无视频"); res=ares; } } }); return res; } })();