request($this->CollectionUrl, $param); dump($result); $parsedResult = json_decode($result, true); if (count(Arr::get($parsedResult, "favoriteList", [])) > 0) { foreach ($parsedResult["favoriteList"] as $item) { AcfunVideo::firstOrCreate( ["content_id" => $item["contentId"]], [ "title" => $item["contentTitle"], "from_type" => 1, "from_collection_name" => "默认", "from_up_name" => $item["userName"], "from_up_user_id" => $item["userId"], ] ); } } else { break; } } } public function request($url, $param) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $param, CURLOPT_HTTPHEADER => array( 'authority: www.acfun.cn', 'accept: application/json, text/plain, */*', 'accept-language: zh-CN,zh;q=0.9', 'cache-control: no-cache', 'content-type: application/x-www-form-urlencoded', 'cookie: csrfToken=Y66_80DyOUzh3300_JppG-lj; _did=web_27335482609AC197; cur_req_id=602812808A57D014_self_2d45c537a4f93b4689463857c3114dd1; cur_group_id=602812808A57D014_self_2d45c537a4f93b4689463857c3114dd1_0; webp_supported=%7B%22lossy%22%3Atrue%2C%22lossless%22%3Atrue%2C%22alpha%22%3Atrue%2C%22animation%22%3Atrue%7D; Hm_lvt_2af69bc2b378fb58ae04ed2a04257ed1=1690949379; lsv_js_player_v2_main=e4d400; stochastic=dnU5a2sxM3I2YWM%3D; acPasstoken=ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4ScJE3kMWPZFp8HUJuLyT60kKBKFKCtLbYyK8VmCkHqWfZ4HLiGoLg9Rv4F5ezMd-7rnq8oZ088XIoXeHI5HnUaxrN_0Pbs7WVWDqs-3DpYE07TcS82E_kPgwgTFAwt9jh7xc91o_Q-_v3tSAEUthCwuwaEtg7AkwMUtojw7sGpJwKYwEO5CIgK5Hn30lT3kxo9l7lM_fTFK8dfqhTI0f3HEIrFvgs8bMoBTAB; auth_key=572984; ac_username=Nicksxs; acPostHint=8fb77d89b7c29b47c62cfbc6d82c23d82f7b; ac_userimg=https%3A%2F%2Fimgs.aixifan.com%2Fstyle%2Fimage%2F201907%2FuQ5Vc06d3HSVTjY3VZocT81X40FByVpw.jpg; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1690949398', 'origin: https://www.acfun.cn', 'pragma: no-cache', 'referer: https://www.acfun.cn/member/favourite', 'sec-ch-ua: "Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"', 'sec-ch-ua-mobile: ?0', 'sec-ch-ua-platform: "macOS"', 'sec-fetch-dest: empty', 'sec-fetch-mode: cors', 'sec-fetch-site: same-origin', 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', ), )); $response = curl_exec($curl); curl_close($curl); return $response; } public function onlyRequest() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.acfun.cn/rest/pc-direct/favorite/dougaList", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "perpage=100&page=1", CURLOPT_HTTPHEADER => array( "authority: www.acfun.cn", "pragma: no-cache", "cache-control: no-cache", "accept: */*", "x-requested-with: XMLHttpRequest", "user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36", "content-type: application/x-www-form-urlencoded; charset=UTF-8", "origin: https://www.acfun.cn", "sec-fetch-site: same-origin", "sec-fetch-mode: cors", "sec-fetch-dest: empty", "referer: https://www.acfun.cn/member/", "accept-language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6,ja;q=0.5", "cookie: _did=web_32586178239268B; sign_remind=1; ac__avi=1010934062045114530882ab2cd25b90ef370ea22b151084981cf6c2c6febafe3a364146315ef65213; uuid=d7fdb48c886459236faa794ffafbfbb0; analytics=GA1.2.626694313.1592365512; lsv_js_player_v2_main=62b719; csrfToken=TnNz3lG1IfA-93kw4M-Px06m; session_id=63965769975BFD30; webp_supported=%7B%22lossy%22%3Atrue%2C%22lossless%22%3Atrue%2C%22alpha%22%3Atrue%2C%22animation%22%3Atrue%7D; Hm_lvt_2af69bc2b378fb58ae04ed2a04257ed1=1592481541,1592489023,1592797550,1592976124; lsv_js_player_v1_main=f2c6e6; stochastic=NWFlaDB1ZjlmNXE%3D; acPasstoken=ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4ScJrFeEdlHcrvoHjYpzy_V7pAPxxMhNmo45RlMccpB84XwmIx9rJocLwXSPnJu4btgtqVGa04P9AIMBNdQknDd4QRTbjBp5aoQgis-Q88BjMvqVTGHAjG04W7zjswa0ZC5k5sdJCeTsLJKEiEsE8EY90aEhwsbiM70HUviQANoYC6Iptv6yIg0X6u8ikzzwuDe1VMKWNNYXWwFR81YKYQNq9P4gsk5oMoBTAB; auth_key=572984; ac_username=Nicksxs; acPostHint=1cc641584039a19bc0941d00e8eff73bd4b0; ac_userimg=https%3A%2F%2Fimgs.aixifan.com%2Fstyle%2Fimage%2F201907%2FuQ5Vc06d3HSVTjY3VZocT81X40FByVpw.jpg; clientlanguage=zh_CN; safety_id=AAG%2B9AbVZS6fTHVxwLtsI9Jl; notice_status=1; online_status=0; userGroupLevel=1; checkMobile=1; checkEmail=1; cur_req_id=1296724223CA632E_self_0fb782b0474cbe335574779cf53ed145; cur_group_id=1296724223CA632E_self_0fb782b0474cbe335574779cf53ed145_0; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1592976174", // "Content-Type: text/plain" ), )); $response = curl_exec($curl); curl_close($curl); echo $response; } public function downloadVideo() { $innerDir = "/Volumes/T7/Video/acfun"; $list = AcfunVideo::orderBy('updated_at', 'desc')->get(); $files = scandir($innerDir); // dump($files); foreach ($list as $item) { if ($item["is_downloaded"] == 1) { continue; } if (in_array($item['title'] . " (" . $item["from_up_name"] . ").mp4", $files)) { Log::info("file " . $item["title"] . ".mp4" . " exists continue"); continue; } Log::info($item['title'] . " (" . $item["from_up_name"] . ").mp4" . " does not exists to download"); // exit; $downloadResult = shell_exec('cd "' . $innerDir . '" && you-get https://www.acfun.cn/v/ac' . $item["content_id"]); Log::info($downloadResult); $item["is_downloaded"] = 1; $item->save(); } } public function queryUpUsersVideos($upId, $upName) { $upUrl = $this->upBaseUrl . $upId; $mainQl = QueryList::getInstance(); $pCursor = ""; $queried = 0; $reqId = 1; do { $result = $this->requestUpPageApi($upId, $reqId, $pCursor); // dump($result); if (!$result) { return; } $resourceIds = $mainQl->setHtml($result["html"])->find(".video-item")->attrs("resource-id"); $titles = $mainQl->setHtml($result["html"])->find(".video-name")->htmls(); dump($resourceIds); foreach ($resourceIds as $key => $resourceId) { AcfunVideo::firstOrCreate( ["content_id" => $resourceId], [ "title" => $titles[$key], "from_type" => 2, "from_collection_name" => "", "from_up_name" => "$upName", "from_up_user_id" => $upId, ] ); } $queried += $result["pageSize"]; Log::info("current queried: " . $queried); if (array_key_exists("noMore", $result) || $queried > (int) $result["totalCount"]) { break; } if (array_key_exists("pcursor", $result)) { $pCursor = $result["pcursor"]; $reqId++; } else { break; } } while (true); } public function requestUpPage($upId) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://m.acfun.cn/upPage/$upId?", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'authority: m.acfun.cn', 'pragma: no-cache', 'cache-control: no-cache', 'upgrade-insecure-requests: 1', 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1', 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'sec-fetch-site: none', 'sec-fetch-mode: navigate', 'sec-fetch-user: ?1', 'sec-fetch-dest: document', 'accept-language: zh-CN,zh;q=0.9', 'cookie: _did=web_492135297EB70FE5; acPasstoken=ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4ScMqMOf7IIDgLFifcwDByiCz1Wv6zcyhwUzxFnkKxtITs0jGXUUuLWqDsl-7NGWvWwo5AcSoY2-Kjd3CZOXY7PNERtpJIdfyEJ4AFL7nlbdkjI_V_uUanyorcfQ7kaiWNig2_E6FVh7O8nRoGss5vf9saErqF0TDd7uDbNNp-mP7P0DOW_CIg24xq_0sWM6gTjuCWKKX9x7Yg_OpB1KtIk17LYCXdAPwoBTAB; auth_key=572984; ac_username=Nicksxs; acPostHint=b9f4cda120751d7200fa5158fa16dcbcaf88; ac_userimg=https%3A%2F%2Fimgs.aixifan.com%2Fstyle%2Fimage%2F201907%2FuQ5Vc06d3HSVTjY3VZocT81X40FByVpw.jpg; safety_id=AAJRRbRCoai0XjYzLsf70ktB; EGG_SESS=LeuVrD7spUl4PQfNroW9BEVd1JGguP_VHNuClb-BCn-E0TK-gvszCD8JicS8W_cFD8r34_e30N8vQt95J-5Pn7CoX6NDxA_Sm_p3S-E8GaWKY5L1qIfhe_n0viZOlC1RZN9e9wm6bVjMwJc04acrWA==; Hm_lvt_c68e829637dac3d1ad7a134d18b6064f=1641224120; webp_supported=%7B%22lossy%22%3Atrue%2C%22lossless%22%3Atrue%2C%22alpha%22%3Atrue%2C%22animation%22%3Atrue%7D; Hm_lvt_2af69bc2b378fb58ae04ed2a04257ed1=1641223365,1641261026; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1641261026; _did=web_492135297EB70FE5', ), )); $response = curl_exec($curl); curl_close($curl); return $response; } public function requestUpPageApi($upId, $reqId, $pcursor = "") { if ($upId == null) { return ""; } $t = time() * 1000; $url = "https://m.acfun.cn/upPage/$upId?pagelets=video-list&reqID=$reqId&ajaxpipe=1&userId=$upId&type=3&pcursor=$pcursor&t=$t"; // https://m.acfun.cn/upPage/1702633?pagelets=video-list&reqID=1&ajaxpipe=1&userId=1702633&type=3&pcursor=1677145407113&t=1680146711555 if ($pcursor != null && $pcursor != "") { $url .= "&pcursor=$pcursor"; } $url .= "&t=" . (int) (microtime(true) * 1000); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'authority: m.acfun.cn', 'pragma: no-cache', 'cache-control: no-cache', 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1', 'x-requested-with: XMLHttpRequest', 'accept: */*', 'sec-fetch-site: same-origin', 'sec-fetch-mode: cors', 'sec-fetch-dest: empty', 'referer: https://m.acfun.cn/upPage/4537972?', 'accept-language: zh-CN,zh;q=0.9', 'cookie: _did=web_280933889D060418; acPasstoken=ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4ScIVlVCL6FSd7r7J8EESfIrvCZWZ44ZhcldtaiMZTVnka4I1hQQGJ-ywegVxy5bWPDafabEeWEH1IA3W44p_U3tOfyvt5ivCVDiZd-OlAWMOYtj3Og-s0rdEqcqMX_NTExa2jZ3M2N3z_uZHVHghIXPkaEsDLegiAw1sTxw7mkhbBiGkpPiIgMVkL4EVoF5UUt584m8hro8yjbem-qWBoGte7yFXO89AoBTAB; auth_key=572984; ac_username=Nicksxs; acPostHint=cd58860b125ee662a0d161cff68c37e2180f; ac_userimg=https://imgs.aixifan.com/style/image/201907/uQ5Vc06d3HSVTjY3VZocT81X40FByVpw.jpg; _did=web_280933889D060418; csrfToken=AgVgghhXcxJW5CTDNT7kiOWY; cur_req_id=7852848870815E4E_self_2d45c537a4f93b4689463857c3114dd1; cur_group_id=7852848870815E4E_self_2d45c537a4f93b4689463857c3114dd1_0; webp_supported={"lossy":true,"lossless":true,"alpha":true,"animation":true}; Hm_lvt_2af69bc2b378fb58ae04ed2a04257ed1=1665098925,1666089608,1667002226; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1667002226; lsv_js_player_v2_main=e4d400', ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; $replaced = str_replace("/**/", "", $response); $result = json_decode($replaced, true); if ($result == null || !array_key_exists("scripts", $result)) { echo "=========================scripts not exist ===========================\n" . $url; echo "=========================scripts not exist ===========================\n" . $response; return false; } $scripts = $result["scripts"][0]; preg_match_all("#no_more#", $scripts, $noMore); if (count($noMore[0]) > 0) { // dump($noMore); $result["noMore"] = true; } else { preg_match_all("#\"pcursor\"\:\"(\d+)\"#", $scripts, $pcursors); $parsed["pcursor"] = $pcursors[1][0]; } preg_match_all("#\"totalCount\"\:(\d+)#", $scripts, $totalCounts); $parsed["totalCount"] = $totalCounts[1][0]; preg_match_all("#\"videoFeedLength\"\:(\d+)#", $scripts, $pageSizes); $parsed["pageSize"] = $pageSizes[1][0]; $parsed["html"] = $result["html"]; unset($result); return $parsed; } }