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: */*', 'accept-language: zh-CN,zh;q=0.9', 'cache-control: no-cache', 'cookie: csrfToken=cxz9Oe21WoDFZYl3TTHsqv4k; _did=web_388385460DFDFC9F; cur_req_id=361821796955B69A_self_2d45c537a4f93b4689463857c3114dd1; cur_group_id=361821796955B69A_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=1697170205; lsv_js_player_v2_main=e4d400; stochastic=c2szYnRlbHpsdG0%3D; acPasstoken=ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4ScCbmhGY2J7R1vWjSV-QGrsoKtJx3rWoEnadNCedw4Frwasg3QtAfH3WfrmCWMFIkC8j7ORv5Dfl2hSC6eE46rfOkBfaOwno8j8HD0XMY3kuKz2BJgIsAY5oiupe5C1VDC15amEd4bdYc_8slFoQSZMgaEv_ytBX1SUzuojzfT3qKAFJ3CCIg9IVUrx5JUPvQr3rPObqfAyMxwxqHLA2RhVPw9b5JTEMoBTAB; auth_key=572984; ac_username=Nicksxs; acPostHint=bf8ae1f2b79e479172ecaa3a893ee6045952; ac_userimg=https%3A%2F%2Fimgs.aixifan.com%2Fstyle%2Fimage%2F201907%2FuQ5Vc06d3HSVTjY3VZocT81X40FByVpw.jpg; safety_id=AAKWI536cb7ZEaWk_4cwOlug; _did=web_388385460DFDFC9F; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1697170267', 'pragma: no-cache', 'referer: https://www.acfun.cn/member/', 'sec-ch-ua: "Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', '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/117.0.0.0 Safari/537.36', 'x-requested-with: XMLHttpRequest', ), )); $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 . '" && python -m youtube_dl 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: www.acfun.cn', 'accept: */*', 'accept-language: zh-CN,zh;q=0.9', 'cache-control: no-cache', 'cookie: csrfToken=cxz9Oe21WoDFZYl3TTHsqv4k; _did=web_388385460DFDFC9F; cur_req_id=361821796955B69A_self_2d45c537a4f93b4689463857c3114dd1; cur_group_id=361821796955B69A_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=1697170205; lsv_js_player_v2_main=e4d400; stochastic=c2szYnRlbHpsdG0%3D; acPasstoken=ChVpbmZyYS5hY2Z1bi5wYXNzdG9rZW4ScCbmhGY2J7R1vWjSV-QGrsoKtJx3rWoEnadNCedw4Frwasg3QtAfH3WfrmCWMFIkC8j7ORv5Dfl2hSC6eE46rfOkBfaOwno8j8HD0XMY3kuKz2BJgIsAY5oiupe5C1VDC15amEd4bdYc_8slFoQSZMgaEv_ytBX1SUzuojzfT3qKAFJ3CCIg9IVUrx5JUPvQr3rPObqfAyMxwxqHLA2RhVPw9b5JTEMoBTAB; auth_key=572984; ac_username=Nicksxs; acPostHint=bf8ae1f2b79e479172ecaa3a893ee6045952; ac_userimg=https%3A%2F%2Fimgs.aixifan.com%2Fstyle%2Fimage%2F201907%2FuQ5Vc06d3HSVTjY3VZocT81X40FByVpw.jpg; safety_id=AAKWI536cb7ZEaWk_4cwOlug; _did=web_388385460DFDFC9F; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1697170267', 'pragma: no-cache', 'referer: https://www.acfun.cn/member/', 'sec-ch-ua: "Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', '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/117.0.0.0 Safari/537.36', 'x-requested-with: XMLHttpRequest', ), )); $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', 'accept: */*', 'accept-language: zh-CN,zh;q=0.9', 'cache-control: no-cache', 'pragma: no-cache', 'referer: https://m.acfun.cn/upPage/10703951?', 'sec-ch-ua: "Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', 'sec-ch-ua-mobile: ?1', 'sec-ch-ua-platform: "Android"', 'sec-fetch-dest: empty', 'sec-fetch-mode: cors', 'sec-fetch-site: same-origin', 'user-agent: Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36', 'x-requested-with: XMLHttpRequest', ), )); $response = curl_exec($curl); curl_close($curl); // echo $response; // exit; $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; } public function queryUpUsersVideosV2($upId, $upName) { $upUrl = $this->upBaseUrl . $upId; $mainQl = QueryList::getInstance(); $pCursor = ""; $page = 1; $queried = 0; $reqId = 1; do { $wbinfos = []; $titles = []; $result = $this->requestUpPagePCApi($upId, $reqId, $page); // dump($result); if (!$result) { return; } $wbinfos = $mainQl->setHtml($result["html"])->find(".ac-space-video")->attrs("data-wbinfo"); $titles = $mainQl->setHtml($result["html"])->find(".title")->htmls(); // dump($wbinfos); // dump($titles);exit; if (count($wbinfos) == 0) { // code... break; } foreach ($wbinfos as $key => $wbinfo) { $wbJson = json_decode($wbinfo, true); AcfunVideo::firstOrCreate( ["content_id" => $wbJson["mediaId"]], [ "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++; $page++; // } else { // break; // } } while (true); } public function requestUpPagePCApi($upId, $reqId, $page) { $curl = curl_init(); if ($upId == null) { return ""; } $t = time() * 1000; $url = "https://www.acfun.cn/u/$upId?quickViewId=ac-space-video-list&reqID=$reqId&ajaxpipe=1&type=video&order=newest&page={$page}&pageSize=20&t=$t"; 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: www.acfun.cn', 'accept: */*', 'accept-language: zh-CN,zh;q=0.9', 'cache-control: no-cache', 'cookie: _did=web_388385460DFDFC9F; _did=web_388385460DFDFC9F; lsv_js_player_v2_main=e4d400; csrfToken=fjMi-0ixCRuVRpGN5Lz2s7Zo; cur_req_id=821488364D119F62_self_39ec375e04fa2b11099dd441ca3bca54; cur_group_id=821488364D119F62_self_39ec375e04fa2b11099dd441ca3bca54_0; webp_supported=%7B%22lossy%22%3Atrue%2C%22lossless%22%3Atrue%2C%22alpha%22%3Atrue%2C%22animation%22%3Atrue%7D; Hm_lvt_2af69bc2b378fb58ae04ed2a04257ed1=1699527119,1700444342; Hm_lpvt_2af69bc2b378fb58ae04ed2a04257ed1=1700444342', 'pragma: no-cache', 'referer: https://www.acfun.cn/u/1016261', 'sec-ch-ua: "Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"', '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/119.0.0.0 Safari/537.36', 'x-requested-with: XMLHttpRequest', ), )); $response = curl_exec($curl); curl_close($curl); $replaced = str_replace("/**/", "", $response); $result = json_decode($replaced, true); $parsedResult["html"] = $result["html"]; // dump($parsedResult);exit; return $parsedResult; } }