Skip to content

Latest commit

 

History

History
137 lines (129 loc) · 5.09 KB

20170204_xiami.md

File metadata and controls

137 lines (129 loc) · 5.09 KB

获取虾米音乐真实链接的方法

虾米音乐的真实链接在一段加密过的xml内容中, 首先要获取这段xml

获取xml的链接 :http://www.xiami.com/song/playlist/id/1771093941/object_name/collect/object_id/1771093941

  • 其中这个链接的数字部分是你要下载的歌曲的id, 比如林宥嘉的<浪费>http://www.xiami.com/song/1771093941, id就是1771093941,把链接里面的都替换掉就行

请求之后我们会得到这样一段xml

<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList><track><songId>1771093941</songId>
<songStringId>xLxse3a075d</songStringId>
<ttpodId>1225300</ttpodId>
<songName>浪费</songName>
<subName>Unrequited</subName>
<pace>142</pace>
<albumId>516102</albumId>
<albumStringId>k88sa7423</albumStringId>
<artistId>23517</artistId>
<artistStringId>6in9397a</artistStringId>
<albumTTPodId>11600</albumTTPodId>
<artist><![CDATA[林宥嘉]]></artist>
<singers>林宥嘉</singers>
<singerIds>Array</singerIds>
<pinyin>lang fei </pinyin>
<recommendCount>16537</recommendCount>
<collectCount>392756</collectCount>
<demo></demo>
<demoCreateTime>1340796375000</demoCreateTime>
<mvId>223373</mvId>
<musicType>NORMAL</musicType>
<track>4</track>
<cdSerial>1</cdSerial>
<allAudios>Array</allAudios>
<songOpt>NORMAL</songOpt>
<purviews>Array</purviews>
<parentPackagePurviews></parentPackagePurviews>
<publishStatus>PUBLISH</publishStatus>
<songwriters>陈信延</songwriters>
<composer>郑楠</composer>
<arrangement>张晁毓</arrangement>
<bakSongId>0</bakSongId>
<boughtCount>0</boughtCount>
<bakSong></bakSong>
<panFlag>0</panFlag>
<lyric>http://img.xiami.net/lyric/upload/41/1771093941_1340434506.lrc</lyric>
<song_id>1771093941</song_id>
<album_id>516102</album_id>
<name>浪费</name>
<title><![CDATA[大小说家]]></title>
<album_name><![CDATA[大小说家]]></album_name>
<sub_title>Unrequited</sub_title>
<song_sub_title>Unrequited</song_sub_title>
<artist_name>林宥嘉</artist_name>
<artist_id>23517</artist_id>
<cd_serial>1</cd_serial>
<singersSource>Array</singersSource>
<length>307</length>
<recommends>16537</recommends>
<collects>392756</collects>
<key_words></key_words>
<music_type>0</music_type>
<play_volume>89</play_volume>
<flag></flag>
<album_logo>images/album/img17/23517/5161021340071211_1.jpg</album_logo>
<needpay>0</needpay>
<mvUrl>K66QIE</mvUrl>
<playstatus>1</playstatus>
<downloadstatus>1</downloadstatus>
<downloadjson>%7B%22LOW%22%3A%22FREE%22%2C%22HIGH%22%3A%22FREE%22%2C%22LOSSLESS%22%3A%22NEED_VIP%22%7D</downloadjson>
<can_show>1</can_show>
<can_check>1</can_check>
<location>9hFl%21F35p_6aca85lt%i23619%3k7f3f2Elt2cF51745%e7777%-pFd51%71E3y8de-5%%on1751_3F%7b51E53m.7%E%3_a3c2e4%EA5c%2254luD22685-%.o2F%E5.tbd686En2amF5294mh61db7%u</location>
<lyric_url>http://img.xiami.net/lyric/upload/41/1771093941_1340434506.lrc</lyric_url>
<object_id>1771093941</object_id>
<object_name>collect</object_name>
<insert_type>1</insert_type>
<background>http://img.xiami.net/res/player/bimg/bg-5.jpg</background>
<aritst_type></aritst_type>
<artist_url>http://www.xiami.com/artist/23517</artist_url>
<grade>-1</grade>
<tryhq>0</tryhq>
<pic>http://img.xiami.net/images/album/img17/23517/5161021340071211_1.jpg</pic>
<album_pic>http://img.xiami.net/images/album/img17/23517/5161021340071211.jpg</album_pic>
<rec_note></rec_note>
</track>
</trackList>
<lastSongId>0</lastSongId>
<type>collect</type>
<type_id>1771093941</type_id>
<clearlist></clearlist>
<vip>0</vip>
<vip_role>0</vip_role>
<hqset>0</hqset>
<message></message>
</playlist>

其中大部分的标签我们都不关注, 只需要关注location里面的内容,这是一段加密过的链接 我们将location标签包裹的内容复制出来 然后用解密算法解密后就可以得到我们想要的链接

解密算法:

    function decoder(sourceString) {
        var _loc9 = Number(sourceString[0]);
        var _loc7 = sourceString.substr(1);
        var _loc5 = Math.floor(_loc7.length / _loc9);
        var _loc6 = _loc7.length % _loc9;
        var _loc2 = new Array();
        for (var _loc3 = 0; _loc3 < _loc6; ++_loc3) {
            if (_loc2[_loc3] == undefined) _loc2[_loc3] = "";
            _loc2[_loc3] = _loc7.substr((_loc5 + 1) * _loc3, _loc5 + 1);
        }
        for (var _loc3 = _loc6; _loc3 < _loc9; ++_loc3)
            _loc2[_loc3] = _loc7.substr(_loc5 * (_loc3 - _loc6) + (_loc5 + 1) * _loc6, _loc5);
        var _loc4 = "";
        for (var _loc3 = 0; _loc3 < _loc2[0].length; ++_loc3)
            for (var _loc1 = 0; _loc1 < _loc2.length; ++_loc1)
                _loc4 = _loc4 + _loc2[_loc1].charAt(_loc3);
        _loc4 = unescape(_loc4);
        var _loc8 = "";
        for (var _loc3 = 0; _loc3 < _loc4.length; ++_loc3) {
            if (_loc4.charAt(_loc3) == "^") {
                _loc8 = _loc8 + "0";
                continue;
            }
            _loc8 = _loc8 + _loc4.charAt(_loc3);
        }
        return _loc8;
    }

然后调用解密算法,传入刚才复制出来的字符串就可以得到想要的链接了