-
-
Save tt7/b665c076c572bad99497125c621a580f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Music Link Extractor | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description getmusic is here: ca8543d410e330b8608c23df86dab425 | |
// @author tt7 | |
// @match http://music.163.com/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
+ function (w) { | |
var host = "localhost"; | |
var port = 6800; | |
var token = ""; | |
var get = function (url) { | |
return new Promise(function (hd, rj) { | |
let r = new XMLHttpRequest(); | |
r.open("GET", url); | |
r.onload = function () { | |
r.status == 200 && hd(r.response) || rj(r.status); | |
}; | |
r.onerror = function () {}; | |
r.send(); | |
}); | |
}; | |
var msgTools = (function () { | |
var d = top.document; | |
var box = d.createElement("div"); | |
box.style.position = "absolute"; | |
box.style.top = "105px"; | |
box.style.opacity = "0.85"; | |
box.style.left = "50%"; | |
box.style.marginLeft = "-360px"; | |
box.style.width = "720px"; | |
box.style.height = "500px"; | |
var ta = d.createElement("textarea"); | |
ta.style.width = "100%"; | |
ta.style.height = "100%"; | |
ta.disabled = true; | |
box.appendChild(ta); | |
var cl = d.createElement("div"); | |
cl.style.width = "30px"; | |
cl.style.height = "30px"; | |
cl.innerText = "X"; | |
cl.style.position = "absolute"; | |
cl.style.top = "5px"; | |
cl.style.right = "5px"; | |
cl.style.marginRight = "15px"; | |
cl.style.textAlign = "center"; | |
cl.style.verticalAlign = "middle"; | |
cl.style.lineHeight = "30px"; | |
cl.style.border = "1px black dashed"; | |
box.appendChild(cl); | |
d.body.appendChild(box); | |
var showMessage = function (msg) { | |
ta.value = msg; | |
box.style.display = "block"; | |
}; | |
var hideMessage = function () { | |
box.style.display = "none"; | |
}; | |
cl.addEventListener("click", hideMessage); | |
cl.addEventListener("mouseover", function () { | |
cl.style.backgroundColor = "#111"; | |
}); | |
cl.addEventListener("mouseout", function () { | |
cl.style.backgroundColor = "#FFF"; | |
}); | |
hideMessage(); | |
return [showMessage, hideMessage]; | |
})(); | |
var showMsg = msgTools[0]; | |
var hideMsg = msgTools[1]; | |
get("https://cdn1.lncld.net/static/js/av-mini-0.6.4.js").then(function (resp) { | |
eval(resp); | |
AV.initialize('ot1IaBu4xud3XIC5aYlV1pSK-gzGzoHsz', 'bmQ4rDPpAMtvxoQgCUhpY379'); | |
}); | |
var d = w.top.document; | |
var pframe = d.getElementById("g_iframe"); | |
var aa = Function.prototype.apply.bind(Array.prototype.slice); | |
function extractUrls() { | |
showMsg("starting to extract, please wait..."); | |
var ous = []; + | |
function (d, ous) { | |
if (!d) { | |
console.error("oops...not working."); | |
return; | |
} | |
var api = "http://music.163.com/api/song/detail?id="; | |
var sids = []; | |
aa(d.getElementsByClassName("tt")).forEach(function (el, i) { | |
sids.push(/\/?id=(\d+)/.exec(el.getElementsByTagName('a')[0].href)[1]); | |
}); | |
showMsg(sids.length + " song id's extracted."); | |
get(api + sids[0] + "&ids=[" + sids.join(',') + "]").then(function (resp) { | |
var ss = JSON.parse(resp).songs; | |
ss.forEach(function (s, i) { | |
ous.push([s.mp3Url, s.name].join("\t") + ".mp3"); | |
}); | |
showMsg(ous.length + " links fetched."); | |
var avid = AV._getInstallationId(); | |
var cmd = "getmusic --host " + host + " --port " + port + " --token " + token + " --avid " + avid + " - "; | |
var msg = "echo \"\n" + ous.join("\n") + "\" | " + cmd; | |
console.info(msg); | |
showMsg(msg); | |
}); | |
}(pframe.contentDocument, ous); | |
} | |
+function () { | |
try { | |
var doc = pframe.contentDocument; | |
var dlbt = doc.getElementsByClassName("u-btni-dl")[0]; | |
var dlbtcp = doc.createElement("a"); | |
dlbtcp.className = dlbt.className; | |
dlbtcp.href = "javascript:void(0);"; | |
dlbtcp.appendChild(dlbt.children[0].cloneNode(true)); | |
var nextbt = dlbt.nextElementSibling; | |
var p = dlbt.parentElement; | |
p.removeChild(dlbt); | |
p.insertBefore(dlbtcp, nextbt); | |
dlbtcp.addEventListener("click", extractUrls); | |
} catch (ex) { | |
console.error(ex); | |
} | |
}(); | |
}(window); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment