@ -7,12 +7,17 @@ namespace App\Services;
use App\AcfunVideo ;
use Illuminate\Support\Arr ;
use Log ;
use QL\QueryList ;
class AcfunService
{
private $CollectionUrl = " https://www.acfun.cn/rest/pc-direct/favorite/dougaList " ;
private $upBaseUrl = " https://m.acfun.cn/upPage/ " ;
public function queryCollectionVideos ()
{
for ( $i = 1 ; $i < 100 ; $i ++ ) {
@ -122,7 +127,7 @@ class AcfunService
public function downloadVideo ()
{
$innerDir = " /Volumes/intel660p/video/mv /acfun " ;
$innerDir = " /Volumes/Crucial X6/Video /acfun " ;
$list = AcfunVideo :: all ();
$files = scandir ( $innerDir );
@ -137,11 +142,144 @@ class AcfunService
}
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 " ]);
$downloadResult = shell_exec ( 'cd "' . $innerDir . '" && annie https://www.acfun.cn/v/ac' . $item [ " content_id " ]);
Log :: info ( $downloadResult );
$item [ " is_downloaded " ] = 1 ;
$item -> save ();
}
}
public function queryUpUsersVideos ( $upId )
{
$upUrl = $this -> upBaseUrl . $upId ;
$mainQl = QueryList :: getInstance ();
$pCursor = " " ;
$queried = 0 ;
do {
$result = $this -> requestUpPageApi ( $upId , $pCursor );
$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 " => " 香菜猫饼 " ,
" from_up_user_id " => $upId
]);
}
$queried += $result [ " pageSize " ];
Log :: info ( " current queried: " . $queried );
if ( $result [ " noMore " ] || $queried > ( int ) $result [ " totalCount " ]) {
break ;
}
$pCursor = $result [ " pcursor " ];
} 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 , $pcursor = " " ) {
if ( $upId == null ) {
return " " ;
}
$url = " https://m.acfun.cn/upPage/ $upId ?pagelets=video-list&reqID=4&ajaxpipe=1&userId= $upId &type=3 " ;
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_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==; 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; cur_req_id=9320591763A17878_self_e9df062d443158972b38326847c62945; cur_group_id=9320591763A17878_self_e9df062d443158972b38326847c62945_0; Hm_lvt_c68e829637dac3d1ad7a134d18b6064f=1641224120,1641263656; Hm_lpvt_c68e829637dac3d1ad7a134d18b6064f=1641263656; _did=web_492135297EB70FE5'
),
));
$response = curl_exec ( $curl );
curl_close ( $curl );
// echo $response;
$replaced = str_replace ( " /*<!-- fetch-stream -->*/ " , " " , $response );
$result = json_decode ( $replaced , true );
$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 ;
}
}