最近经常上虾米听歌,有些歌蛮好听的,昨天回上海准备下载一些音乐路上听,发现要用虾币购买,第一想法在chrome浏览器中按下F12,看Network中发出的报文,很轻松的到了类似f3.xiami/78926/417559/08%201769939716_1875663.mp3这样的链接,这就是音乐的真实地址,可以直接下载下来。这里多说一句,很多人问怎么可以把在线的视频或者音乐下载到本地,网上也可以看到各式各样的回答,有用嗅探工具的,有从浏览器缓存的,其实用chrome或者其他浏览器自带的抓包功能就很容易就能到。
上面是最简单的方法,但是需要很多手工操作,下面用程序的方式来解析,更重要的是提供一个这类问题的思路。
首先来分析一下这首歌,地址是www.xiami/song/1769939716 从网页内容可以看到歌曲名字Rainbow Trees,演唱者 Robert de Boron,所属专辑 Diaspora,打开网页源代码注意到一些数字 1769939716,417599,78926.回头看看mp3的真实地址f3.xiami/78926/417559/08%201769939716_1875663.mp3,1769939716是歌曲ID,417599是所属专辑ID,78926是演唱者ID,发现这个url的构成 f3.xiami/演唱者ID/所
属专辑ID/08%20歌曲ID_18655663.mp3.
这里还差一些东西08是什么?18655663是什么?%20我们知道是空格符,回到专辑页面www.xiami/album/417559发现这首歌Rainbow Trees是第八首歌,那18655663是什么?翻遍了chrome发出的所有报文,所有相关页面的源代码,没到这个数字是什么意思。没办法,网上了个反编译swf的软件,反编译了播放器的源代码,到一些源代码
下面的代码看起来像是获取歌曲位置的代码,再继续到getLocation方法
var dataStr:* = evt.target.data;
dataStr = place(" xmlns=\"/ns/0/\"", "");
var xmlData:* = new XML(dataStr);
xmlData.ignoreWhitespace = true;
uid = xmlData.uid;
clearList = xmlData.clearlist;
var songArr:* = ack;
var tLoadArr:* = [];
var backgroundStr:* = "";
var firstSongId:* = 0;
var addSongTmpArr:* = [];
var oldDataArr:* = [];
if (songArr[0] != undefined){
for (i in 王喜微博songArr) {
tData = songArr[i];
songLocation = "";
thisLocation = tData.location;
if (thisLocation.indexOf("") < 0){
try {
songLocation = Location(tData.location);
} catch(e) {
};
} else {
songLocation = thisLocation;
};
以下是getLocation方法
public function getLocation(_arg1:String):String{
var _local10:*;
var _local2:* = Number(_arg1.charAt(0));
var _local3:* = _arg1.substring(1);
var _local4:* = Math.floor((_local3.length / _local2));
var _local5:* = (_local3.length % _local2);
var _local6:* = new Array();
var _local7:* = 0;
while (_local7 < _local5) {
if (_local6[_local7] == undefined){
_local6[_local7] = "";
};
_local6[_local7] = _local3.substr(((_local4 + 1) * _local7), (_local4 + 1));
_local7++;
};
_local7 = _local5;
while (_local7 < _local2) {
_local6[_local7] = _local3.substr(((_local4 * (_local7 - _local5)) + ((_local4 + 1) * _local5)), _local4);
_local7++;
};
var _local8:* = "";
_local7 = 0;
while (_local7 < _local6[0].length) {
_local10 = 0;
while (_local10 < _local6.length) {
_local8 = (_local8 + _local6[_local10].charAt(_local7));
_local10++;
};
_local7++;
};
_local8 = unescape(_local8);
var _local9:* = "";
_local7 = 0;
while (_local7 < _local8.length) {
if (_local8.charAt(_local7) == "^"){
_local9 = (_local9 + "0");
} else {
_local9 = (_local9 + _local8.charAt(_local7));
};
_local7++;
};
_local9 = _place("+", " ");
return (_local9);
}
这些代码看起来非常像获取地址的关键代码,沿着标黑的代码往上到一个xml文件,并且这个xml文件里面应该有location这个标签,这时候到这个xml文件很关键,这时候回到浏览器重新抓包,到了这样一个链接www.xiami/song/playlist/id/1769939716(歌曲ID)/object_name/default/object_id/0。内容如下
<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="/ns/0/">
<trackList>
<track>
<title><![CDATA[Rainbow Trees]]></title>
<song_id>1769939716</song_id>
<album_id>417559</album_id>
<album_name><![CDATA[Diaspora]]></album_name>
<object_id>1</object_id>
<object_name>default</object_name>
<insert_type>1</insert_type>
<background>img.xiami/res/player/bimg/bg-5.bak.jpg</background>
<grade>-1</grade>
<artist><![CDATA[Robert de Boron]]></artist>
发布评论