uid = akina_option('bilibili_id'); $this->cookies = akina_option('bilibili_cookie'); } public function get_the_bgm_items($page = 1) { $uid = $this->uid; $cookies = $this->cookies; $url = 'https://api.bilibili.com/x/space/bangumi/follow/list?type=1&pn=' . $page . '&ps=15&follow_status=0&vmid=' . $uid; $args = array( 'headers' => array( 'Cookie' => $cookies, 'Host' => 'api.bilibili.com', 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97' ) ); $response = wp_remote_get($url, $args); $bgmdata = json_decode($response["body"])->data; return json_encode($bgmdata); } public function get_bgm_items($page = 1) { $bgm = json_decode($this->get_the_bgm_items($page), true); $totalpage = $bgm["total"] / 15; if ($totalpage - $page < 0) { $next = '共追番' . $bgm["total"] . '部,继续加油吧!٩(ˊᗜˋ*)و'; } else { $next = ' NEXT '; } $lists = $bgm["list"]; $html = ""; foreach ((array)$lists as $list) { if (preg_match('/看完/m', $list["progress"], $matches_finish)) { $percent = 100; } else { preg_match('/第(\d+)./m', $list['progress'], $matches_progress); preg_match('/第(\d+)./m', $list["new_ep"]['index_show'], $matches_new); $progress = is_numeric($matches_progress[1]) ? $matches_progress[1] : 0; $total = is_numeric($matches_new[1]) ? $matches_new[1] : $list['total_count']; $percent = $progress / $total * 100; } $html .= '

' . $list['title'] . '

' . $list['evaluate'] . '

' . $list['new_ep']['index_show'] . '

'; } $html .= '
' . $next . '
'; return $html; } }