免费下载收费歌曲

注释写代码里了,直接上代码吧

     function musicKuwo()
    {         
        $musicName = input('musicName');
        if(!$musicName)
            return $this->redirect('/#Index/index'); 
        $data = UtilsAll::getMusicInformation($musicName);//这是主要的
   /*     var_dump($data);
        die;*/
       /* var_dump(count($data));
        die;*/
        $DDL = UtilsAll::getMusicInformation($stri = '');//这是获取历史记录要用到的
            if (count($DDL)) 
            {   //去除不必要的信息,仅保留下标1,2的歌名和歌曲链接
                unset($DDL[0]);
                unset($DDL[3]);
                unset($DDL[4]);
                unset($DDL[5]);
                unset($DDL[6]);
                unset($DDL[7]);
                unset($DDL[8]);
                unset($DDL[9]);
            }
           $DDL = array_values($DDL);//重新对数组排序 数组中排序为:0 歌名 1链接 ..            
             if (count($data)) 
           {           
              $data[0] = $DDL;
              unset($data[2]);
              unset($data[7]);
              unset($data[8]);
              unset($data[9]);
              $data = array_values($data); //重排           
              return json($data);
           }
        $ipAddres = $_SERVER['REMOTE_ADDR'];//获取访问ip
        $url = "http://sou.kuwo.cn/ws/NSearch?type=all&catalog=yueku20177&key=$musicName";
        $kuwoweb = 'http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_';
        $html = file_get_contents($url); //请求一个页面       

        $strend =  strstr($html,'<a href="http://www.kuwo.cn/yinyue/');//截取一个页面所有a标签        
        preg_match('/<a\s(href).*\/.*\/(\d+)/', $strend, $matches);      
        
        //网易歌词接口无法获取id,放弃!
        /*$page163 = "https://music.163.com/#/search/m/?&s=$musicName&type=1";
        $backPage = file_get_contents($page163);
        preg_match('/<a\shref\S*\/song\?id=(.*)/',$backPage,$preg163);//href="/song?id=400162138
        */
       //酷我歌词接口司马加密,放弃!    
        /*$kuwoUrl = "http://search.kuwo.cn/r.s?all=$musicName&ft=music&itemset=web_2013&client=kt&pn=0&rn=5&rformat=json&encoding=utf8";
        $kuwoP = file_get_contents($kuwoUrl);
        preg_match('/MUSIC_(\d+)/',$kuwoP,$kuwoId);
        $kuwoInline = "http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=$kuwoId[0]";
        $kuwoInlineP = file_get_contents($kuwoInline);
        preg_match('/<lyric>(.*)<\/lyric>/',$kuwoInlineP,$lyricsPages);
        $kuwoLyrics = "http://newlyric.kuwo.cn/newlyric.lrc?$lyricsPages[1]";
        $backLyrics = file_get_contents($kuwoLyrics);*/

        //百度貌似又死了,
        //歌词迷,新歌很多歌词都没有,只能勉强用了。
        $gecimiAPI = "http://gecimi.com/api/lyric/$musicName";
        $downloadLyrics = '';
        try {//这里如果获取不到会爆异常,需要把他抛了
        $backPage = file_get_contents($gecimiAPI);//http://s.gecimi.com/lrc/344/34435/3443588.lrc
        preg_match('/lrc.*(http.*\/\/\S*\/\w+\/\d+\/\d+\/\d+\.lrc)/',$backPage,$backLyricsUrl);                 
        $downloadLyrics = file_get_contents($backLyricsUrl[1]);
           } catch (Exception $e) 
           {
            $downloadLyrics = '歌词??不存在的';
           }   
        $kuwoSong = file_get_contents($kuwoweb . $matches[2]); //得到外链页面
       
        preg_match('/(\w\d)+?\/(\d+)\/(\d+)\/(\d+)\.?(mp3)/',$kuwoSong,$mp3);//提取mp3值
        preg_match('/(other)\.(web)\.(.*)\.(\w+)?\.(.*)?(cn)/',$kuwoSong,$other);//提取other值

        preg_match('/<a\shref.*\/yinyue\/\d+\/\S\s.*/',$strend,$nameArr);//提取姓名a标签
        preg_match('/<a\shref.*\/album\/\d+\/\S\s.*/',$strend,$albumArr);//提取专辑a标签
        preg_match('/<a\shref.*\/mingxing\/\S*.*/',$strend,$starArr);//提取明星a标签

           preg_match('/title=\S(\S*)\S/',$nameArr[0],$name);//提取title值
           preg_match('/title=\S(\S*)\S/',$albumArr[0],$album);//提取专辑a标签title值
           preg_match('/title\S+(\S)*\S/',$starArr[0],$star);//提取明星title值

           // $nameStr = mb_substr($star[0],8,9,'UTF-8');
           $nameReplace = str_replace('title="','',$name[0]);//姓名检验
           $albumReplace = str_replace('title="','',$album[0]);//专辑校验
           $starReplace = str_replace('title="','',$star[0]);//明星校验         
                      
        $data[0] = $DDL;        
        $data[1] = $musicName;//歌曲名
        $data[2] = 'http://' . $other[0] . '/resource/' . $mp3[0];//播放连接
        $data[3] = $nameReplace;//歌手名
        $data[4] = $albumReplace;//专辑名
        $data[5] = $starReplace;//明星名
        $data[6] = $downloadLyrics;//歌词 
        // $data[7] = $ipAddres;     
        UtilsAll::setSave($data);//调用保存方法保存到本地主机
        $this->assign('data',$data);           //模版赋值
        return json($data);       //返回json数组
    }

猜你喜欢

转载自blog.csdn.net/qq_34886247/article/details/80861294
今日推荐