APlayer_Plugin::get_netease_music PHP Метод

get_netease_music() приватный статический Метод

从netease中获取歌曲信息
private static get_netease_music ( unknown $id, unknown $type = 'song' )
$id unknown
$type unknown 获取的id的类型,song:歌曲,album:专辑,artist:艺人,collect:歌单
    private static function get_netease_music($id, $type = 'song')
    {
        $return = false;
        switch ($type) {
            case 'song':
                $url = "http://music.163.com/api/song/detail/?ids=[{$id}]";
                $key = 'songs';
                break;
            case 'album':
                $url = "http://music.163.com/api/album/{$id}?id={$id}";
                $key = 'album';
                break;
            case 'artist':
                $url = "http://music.163.com/api/artist/{$id}?id={$id}";
                $key = 'artist';
                break;
            case 'collect':
                $url = "http://music.163.com/api/playlist/detail?id={$id}";
                $key = 'result';
                break;
            default:
                $url = "http://music.163.com/api/song/detail/?ids=[{$id}]";
                $key = 'songs';
        }
        if (!function_exists('curl_init')) {
            return false;
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie: appver=2.0.2'));
        curl_setopt($ch, CURLOPT_TIMEOUT, 15);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($ch, CURLOPT_REFERER, 'http://music.163.com/;');
        $cexecute = curl_exec($ch);
        curl_close($ch);
        if ($cexecute) {
            $result = json_decode($cexecute, true);
            if ($result['code'] == 200 && $result[$key]) {
                $return['status'] = true;
                $return['message'] = "";
                switch ($key) {
                    case 'songs':
                        $data = $result[$key];
                        break;
                    case 'album':
                        $data = $result[$key]['songs'];
                        break;
                    case 'artist':
                        $data = $result['hotSongs'];
                        break;
                    case 'result':
                        $data = $result[$key]['tracks'];
                        break;
                    default:
                        $data = $result[$key];
                        break;
                }
                //列表
                $list = array();
                foreach ($data as $keys => $data) {
                    //获取歌词
                    $lyric = self::get_netease_lyric($data['id']);
                    if ($lyric) {
                        $lyric = $lyric['lyric'];
                    }
                    $list[$data['id']] = array('song_id' => $data['id'], 'title' => $data['name'], 'album_name' => $data['album']['name'], 'artist' => $data['artists'][0]['name'], 'location' => str_replace('http://m', 'http://p', $data['mp3Url']), 'pic' => $data['album']['blurPicUrl'] . '?param=106x106', 'lyric' => $lyric);
                }
                //修复一次添加多个id的乱序问题
                if ($type = 'song' && strpos($id, ',')) {
                    $ids = explode(',', $id);
                    $r = array();
                    foreach ($ids as $v) {
                        if (!empty($list[$v])) {
                            $r[] = $list[$v];
                        }
                    }
                    $list = $r;
                }
                //最终播放列表
                $return['trackList'] = $list;
            }
        } else {
            $return = array('status' => false, 'message' => '非法请求');
        }
        return $return;
    }