自动下载酷狗音乐

try to take over the world!

目前為 2020-05-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name         自动下载酷狗音乐
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      *://*.kugou.com/song*
// @match        https://www.zuihuimai.net/vrhr/loading.php
// @grant        GM_download
// @grant        GM_openInTab
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @grant        unsafeWindow
// @grant        GM_setClipboard
// @grant        GM_getResourceURL
// @grant        GM_getResourceText
// @connect      *

// ==/UserScript==

(function() {
    'use strict';

    if(window.GM_download){
        console.log("此时可以使用");
    }else{
        console.log("--------------------");
    }

    function getHashParams(key) {
        var arr = location.hash.replace("#", "").split("&"), keyValue = "";
        for (var i = 0;i<arr.length;i++) {
            if (arr[i].split("=")[0] == key) {
                keyValue = arr[i].split("=")[1];
                break;
            }
        }
        return keyValue;
    }

    unsafeWindow.download_mp3=function(){

        var hash, album_id;
        if (location.hash != "") {
            hash = getHashParams("hash");
            album_id = getHashParams("album_id");
        }

        console.log(hash,album_id);
        //https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash=BB21CA72E4023E7040F7B29F3259E13C&album_id=976137&dfid=33V8Ma31zLZ10pe7Hh1qzZzL&mid=da81c414c54b0a6a51e239a1459c2441&platid=4&_=1588925428584
        var dfid="";
        var mid="";
        //     setInterval(function(){
        //        console.log("kgUser=",window.KgUser);
        //        console.log("location.href=",location.href);
        //         console.log("hash=",location.hash);
        //     },1000);
        window.KgUser && (dfid = KgUser.getDfid(1014), mid = KgUser.getKgMid())
        let req_url = "https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash="+hash+"&album_id="+album_id+"&dfid="+dfid+"&mid="+mid+"&platid=4"
        console.log("请求地址:",req_url);
        GM_xmlhttpRequest({
            method: "GET",
            url: req_url,
            headers: { "Content-Type": "application/x-www-form-urlencoded" },
            responseType: "json",
            onload: function(r){
                console.log(r);
                if(r.readyState == 4){
                    var res = r.response.data;
                    console.log("mp3地址", res.play_url);
                    GM_download({
                        url: res.play_url,
                        name: res.audio_name+".mp3",
                        onload: function(){
                            console.log(res.sony_name, "下载完成");
                        },
                        onerror: function(error){
                            console.log(res.sony_name, "下载失败", error);
                        }
                    })
                }
            },
            onerror: function(err){
                console.log("请求地址失败");
            }
        });
    }
    unsafeWindow.addEventListener("hashchange", function(){
        console.log("hash 地址变化了!");
        unsafeWindow.download_mp3();
    });


})();

QingJ © 2025

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