<commit_before><?php
class HermitJson
{
    private $token;
    private $_settings;
    
    public function __construct()
    {
        /**
         ** 缓存插件设置
         */
        $this->_settings = get_option('hermit_setting');
        
		global $Netease;
        @require_once('include/Netease.php');
        $Netease = new MusicAPI();
    }
    
    public function song($song_id)
    {
        $cache_key = "/xiami/song/" . $song_id;
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $response = $this->xiami_http(0, $song_id);
        var_dump($response);
        exit;
        if ($response && $response["state"] == 0 && $response['data']) {
            $result = $response["data"]["song"];
            
            $song = array(
                "title" => $result["song_name"],
                "author" => $result["singers"],
                "url" => $result["listen_file"],
                "pic" => $result['logo'],
                "lrc" => ""
            );
            
            $this->set_cache($cache_key, $song);
            
            return $song;
        }
        
        return false;
    }
    
    public function song_list($song_list)
    {
        if (!$song_list)
            return false;
        
        $this->get_token();
        
        $songs_array = explode(",", $song_list);
        $songs_array = array_unique($songs_array);
        
        if (!empty($songs_array)) {
            $result = array();
            foreach ($songs_array as $song_id) {
                $result['songs'][] = $this->song($song_id);
            }
            //$this->set_cache($key, $result);
            return $result;
        }
        
        return false;
    }
    
    public function album($album_id)
    {
		
        $cache_key = '/xiami/album/' . $album_id;
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $this->get_token();
        $response = $this->xiami_http(1, $album_id);
        
        if ($response && $response["state"] == 0 && $response["data"]) {
            $result = $response["data"];
            $count  = $result['song_count'];
            
            if ($count < 1)
                return false;
            
            $album = array(
                "album_id" => $album_id,
                "album_title" => $result['album_name'],
                "album_author" => $result['artist_name'],
                "album_cover" => $result['album_logo'],
                "album_count" => $count,
                "album_type" => "albums"
            );
            
            foreach ($result['songs'] as $key => $val) {
                $song_id          = $val['song_id'];
                $album["songs"][] = $this->song($song_id);
            }
            
            $this->set_cache($cache_key, $album);
            return $album;
        }
        
        return false;
    }
    
    public function collect($collect_id)
    {
        $cache_key = '/xiami/collect/' . $collect_id;
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $this->get_token();
        $response = $this->xiami_http(2, $collect_id);
        
        if ($response && $response["state"] == 0 && $response["data"]) {
            $result = $response["data"];
            $count  = $result['songs_count'];
            
            if ($count < 1)
                return false;
            
            $collect = array(
                "collect_id" => $collect_id,
                "collect_title" => $result['collect_name'],
                "collect_author" => $result['user_name'],
                "collect_cover" => $result['logo'],
                "collect_type" => "collects",
                "collect_count" => $count
            );
            
            foreach ($result['songs'] as $key => $value) {
                $collect["songs"][] = array(
                    "title" => $value["song_name"],
                    "url" => $value["listen_file"],
                    "author" => $value["singers"],
                    "pic" => $value['album_logo'],
                    "lrc" => ""
                );
            }
            
            $this->set_cache($cache_key, $collect);
            
            return $collect;
        }
        
        return false;
    }
    
