Netease Music Download

网易云音乐下载地址

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Netease Music Download
// @namespace   qixinglu.com
// @description 网易云音乐下载地址
// @include     http://music.163.com/*
// @grant       none
// @version 0.0.1.20140517140352
// ==/UserScript==

var api = {

    detailUrl: function(songIds) {
        var tpl = 'http://music.163.com/api/song/detail?ids=[${songIds}]';
        return tpl.replace('${songIds}', songIds.join(','));
    },

    detail: function(songIds, callback) {
        var req = new XMLHttpRequest();
        req.open('GET', this.detailUrl(songIds), true);
        req.onload = function() {
            callback(JSON.parse(this.responseText));
        };
        req.send();
    },

    mediaUrl: function(songId) {
        return 'http://music.163.com/api/song/media?id=' + songId;
    },

    media: function(songId, callback) {
        var req = new XMLHttpRequest();
        req.open('GET', this.mediaUrl(songId), true);
        req.onload = function() {
            callback(JSON.parse(this.responseText));
        };
        req.send();
    },

};

var innerFrame = document.querySelector('iframe');

var pages = [
{
    url: 'http://music.163.com/#/m/song?id=',
    handler: function() {
        var songId = location.href.match(/id=([0-9]+)/)[1];
        var downloadLine = this.createDownloadLine(songId);

        var innerFrameDoc = innerFrame.contentWindow.document;
        var albumNode = innerFrameDoc.querySelectorAll('p.des.s-fc4')[1];
        var parentNode = albumNode.parentNode;
        parentNode.insertBefore(downloadLine, albumNode.nextElementSibling);
    },
    createDownloadLine: function(songId) {
        var disableStyle = function(link) {
            link.text += '(无)';
            link.style.color = 'gray';
            link.style.textDecoration = 'none';
            link.style.cursor = 'auto';
        };

        var mp3Link = this.createLink('歌曲');
        var lyricLink = this.createLink('歌词');

        api.detail([songId], function(result) {
            var song = result.songs[0];
            mp3Link.href = song.mp3Url;
        });
        api.media(songId, function(result) {
            if (result.lyric) {
                lyricLink.href = 'data:text/plain;charset=utf-8,' +
                                 encodeURIComponent(result.lyric);
            } else {
                disableStyle(lyricLink);
            }
        });

        var container = this.createLineContainer('下载');
        container.appendChild(mp3Link);
        container.appendChild(lyricLink);
        return container;
    },
    createLink: function(label) {
        var link = document.createElement('a');
        link.innerHTML = label;
        link.className = 's-fc7';
        link.style.marginRight = '10px';
        link.href = 'javascript:void(0);';
        return link;
    },
    createLineContainer: function(label) {
        var container = document.createElement('p');
        container.className = 'desc s-fc4';
        container.innerHTML = label + ':';
        container.style.margin = '10px 0';
        return container;
    },
},
]

if (innerFrame) {
    innerFrame.addEventListener('load', function() {
        var i, page;
        for (i = 0; i < pages.length; i += 1) {
            var page = pages[i];
            if (location.href.indexOf(page.url) == 0) {
                page.handler();
            }
        }
    });
}