APlayer_Plugin::getcover PHP Method

getcover() private static method

通过关键词从豆瓣获取专辑封面链接,当缓存存在时则直接读取缓存
private static getcover ( string $words ) : boolean | string
$words string
return boolean | string
    private static function getcover($words)
    {
        $key = 'cover_' . md5($words);
        if ($g = self::cache_get($key)) {
            if (!isset($g[0])) {
                return false;
            }
            return $g[0];
        } else {
            //缓存不存在时用豆瓣获取并存入缓存
            $arg = http_build_query(array('q' => $words, 'count' => 1));
            $url = false;
            $g = self::fetch_url('https://api.douban.com/v2/music/search?' . $arg);
            if ($g) {
                $g = json_decode($g, true);
                if ($g['count']) {
                    $url = $g['musics'][0]['image'];
                    //换成大图
                    $url = str_replace("/spic/", "/mpic/", $url);
                }
            }
            //用array包裹这个变量就不会判断错误啦
            self::cache_set($key, array($url));
            return $url;
        }
    }