    public function netease_song($music_id)
    {
		global $Netease;
        $cache_key = "/netease/song/$music_id";
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $response = json_decode($Netease->detail($music_id), true);
        
        if ($response["code"] == 200 && $response["songs"]) {
            //处理音乐信息
            $mp3_url    = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_song_url&id=' . $music_id;
            $music_name = $response["songs"][0]["name"];
            $cover      = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_pic_url&picid=' . $response['songs'][0]['al']['pic_str'] . '&id=' . $music_id;
            $artists    = array();
            
            foreach ($response["songs"][0]["ar"] as $artist) {
                $artists[] = $artist["name"];
            }
            
            $artists = implode(",", $artists);
            
            $result = array(
                "title" => $music_name,
                "author" => $artists,
                "url" => $mp3_url,
                "pic" => $cover,
                "lrc" => 'https://api.lwl12.com/music/netease/lyric?raw=true&id=' . $music_id
            );
            
            $this->set_cache($cache_key, $result, 24);
            
            return $result;
        }
        
        return false;
    }
    public function netease_song_url($music_id)
    {
		global $Netease;
        if ($this->settings( 'NeteaseMirror_status' ) == 1 && strpos($_SERVER['REQUEST_URI'], "admin-ajax.php") !== FALSE) {
            Header("Location: " . $this->settings('NeteaseMirror') . "/netease_song_url/id/" . $music_id);
            exit;
        }
        
        $url = json_decode($Netease->url($music_id), true);
        $url = $url["data"][0]["url"];
        if (empty($url)) {
            Header("Location: " . 'http://tts.baidu.com/text2audio?lan=zh&pid=101&ie=UTF-8&spd=6&text=%E9%9D%9E%E5%B8%B8%E6%8A%B1%E6%AD%89%EF%BC%8C%E6%AD%A4%E6%AD%8C%E6%9B%B2%E5%9B%A0%E7%89%88%E6%9D%83%E5%8E%9F%E5%9B%A0%E6%88%96%E5%9B%A0%E7%BD%91%E6%98%93%E4%BA%91%E6%8A%BD%E9%A3%8E%E6%97%A0%E6%B3%95%E6%92%AD%E6%94%BE');
            exit;
        }
        Header("Location: " . $url);
        exit;
    }
    public function netease_pic_url($id, $pic_str)
    {
		global $Netease;
        if ($this->settings( 'NeteaseMirror_status' ) == 1 && strpos($_SERVER['REQUEST_URI'], "admin-ajax.php") !== FALSE) {
            Header("Location: " . $this->settings('NeteaseMirror') . "/netease_pic_url/id/" . $id . "/picid/" . $pic_str);
            exit;
        }
        Header("Location: " . $Netease->id2url($pic_str));
        exit;
    }
    public function netease_songs($song_list)
    {
        if (!$song_list)
            return false;
        
        $songs_array = explode(",", $song_list);
        $songs_array = array_unique($songs_array);
        
        if (!empty($songs_array)) {
            $result = array();
            foreach ($songs_array as $song_id) {
                $result['songs'][] = $this->netease_song($song_id);
            }
            return $result;
        }
        
        return false;
    }
    
