虾米音乐爬虫

**虾米音乐真实地址破解

废话不多说,直接进入正题
获取音乐信息地址 https://www.xiami.com/widget/xml-single/uid/0/sid/1795933741
(sid后面的数字为音乐id)
在这里插入图片描述
在这里可以看到有一个非常长的字符串:5h3%2ae4F7739731%1.3h%57E%52b4131tA28mt48%17%97454mF_3%7%5E2c4bc6t%F.i%7326%2549E4pakD525E-fd95e9p2mx.2%4F85F916573ue1E%E-8ac4ae8%F1inF2418E13_373%ty595-%8139248

把他和真实的音乐地址对比,发现有点类似凯撒方阵 http://m128.xiami.net/447/83447/1716883709/1795933741_1496305714473.mp3?auth_key=1550977200-0-0-8822fa1bcdc3449491b5a23cee416988

location 第一个数字表示行数 , 每行字符个数为strlen(location) / 5 或者 strlen(location) /5 +1:
location解析后可得到 :
5
h 3 % 2 a e 4 F 7 7 3 9 7 3 1 % 1 . 3 h % 5 7 E % 5 2 b 4 1 3 1
t A 2 8 m t 4 8 %1 7 % 9 7 4 5 4 m F _ 3 % 7 % 5 E 2 c 4 b c 6
t % F . i % 7 3 2 6 % 2 5 4 9 E 4 p a k D 5 2 5 E - f d 9 5 e 9
p 2 m x . 2 % 4 F 8 5 F 9 1 6 5 7 3 u e 1 E % E - 8 a c 4 a e 8
% F 1 i n F 2 4 1 8 E 1 3 _ 3 7 3 % t y 5 9 5 - % 8 1 3 9 2 4 8

从第一个开始一列一列读就是:
http%3A%2F%2Fm128.xiami.net 。。。。。
进行URLDecode一下就是:http://m128.xiami.net 。。。

代码设计思路:
先找第一行的分界字符**‘t’** 若返回的位置是strlen(location) / 5 或者strlen(location) /5 +1则表示找到正确分割点 ,然后 l o c a t i o n = s u b s t r ( location = substr( location=substr(location , ‘分割位置’) , 并且将第一行转换成一个字符数组;
在找下一个t 然后再找 p知道全部分割完字符串
最后将数组纵向读取就是真实的音乐地址了

好了现在可以上代码了(以PHP为例):

public function xiamiDecode($location){
   if(!isset($location) || !is_string($location)){
       return false ;
   }
   $spliter = array("t","t","p","%","3","A","%","2","f","%","2","f","m","1","2","8",".","x","i","a","m","i") ;
   $line = (int)$location[0] ;
   $location = substr($location , 1) ;
   $index = (int)(strlen($location) / $line) ;
   $result = array() ;
   $error_count = 0 ;
   
   for($i = 0 ; $i < $line - 1 ; $i ++){
       $flag = 0 ;
       $arr = array() ;
       while($flag != $index && $flag != $index + 1){
           $flag = stripos($location , $spliter[$i] , $flag + 1);
           if(++$error_count >= 50){
              return false;
           }
       }
       $str = substr($location , 0 , $flag);
       $location = substr($location , $flag);
       $arr = str_split($str , 1);
       $result[] = $arr ;
   }
   $arr = str_split($location , 1);
   $result[] = $arr ;
   
   $url = '';
   for($i = 0 ; $i < $index + 1 ; $i++){
       for($j = 0 , $len = count($result) ; $j < $len ; $j ++){
           if(isset($result[$j][$i])){
               $url .= $result[$j][$i] ;
           }else{
               continue ;
           }
       }
   }
   $url = str_ireplace("%5e" , "0" , $url);
   return URLDecode($url) ;
 }

为什么写$url = str_ireplace("%5e" , “0” , $url);这一句呢 , 因为我按之前的思路解析完后发现真实地址的0全部被%5e替换了 所以得替换回来 好了,我知道的就这么多了,希望可以帮助到你
我的Github为:https://github.com/wangffei/PHP
里面有跟详细的代码

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值