    public function netease_album($album_id)
    {
		global $Netease;
        $key = "/netease/album/$album_id";
        
        $cache = $this->get_cache($key);
        if ($cache)
            return $cache;
        
        $response = json_decode($Netease->album($album_id), true);
        
        if ($response["code"] == 200 && $response["songs"]) {
            //处理音乐信息
            $result = $response["songs"];
            $count  = count($result);
            
            if ($count < 1)
                return false;
            
            $album_name   = $response["album"]["name"];
            $album_author = $response["album"]["artist"]["name"];
            $cover        = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_pic_url&picid=' . $response["album"]['picId'];
            
            $album = array(
                "album_id" => $album_id,
                "album_title" => $album_name,
                "album_author" => $album_author,
                "album_type" => "albums",
                "album_count" => $count
            );
            
            foreach ($result as $k => $value) {
                $mp3_url          = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_song_url&id=' . $value["id"];
                $album["songs"][] = array(
                    "title" => $value["name"],
                    "url" => $mp3_url,
                    "author" => $album_author,
                    "pic" => $cover  . '&id=' . $value["id"]
                );
            }<commit_msg>fix netease album lyric<commit_after><?php
class HermitJson
{
    private $token;
    private $_settings;
    
    public function __construct()
    {
        /**
         ** 缓存插件设置
         */
        $this->_settings = get_option('hermit_setting');
        
		global $Netease;
        @require_once('include/Netease.php');
        $Netease = new MusicAPI();
    }
    
    public function song($song_id)
    {
        $cache_key = "/xiami/song/" . $song_id;
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $response = $this->xiami_http(0, $song_id);
        var_dump($response);
        exit;
        if ($response && $response["state"] == 0 && $response['data']) {
            $result = $response["data"]["song"];
            
            $song = array(
                "title" => $result["song_name"],
                "author" => $result["singers"],
                "url" => $result["listen_file"],
                "pic" => $result['logo'],
                "lrc" => ""
            );
            
            $this->set_cache($cache_key, $song);
            
            return $song;
        }
        
        return false;
    }
    
    public function song_list($song_list)
    {
        if (!$song_list)
            return false;
        
        $this->get_token();
        
        $songs_array = explode(",", $song_list);
        $songs_array = array_unique($songs_array);
        
        if (!empty($songs_array)) {
            $result = array();
            foreach ($songs_array as $song_id) {
                $result['songs'][] = $this->song($song_id);
            }
            //$this->set_cache($key, $result);
            return $result;
        }
        
        return false;
    }
    
    public function album($album_id)
    {
		
        $cache_key = '/xiami/album/' . $album_id;
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $this->get_token();
        $response = $this->xiami_http(1, $album_id);
        
        if ($response && $response["state"] == 0 && $response["data"]) {
            $result = $response["data"];
            $count  = $result['song_count'];
            
            if ($count < 1)
                return false;
            
            $album = array(
                "album_id" => $album_id,
                "album_title" => $result['album_name'],
                "album_author" => $result['artist_name'],
                "album_cover" => $result['album_logo'],
                "album_count" => $count,
                "album_type" => "albums"
            );
            
            foreach ($result['songs'] as $key => $val) {
                $song_id          = $val['song_id'];
                $album["songs"][] = $this->song($song_id);
            }
            
            $this->set_cache($cache_key, $album);
            return $album;
        }
        
        return false;
    }
    
    public function collect($collect_id)
    {
        $cache_key = '/xiami/collect/' . $collect_id;
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $this->get_token();
        $response = $this->xiami_http(2, $collect_id);
        
        if ($response && $response["state"] == 0 && $response["data"]) {
            $result = $response["data"];
            $count  = $result['songs_count'];
            
            if ($count < 1)
                return false;
            
            $collect = array(
                "collect_id" => $collect_id,
                "collect_title" => $result['collect_name'],
                "collect_author" => $result['user_name'],
                "collect_cover" => $result['logo'],
                "collect_type" => "collects",
                "collect_count" => $count
            );
            
            foreach ($result['songs'] as $key => $value) {
                $collect["songs"][] = array(
                    "title" => $value["song_name"],
                    "url" => $value["listen_file"],
                    "author" => $value["singers"],
                    "pic" => $value['album_logo'],
                    "lrc" => ""
                );
            }
            
            $this->set_cache($cache_key, $collect);
            
            return $collect;
        }
        
        return false;
    }
    
    public function netease_song($music_id)
    {
		global $Netease;
        $cache_key = "/netease/song/$music_id";
        
        $cache = $this->get_cache($cache_key);
        if ($cache)
            return $cache;
        
        $response = json_decode($Netease->detail($music_id), true);
        
        if ($response["code"] == 200 && $response["songs"]) {
            //处理音乐信息
            $mp3_url    = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_song_url&id=' . $music_id;
            $music_name = $response["songs"][0]["name"];
            $cover      = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_pic_url&picid=' . $response['songs'][0]['al']['pic_str'] . '&id=' . $music_id;
            $artists    = array();
            
            foreach ($response["songs"][0]["ar"] as $artist) {
                $artists[] = $artist["name"];
            }
            
            $artists = implode(",", $artists);
            
            $result = array(
                "title" => $music_name,
                "author" => $artists,
                "url" => $mp3_url,
                "pic" => $cover,
                "lrc" => 'https://api.lwl12.com/music/netease/lyric?raw=true&id=' . $music_id
            );
            
            $this->set_cache($cache_key, $result, 24);
            
            return $result;
        }
        
        return false;
    }
    public function netease_song_url($music_id)
    {
		global $Netease;
        if ($this->settings( 'NeteaseMirror_status' ) == 1 && strpos($_SERVER['REQUEST_URI'], "admin-ajax.php") !== FALSE) {
            Header("Location: " . $this->settings('NeteaseMirror') . "/netease_song_url/id/" . $music_id);
            exit;
        }
        
        $url = json_decode($Netease->url($music_id), true);
        $url = $url["data"][0]["url"];
        if (empty($url)) {
            Header("Location: " . 'http://tts.baidu.com/text2audio?lan=zh&pid=101&ie=UTF-8&spd=6&text=%E9%9D%9E%E5%B8%B8%E6%8A%B1%E6%AD%89%EF%BC%8C%E6%AD%A4%E6%AD%8C%E6%9B%B2%E5%9B%A0%E7%89%88%E6%9D%83%E5%8E%9F%E5%9B%A0%E6%88%96%E5%9B%A0%E7%BD%91%E6%98%93%E4%BA%91%E6%8A%BD%E9%A3%8E%E6%97%A0%E6%B3%95%E6%92%AD%E6%94%BE');
            exit;
        }
        Header("Location: " . $url);
        exit;
    }
    public function netease_pic_url($id, $pic_str)
    {
		global $Netease;
        if ($this->settings( 'NeteaseMirror_status' ) == 1 && strpos($_SERVER['REQUEST_URI'], "admin-ajax.php") !== FALSE) {
            Header("Location: " . $this->settings('NeteaseMirror') . "/netease_pic_url/id/" . $id . "/picid/" . $pic_str);
            exit;
        }
        Header("Location: " . $Netease->id2url($pic_str));
        exit;
    }
    public function netease_songs($song_list)
    {
        if (!$song_list)
            return false;
        
        $songs_array = explode(",", $song_list);
        $songs_array = array_unique($songs_array);
        
        if (!empty($songs_array)) {
            $result = array();
            foreach ($songs_array as $song_id) {
                $result['songs'][] = $this->netease_song($song_id);
            }
            return $result;
        }
        
        return false;
    }
    
    public function netease_album($album_id)
    {
		global $Netease;
        $key = "/netease/album/$album_id";
        
        $cache = $this->get_cache($key);
        if ($cache)
            return $cache;
        
        $response = json_decode($Netease->album($album_id), true);
        
        if ($response["code"] == 200 && $response["songs"]) {
            //处理音乐信息
            $result = $response["songs"];
            $count  = count($result);
            
            if ($count < 1)
                return false;
            
            $album_name   = $response["album"]["name"];
            $album_author = $response["album"]["artist"]["name"];
            $cover        = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_pic_url&picid=' . $response["album"]['picId'];
            
            $album = array(
                "album_id" => $album_id,
                "album_title" => $album_name,
                "album_author" => $album_author,
                "album_type" => "albums",
                "album_count" => $count
            );
            
            foreach ($result as $k => $value) {
                $mp3_url          = admin_url() . "admin-ajax.php" . '?action=hermit&scope=netease_song_url&id=' . $value["id"];
                $album["songs"][] = array(
                    "title" => $value["name"],
                    "url" => $mp3_url,
                    "author" => $album_author,
                    "pic" => $cover  . '&id=' . $value["id"],
		    "lrc" => 'https://api.lwl12.com/music/netease/lyric?raw=true&id=' . $value["id"]
                );
            }
{'fraction_non_alphanumeric': 0.16571026418362927, 'fraction_numerical': 0.012234733650931138, 'mean_word_length': 1.5054930150549302, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 138, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4461008', 'n_tokens_mistral': 6048, 'n_tokens_neox': 5812, 'n_words': 870}