|
|
@ -36,18 +36,16 @@ class BilibiliServiceV2 { |
|
|
// private $remoteDir = "/data/";
|
|
|
// private $remoteDir = "/data/";
|
|
|
private $remoteDir = "/Volumes/Crucial X6/Video/"; |
|
|
private $remoteDir = "/Volumes/Crucial X6/Video/"; |
|
|
|
|
|
|
|
|
// 是否只根据视频数量,不尝试抓取第一页
|
|
|
|
|
|
private $skipFirstPage = true; |
|
|
|
|
|
|
|
|
// 是否只根据视频数量,不尝试抓取第一页
|
|
|
|
|
|
private $skipFirstPage = true; |
|
|
|
|
|
|
|
|
public function isSkipFirstPage(): bool |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->skipFirstPage; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function isSkipFirstPage(): bool { |
|
|
|
|
|
return $this->skipFirstPage; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function setSkipFirstPage(bool $skipFirstPage): void |
|
|
|
|
|
{ |
|
|
|
|
|
$this->skipFirstPage = $skipFirstPage; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function setSkipFirstPage(bool $skipFirstPage): void { |
|
|
|
|
|
$this->skipFirstPage = $skipFirstPage; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private $mixinKeyEncTab = [ |
|
|
private $mixinKeyEncTab = [ |
|
|
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, |
|
|
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, |
|
|
@ -133,17 +131,18 @@ class BilibiliServiceV2 { |
|
|
foreach ($list as $key => $item) { |
|
|
foreach ($list as $key => $item) { |
|
|
Log::info("schedule queryUpVideoList current up is {$item['up_name']}, started at: " . date("Y-m-d H:i:s")); |
|
|
Log::info("schedule queryUpVideoList current up is {$item['up_name']}, started at: " . date("Y-m-d H:i:s")); |
|
|
// $files = scandir($this->baseDir . "bilibili/" . $item['up_name']);
|
|
|
// $files = scandir($this->baseDir . "bilibili/" . $item['up_name']);
|
|
|
$todayCount = $this->queryUpVideoTotalWithCache($item["mid"]); |
|
|
|
|
|
if ($todayCount <= $item["count"]) { |
|
|
|
|
|
Log::info("today new count is {$todayCount} is same or smaller than {$item["count"]} skip"); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// $todayCount = $this->queryUpVideoTotalWithCache($item["mid"]);
|
|
|
|
|
|
$todayCount = 1000; |
|
|
|
|
|
if ($todayCount <= $item["count"]) { |
|
|
|
|
|
Log::info("today new count is {$todayCount} is same or smaller than {$item["count"]} skip"); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$mediaId = $item['mid']; |
|
|
$mediaId = $item['mid']; |
|
|
$videos = []; |
|
|
$videos = []; |
|
|
$pageNo = 1; |
|
|
$pageNo = 1; |
|
|
$url = "https://api.bilibili.com/x/space/wbi/arc/search?mid={$mediaId}&ps=30&tid=0&keyword=&pn="; |
|
|
$url = "https://api.bilibili.com/x/space/wbi/arc/search?mid={$mediaId}&ps=30&tid=0&keyword=&pn="; |
|
|
$pageAll = ceil(($todayCount - $item["count"])/30); |
|
|
|
|
|
|
|
|
$pageAll = ceil(($todayCount - $item["count"]) / 30); |
|
|
// if ($mediaId == 241804522 || $mediaId == 3461581333596856) {
|
|
|
// if ($mediaId == 241804522 || $mediaId == 3461581333596856) {
|
|
|
// $pageAll = 10;
|
|
|
// $pageAll = 10;
|
|
|
// }
|
|
|
// }
|
|
|
@ -163,15 +162,24 @@ class BilibiliServiceV2 { |
|
|
// https://space.bilibili.com/475250/video
|
|
|
// https://space.bilibili.com/475250/video
|
|
|
for ($i = 1; $i <= $pageAll; $i++) { |
|
|
for ($i = 1; $i <= $pageAll; $i++) { |
|
|
$curl = curl_init(); |
|
|
$curl = curl_init(); |
|
|
$b_nut = time(); |
|
|
|
|
|
$dmImgStr = str_replace("==", "", base64_encode($this->randFloat())) ; |
|
|
|
|
|
$dmImgStr = "V2ViR0wgMS4wIChPcGVuR0wgRVMgMi4wIENocm9taXVtKQ"; |
|
|
|
|
|
$dmCoverImgStr = str_replace("==", "", base64_encode($this->randFloat())) ; |
|
|
|
|
|
$dmCoverImgStr = "QU5HTEUgKEludGVsIEluYy4sIEludGVsKFIpIElyaXMoVE0pIFBsdXMgR3JhcGhpY3MgNjU1LCBPcGVuR0wgNC4xKUdvb2dsZSBJbmMuIChJbnRlbCBJbmMuKQ"; |
|
|
|
|
|
|
|
|
$b_nut = time(); |
|
|
|
|
|
$dmImgStr = str_replace("==", "", base64_encode($this->randFloat())); |
|
|
|
|
|
$dmImgStr = "V2ViR0wgMS4wIChPcGVuR0wgRVMgMi4wIENocm9taXVtKQ"; |
|
|
|
|
|
$dmCoverImgStr = str_replace("==", "", base64_encode($this->randFloat())); |
|
|
|
|
|
$dmCoverImgStr = "QU5HTEUgKEludGVsIEluYy4sIEludGVsKFIpIElyaXMoVE0pIFBsdXMgR3JhcGhpY3MgNjU1LCBPcGVuR0wgNC4xKUdvb2dsZSBJbmMuIChJbnRlbCBJbmMuKQ"; |
|
|
// echo $dmImgStr . "\n";
|
|
|
// echo $dmImgStr . "\n";
|
|
|
// echo $dmCoverImgStr . "\n";exit;
|
|
|
|
|
|
$encrypt_string = "dm_cover_img_str={$dmCoverImgStr}&dm_img_list=%5B%5D&dm_img_str={$dmImgStr}&keyword=&mid={$mediaId}&order=pubdate&order_avoided=true&platform=web&pn={$i}&ps=30&tid=&web_location="; |
|
|
|
|
|
$query = $this->build_params($encrypt_string); |
|
|
|
|
|
|
|
|
// echo $dmCoverImgStr . "\n";exit;
|
|
|
|
|
|
|
|
|
|
|
|
$dm_rand = 'ABCDEFGHIJK'; |
|
|
|
|
|
$dm_img_list = '[]'; |
|
|
|
|
|
$dm_img_str = $this->GetRandStr(2); |
|
|
|
|
|
$dm_cover_img_str = $this->GetRandStr(2); |
|
|
|
|
|
|
|
|
|
|
|
$dm_img_inter = "{\"ds\":[],\"wh\":[0,0,0],\"of\":[0,0,0]}"; |
|
|
|
|
|
$w_webid = $this->getWebId(); |
|
|
|
|
|
$encrypt_string = "dm_img_list={$dm_img_list}&dm_img_str={$dm_img_str}&dm_cover_img_str={$dm_cover_img_str}&dm_img_inter=" . $dm_img_inter . "&w_webid={$w_webid}&keyword=&mid={$mediaId}&order=pubdate&order_avoided=true&platform=web&pn={$i}&ps=30&tid=&web_location="; |
|
|
|
|
|
$query = $this->build_params($encrypt_string); |
|
|
|
|
|
// dump($query);exit;
|
|
|
|
|
|
|
|
|
$params = [ |
|
|
$params = [ |
|
|
"mid" => $mediaId, |
|
|
"mid" => $mediaId, |
|
|
@ -183,57 +191,58 @@ class BilibiliServiceV2 { |
|
|
"web_location" => 1550101, |
|
|
"web_location" => 1550101, |
|
|
"order_avoided" => 'true', |
|
|
"order_avoided" => 'true', |
|
|
"pn" => $i, |
|
|
"pn" => $i, |
|
|
"dm_img_list" => [], |
|
|
|
|
|
"dm_img_str" => $dmImgStr, |
|
|
|
|
|
"dm_cover_img_str" => $dmCoverImgStr, |
|
|
|
|
|
|
|
|
"dm_img_list" => [], |
|
|
|
|
|
"dm_img_str" => $dmImgStr, |
|
|
|
|
|
"dm_cover_img_str" => $dmCoverImgStr, |
|
|
]; |
|
|
]; |
|
|
// $query = $this->build_params($params);
|
|
|
// $query = $this->build_params($params);
|
|
|
// echo $query;exit;
|
|
|
|
|
|
// $opts = array('http' => array('header' => '"User-Agent": "Mozilla/5.0"\r\n "origin": "https://space.bilibili.com\r\n "accept-language":"en,zh-CN;q=0.9,zh;q=0.8"\r\n'));
|
|
|
|
|
|
|
|
|
// echo $query;exit;
|
|
|
|
|
|
// $opts = array('http' => array('header' => '"User-Agent": "Mozilla/5.0"\r\n "origin": "https://space.bilibili.com\r\n "accept-language":"en,zh-CN;q=0.9,zh;q=0.8"\r\n'));
|
|
|
|
|
|
|
|
|
// $ctx = stream_context_create($opts);
|
|
|
// $ctx = stream_context_create($opts);
|
|
|
// echo file_get_contents("https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"], false, $ctx);
|
|
|
|
|
|
// exit;
|
|
|
|
|
|
$url = "https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"]; |
|
|
|
|
|
$header[] = "Accept: */*"; |
|
|
|
|
|
$header[] = "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"; |
|
|
|
|
|
$header[] = "Connection: close"; |
|
|
|
|
|
$header[] = "Cache-Control: max-age=0"; |
|
|
|
|
|
curl_setopt_array($curl, [ |
|
|
|
|
|
CURLOPT_HTTPGET => 1, |
|
|
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
|
|
|
CURLOPT_RETURNTRANSFER => 1, |
|
|
|
|
|
CURLOPT_HTTPHEADER => $header, |
|
|
|
|
|
CURLOPT_ENCODING => '', |
|
|
|
|
|
CURLOPT_URL => $url, |
|
|
|
|
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.39', |
|
|
|
|
|
CURLOPT_TIMEOUT => 15 |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
// echo file_get_contents("https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"], false, $ctx);
|
|
|
|
|
|
// exit;
|
|
|
|
|
|
$url = "https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"]; |
|
|
|
|
|
$header[] = "Accept: */*"; |
|
|
|
|
|
$header[] = "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"; |
|
|
|
|
|
$header[] = "Connection: close"; |
|
|
|
|
|
$header[] = "Cache-Control: max-age=0"; |
|
|
|
|
|
// $header[] = "Cookie: buvid3=F1D75200-6E4F-58D2-E1FA-7DE70663401985249infoc; b_nut=1706932685; buvid4=A11F8D72-D362-0ECD-5199-D0E4F52EE6F285597-024020303-jL3QxKOpdP9YTu%2BHyZaEIQ%3D%3D; _uuid=449728D2-B68B-1026D-DBB2-A1BEDCC6866585496infoc; buvid_fp=0be21f013c19ab3635b096b34a8a20fd; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDcxOTE4ODYsImlhdCI6MTcwNjkzMjYyNiwicGx0IjotMX0.KdU9NjwlEAoUr2VXRehVM4omOfSN1Wh9KPn0Cp_Fhtw; bili_ticket_expires=1707191826; b_lsid=6F6684EC_18D6EBB74D7; PVID=1";
|
|
|
|
|
|
curl_setopt_array($curl, [ |
|
|
|
|
|
CURLOPT_HTTPGET => 1, |
|
|
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
|
|
|
CURLOPT_RETURNTRANSFER => 1, |
|
|
|
|
|
CURLOPT_HTTPHEADER => $header, |
|
|
|
|
|
CURLOPT_ENCODING => '', |
|
|
|
|
|
CURLOPT_URL => $url, |
|
|
|
|
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36', |
|
|
|
|
|
CURLOPT_TIMEOUT => 15, |
|
|
|
|
|
]); |
|
|
// curl_setopt_array($curl, array(
|
|
|
// curl_setopt_array($curl, array(
|
|
|
// CURLOPT_URL => "https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"],
|
|
|
|
|
|
// CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
|
//// CURLOPT_ENCODING => '',
|
|
|
|
|
|
//// CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
|
//// CURLOPT_TIMEOUT => 10,
|
|
|
|
|
|
//// CURLOPT_FOLLOWLOCATION => true,
|
|
|
|
|
|
//// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
|
// CURLOPT_CUSTOMREQUEST => 'GET',
|
|
|
|
|
|
// CURLOPT_HTTPHEADER => array(
|
|
|
|
|
|
//// 'authority' => 'api.bilibili.com',
|
|
|
|
|
|
//// 'accept' => '*/*',
|
|
|
|
|
|
//// 'accept-language' => 'en,zh-CN;q=0.9,zh;q=0.8',
|
|
|
|
|
|
//// 'cache-control' => 'no-cache',
|
|
|
|
|
|
// 'origin' => 'https://space.bilibili.com',
|
|
|
|
|
|
//// 'pragma' => 'no-cache',
|
|
|
|
|
|
//// 'referer' => 'https://space.bilibili.com/385079033/',
|
|
|
|
|
|
//// 'sec-ch-ua' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
|
|
|
|
|
//// 'sec-ch-ua-mobile' => '?0',
|
|
|
|
|
|
//// 'sec-ch-ua-platform' => '"macOS"',
|
|
|
|
|
|
//// 'sec-fetch-dest' => 'empty',
|
|
|
|
|
|
//// 'sec-fetch-mode' => 'cors',
|
|
|
|
|
|
//// 'sec-fetch-site' => 'same-site',
|
|
|
|
|
|
// 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'),
|
|
|
|
|
|
// ));
|
|
|
|
|
|
|
|
|
// CURLOPT_URL => "https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"],
|
|
|
|
|
|
// CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
|
//// CURLOPT_ENCODING => '',
|
|
|
|
|
|
//// CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
|
//// CURLOPT_TIMEOUT => 10,
|
|
|
|
|
|
//// CURLOPT_FOLLOWLOCATION => true,
|
|
|
|
|
|
//// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
|
// CURLOPT_CUSTOMREQUEST => 'GET',
|
|
|
|
|
|
// CURLOPT_HTTPHEADER => array(
|
|
|
|
|
|
//// 'authority' => 'api.bilibili.com',
|
|
|
|
|
|
//// 'accept' => '*/*',
|
|
|
|
|
|
//// 'accept-language' => 'en,zh-CN;q=0.9,zh;q=0.8',
|
|
|
|
|
|
//// 'cache-control' => 'no-cache',
|
|
|
|
|
|
// 'origin' => 'https://space.bilibili.com',
|
|
|
|
|
|
//// 'pragma' => 'no-cache',
|
|
|
|
|
|
//// 'referer' => 'https://space.bilibili.com/385079033/',
|
|
|
|
|
|
//// 'sec-ch-ua' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
|
|
|
|
|
//// 'sec-ch-ua-mobile' => '?0',
|
|
|
|
|
|
//// 'sec-ch-ua-platform' => '"macOS"',
|
|
|
|
|
|
//// 'sec-fetch-dest' => 'empty',
|
|
|
|
|
|
//// 'sec-fetch-mode' => 'cors',
|
|
|
|
|
|
//// 'sec-fetch-site' => 'same-site',
|
|
|
|
|
|
// 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'),
|
|
|
|
|
|
// ));
|
|
|
|
|
|
|
|
|
$response = curl_exec($curl); |
|
|
$response = curl_exec($curl); |
|
|
$err = curl_error($curl); |
|
|
$err = curl_error($curl); |
|
|
@ -243,7 +252,7 @@ class BilibiliServiceV2 { |
|
|
if ($err) { |
|
|
if ($err) { |
|
|
echo "cURL Error #:" . $err; |
|
|
echo "cURL Error #:" . $err; |
|
|
} else { |
|
|
} else { |
|
|
// echo $response;exit;
|
|
|
|
|
|
|
|
|
echo $response;exit; |
|
|
$result = json_decode($response, true); |
|
|
$result = json_decode($response, true); |
|
|
if (!array_key_exists("data", $result) || !array_key_exists("list", $result["data"])) { |
|
|
if (!array_key_exists("data", $result) || !array_key_exists("list", $result["data"])) { |
|
|
Log::info("result is null " . json_encode($response)); |
|
|
Log::info("result is null " . json_encode($response)); |
|
|
@ -253,8 +262,8 @@ class BilibiliServiceV2 { |
|
|
$count = Arr::get(Arr::get($result["data"], "page", []), "count", 0); |
|
|
$count = Arr::get(Arr::get($result["data"], "page", []), "count", 0); |
|
|
Log::info("up {$item["up_name"]} count is {$count}"); |
|
|
Log::info("up {$item["up_name"]} count is {$count}"); |
|
|
$result = Arr::get($result["data"]["list"], "vlist", []); |
|
|
$result = Arr::get($result["data"]["list"], "vlist", []); |
|
|
if (count($result) > 0 ) { |
|
|
|
|
|
// && $count > $item["count"] + ($i - 1) * 30
|
|
|
|
|
|
|
|
|
if (count($result) > 0) { |
|
|
|
|
|
// && $count > $item["count"] + ($i - 1) * 30
|
|
|
foreach ($result as $vItem) { |
|
|
foreach ($result as $vItem) { |
|
|
$bVideo = BilibiliVideos::firstOrCreate(["aid" => $vItem["aid"]], |
|
|
$bVideo = BilibiliVideos::firstOrCreate(["aid" => $vItem["aid"]], |
|
|
[ |
|
|
[ |
|
|
@ -294,28 +303,106 @@ class BilibiliServiceV2 { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function queryUpVideoTotalWithCache($mid) |
|
|
|
|
|
{ |
|
|
|
|
|
$today = date("Y-m-d"); |
|
|
|
|
|
$todayCount = Redis::connection()->get("bilibili:count:{$today}:{$mid}"); |
|
|
|
|
|
if ($todayCount == null) { |
|
|
|
|
|
$todayCount = $this->queryUpVideoTotal($mid); |
|
|
|
|
|
Redis::connection()->set("bilibili:count:{$today}:{$mid}", $todayCount); |
|
|
|
|
|
} |
|
|
|
|
|
return $todayCount; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function queryUpVideoListNew($mediaId = 320491072, $startPos = 0, $limit = 20) { |
|
|
|
|
|
Log::info("schedule queryUpVideoList inner started at: " . date("Y-m-d H:i:s")); |
|
|
|
|
|
|
|
|
|
|
|
// 475250 kyokyo
|
|
|
|
|
|
// 3489535 熊小颖
|
|
|
|
|
|
// 320491072 绯绯
|
|
|
|
|
|
// 10139490 短短
|
|
|
|
|
|
// 116683 咬人猫
|
|
|
|
|
|
// 16539048 小仙若
|
|
|
|
|
|
// 10278125 香草猫饼
|
|
|
|
|
|
// 391073761 女团直拍
|
|
|
|
|
|
// 267781236 韩国女团饭拍直拍
|
|
|
|
|
|
// 23400436 小雪_juvia
|
|
|
|
|
|
$list = BilibiliUpVideos::where("id", "<=", "200") |
|
|
|
|
|
->orderBy('id', 'desc') |
|
|
|
|
|
->offset($startPos) |
|
|
|
|
|
->limit($limit) |
|
|
|
|
|
->get(); |
|
|
|
|
|
// $list = $list->slice(5);
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
*/ |
|
|
|
|
|
public function queryUpVideoTotal($mid) |
|
|
|
|
|
{ |
|
|
|
|
|
$url = "https://api.bilibili.com/x/space/navnum?mid=" . $mid; |
|
|
|
|
|
$curl = curl_init(); |
|
|
|
|
|
$header[] = "Accept: */*"; |
|
|
|
|
|
|
|
|
foreach ($list as $key => $item) { |
|
|
|
|
|
Log::info("schedule queryUpVideoList current up is {$item['up_name']}, started at: " . date("Y-m-d H:i:s")); |
|
|
|
|
|
// $files = scandir($this->baseDir . "bilibili/" . $item['up_name']);
|
|
|
|
|
|
// $todayCount = $this->queryUpVideoTotalWithCache($item["mid"]);
|
|
|
|
|
|
$todayCount = 1000; |
|
|
|
|
|
if ($todayCount <= $item["count"]) { |
|
|
|
|
|
Log::info("today new count is {$todayCount} is same or smaller than {$item["count"]} skip"); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$mediaId = $item['mid']; |
|
|
|
|
|
$videos = []; |
|
|
|
|
|
$pageNo = 1; |
|
|
|
|
|
$url = "https://api.bilibili.com/x/space/wbi/arc/search?mid={$mediaId}&ps=30&tid=0&keyword=&pn="; |
|
|
|
|
|
$pageAll = ceil(($todayCount - $item["count"]) / 30); |
|
|
|
|
|
// if ($mediaId == 241804522 || $mediaId == 3461581333596856) {
|
|
|
|
|
|
// $pageAll = 10;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// https://api.bilibili.com/x/space/wbi/arc/search?
|
|
|
|
|
|
// mid=363430107&
|
|
|
|
|
|
//ps=30&
|
|
|
|
|
|
//tid=0&
|
|
|
|
|
|
//pn=1&
|
|
|
|
|
|
//keyword=&
|
|
|
|
|
|
//order=pubdate&
|
|
|
|
|
|
//platform=web&
|
|
|
|
|
|
//web_location=1550101&
|
|
|
|
|
|
//order_avoided=true&
|
|
|
|
|
|
//w_rid=a1011501119a6d795f369ec2bafa1af2&
|
|
|
|
|
|
//wts=1685087658
|
|
|
|
|
|
// https://space.bilibili.com/475250/video
|
|
|
|
|
|
for ($i = 1; $i <= $pageAll; $i++) { |
|
|
|
|
|
$curl = curl_init(); |
|
|
|
|
|
$b_nut = time(); |
|
|
|
|
|
$dmImgStr = str_replace("==", "", base64_encode($this->randFloat())); |
|
|
|
|
|
$dmImgStr = "V2ViR0wgMS4wIChPcGVuR0wgRVMgMi4wIENocm9taXVtKQ"; |
|
|
|
|
|
$dmCoverImgStr = str_replace("==", "", base64_encode($this->randFloat())); |
|
|
|
|
|
$dmCoverImgStr = "QU5HTEUgKEludGVsIEluYy4sIEludGVsKFIpIElyaXMoVE0pIFBsdXMgR3JhcGhpY3MgNjU1LCBPcGVuR0wgNC4xKUdvb2dsZSBJbmMuIChJbnRlbCBJbmMuKQ"; |
|
|
|
|
|
// echo $dmImgStr . "\n";
|
|
|
|
|
|
// echo $dmCoverImgStr . "\n";exit;
|
|
|
|
|
|
|
|
|
|
|
|
$dm_rand = 'ABCDEFGHIJK'; |
|
|
|
|
|
$dm_img_list = '[]'; |
|
|
|
|
|
$dm_img_str = $this->GetRandStr(2); |
|
|
|
|
|
$dm_cover_img_str = $this->GetRandStr(2); |
|
|
|
|
|
|
|
|
|
|
|
$dm_img_inter = "{\"ds\":[],\"wh\":[0,0,0],\"of\":[0,0,0]}"; |
|
|
|
|
|
$w_webid = $this->getWebId(); |
|
|
|
|
|
$encrypt_string = "dm_img_list={$dm_img_list}&dm_img_str={$dm_img_str}&dm_cover_img_str={$dm_cover_img_str}&dm_img_inter=" . $dm_img_inter . "&w_webid={$w_webid}&keyword=&mid={$mediaId}&order=pubdate&order_avoided=true&platform=web&pn={$i}&ps=30&tid=&web_location="; |
|
|
|
|
|
$query = $this->build_params($encrypt_string); |
|
|
|
|
|
// dump($query);exit;
|
|
|
|
|
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
"mid" => $mediaId, |
|
|
|
|
|
"ps" => 30, |
|
|
|
|
|
"tid" => '', |
|
|
|
|
|
"keyword" => "", |
|
|
|
|
|
"order" => "pubdate", |
|
|
|
|
|
"platform" => "web", |
|
|
|
|
|
"web_location" => 1550101, |
|
|
|
|
|
"order_avoided" => 'true', |
|
|
|
|
|
"pn" => $i, |
|
|
|
|
|
"dm_img_list" => [], |
|
|
|
|
|
"dm_img_str" => $dmImgStr, |
|
|
|
|
|
"dm_cover_img_str" => $dmCoverImgStr, |
|
|
|
|
|
]; |
|
|
|
|
|
// $query = $this->build_params($params);
|
|
|
|
|
|
// echo $query;exit;
|
|
|
|
|
|
// $opts = array('http' => array('header' => '"User-Agent": "Mozilla/5.0"\r\n "origin": "https://space.bilibili.com\r\n "accept-language":"en,zh-CN;q=0.9,zh;q=0.8"\r\n'));
|
|
|
|
|
|
|
|
|
|
|
|
// $ctx = stream_context_create($opts);
|
|
|
|
|
|
// echo file_get_contents("https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"], false, $ctx);
|
|
|
|
|
|
// exit;
|
|
|
|
|
|
$url = "https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"]; |
|
|
|
|
|
$header[] = "Accept: */*"; |
|
|
$header[] = "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"; |
|
|
$header[] = "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"; |
|
|
$header[] = "Connection: close"; |
|
|
$header[] = "Connection: close"; |
|
|
$header[] = "Cache-Control: max-age=0"; |
|
|
$header[] = "Cache-Control: max-age=0"; |
|
|
|
|
|
// $header[] = "Cookie: buvid3=F1D75200-6E4F-58D2-E1FA-7DE70663401985249infoc; b_nut=1706932685; buvid4=A11F8D72-D362-0ECD-5199-D0E4F52EE6F285597-024020303-jL3QxKOpdP9YTu%2BHyZaEIQ%3D%3D; _uuid=449728D2-B68B-1026D-DBB2-A1BEDCC6866585496infoc; buvid_fp=0be21f013c19ab3635b096b34a8a20fd; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDcxOTE4ODYsImlhdCI6MTcwNjkzMjYyNiwicGx0IjotMX0.KdU9NjwlEAoUr2VXRehVM4omOfSN1Wh9KPn0Cp_Fhtw; bili_ticket_expires=1707191826; b_lsid=6F6684EC_18D6EBB74D7; PVID=1";
|
|
|
curl_setopt_array($curl, [ |
|
|
curl_setopt_array($curl, [ |
|
|
CURLOPT_HTTPGET => 1, |
|
|
CURLOPT_HTTPGET => 1, |
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
@ -323,26 +410,142 @@ class BilibiliServiceV2 { |
|
|
CURLOPT_HTTPHEADER => $header, |
|
|
CURLOPT_HTTPHEADER => $header, |
|
|
CURLOPT_ENCODING => '', |
|
|
CURLOPT_ENCODING => '', |
|
|
CURLOPT_URL => $url, |
|
|
CURLOPT_URL => $url, |
|
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.39', |
|
|
|
|
|
CURLOPT_TIMEOUT => 15 |
|
|
|
|
|
|
|
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36', |
|
|
|
|
|
CURLOPT_TIMEOUT => 15, |
|
|
]); |
|
|
]); |
|
|
$response = curl_exec($curl); |
|
|
|
|
|
$err = curl_error($curl); |
|
|
|
|
|
|
|
|
|
|
|
curl_close($curl); |
|
|
|
|
|
|
|
|
|
|
|
if ($err) { |
|
|
|
|
|
echo "cURL Error #:" . $err; |
|
|
|
|
|
} else { |
|
|
|
|
|
$res = json_decode($response, true); |
|
|
|
|
|
if (array_key_exists("data", $res) && array_key_exists("video", $res["data"])) { |
|
|
|
|
|
return $res["data"]["video"]; |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new Exception("获取up 视频数量异常"); |
|
|
|
|
|
|
|
|
// curl_setopt_array($curl, array(
|
|
|
|
|
|
// CURLOPT_URL => "https://api.bilibili.com/x/space/wbi/arc/search?" . $query["new"],
|
|
|
|
|
|
// CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
|
//// CURLOPT_ENCODING => '',
|
|
|
|
|
|
//// CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
|
//// CURLOPT_TIMEOUT => 10,
|
|
|
|
|
|
//// CURLOPT_FOLLOWLOCATION => true,
|
|
|
|
|
|
//// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
|
// CURLOPT_CUSTOMREQUEST => 'GET',
|
|
|
|
|
|
// CURLOPT_HTTPHEADER => array(
|
|
|
|
|
|
//// 'authority' => 'api.bilibili.com',
|
|
|
|
|
|
//// 'accept' => '*/*',
|
|
|
|
|
|
//// 'accept-language' => 'en,zh-CN;q=0.9,zh;q=0.8',
|
|
|
|
|
|
//// 'cache-control' => 'no-cache',
|
|
|
|
|
|
// 'origin' => 'https://space.bilibili.com',
|
|
|
|
|
|
//// 'pragma' => 'no-cache',
|
|
|
|
|
|
//// 'referer' => 'https://space.bilibili.com/385079033/',
|
|
|
|
|
|
//// 'sec-ch-ua' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
|
|
|
|
|
//// 'sec-ch-ua-mobile' => '?0',
|
|
|
|
|
|
//// 'sec-ch-ua-platform' => '"macOS"',
|
|
|
|
|
|
//// 'sec-fetch-dest' => 'empty',
|
|
|
|
|
|
//// 'sec-fetch-mode' => 'cors',
|
|
|
|
|
|
//// 'sec-fetch-site' => 'same-site',
|
|
|
|
|
|
// 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'),
|
|
|
|
|
|
// ));
|
|
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($curl); |
|
|
|
|
|
$err = curl_error($curl); |
|
|
|
|
|
|
|
|
|
|
|
curl_close($curl); |
|
|
|
|
|
|
|
|
|
|
|
if ($err) { |
|
|
|
|
|
echo "cURL Error #:" . $err; |
|
|
|
|
|
} else { |
|
|
|
|
|
echo $response;exit; |
|
|
|
|
|
$result = json_decode($response, true); |
|
|
|
|
|
if (!array_key_exists("data", $result) || !array_key_exists("list", $result["data"])) { |
|
|
|
|
|
Log::info("result is null " . json_encode($response)); |
|
|
|
|
|
exit; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
$count = Arr::get(Arr::get($result["data"], "page", []), "count", 0); |
|
|
|
|
|
Log::info("up {$item["up_name"]} count is {$count}"); |
|
|
|
|
|
$result = Arr::get($result["data"]["list"], "vlist", []); |
|
|
|
|
|
if (count($result) > 0) { |
|
|
|
|
|
// && $count > $item["count"] + ($i - 1) * 30
|
|
|
|
|
|
foreach ($result as $vItem) { |
|
|
|
|
|
$bVideo = BilibiliVideos::firstOrCreate(["aid" => $vItem["aid"]], |
|
|
|
|
|
[ |
|
|
|
|
|
"title" => $vItem["title"], |
|
|
|
|
|
"from_type" => 2, |
|
|
|
|
|
"from_up_name" => $item["up_name"], |
|
|
|
|
|
"bv_id" => $vItem["bvid"], |
|
|
|
|
|
"up_mid" => $mediaId, |
|
|
|
|
|
"collection_mid" => 0, |
|
|
|
|
|
]); |
|
|
|
|
|
if ($bVideo->from_type != 2) { |
|
|
|
|
|
$bVideo->from_type = 3; |
|
|
|
|
|
} |
|
|
|
|
|
$bVideo->bv_id = $vItem["bvid"]; |
|
|
|
|
|
$bVideo->up_mid = $mediaId; |
|
|
|
|
|
$bVideo->from_up_name = $item["up_name"]; |
|
|
|
|
|
$bVideo->save(); |
|
|
|
|
|
$videos[] = $vItem["aid"]; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
usleep(random_int(1000, 10000) * 1000); |
|
|
|
|
|
} |
|
|
|
|
|
if ($key % 5 == 0 && $key != 0) { |
|
|
|
|
|
sleep(300); |
|
|
} |
|
|
} |
|
|
|
|
|
if (isset($count) && $count > $item["count"]) { |
|
|
|
|
|
$item["count"] = $count; |
|
|
|
|
|
} |
|
|
|
|
|
// $item['videos'] = json_encode($videos);
|
|
|
|
|
|
// $item['downloaded_videos'] = json_encode([]);
|
|
|
|
|
|
|
|
|
|
|
|
$item->save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function queryUpVideoTotalWithCache($mid) { |
|
|
|
|
|
$today = date("Y-m-d"); |
|
|
|
|
|
$todayCount = Redis::connection()->get("bilibili:count:{$today}:{$mid}"); |
|
|
|
|
|
if ($todayCount == null) { |
|
|
|
|
|
$todayCount = $this->queryUpVideoTotal($mid); |
|
|
|
|
|
Redis::connection()->set("bilibili:count:{$today}:{$mid}", $todayCount); |
|
|
|
|
|
} |
|
|
|
|
|
return $todayCount; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
*/ |
|
|
|
|
|
public function queryUpVideoTotal($mid) { |
|
|
|
|
|
$url = "https://api.bilibili.com/x/space/navnum?mid=" . $mid; |
|
|
|
|
|
$curl = curl_init(); |
|
|
|
|
|
$header[] = "Accept: */*"; |
|
|
|
|
|
$header[] = "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"; |
|
|
|
|
|
$header[] = "Connection: close"; |
|
|
|
|
|
$header[] = "Cache-Control: max-age=0"; |
|
|
|
|
|
curl_setopt_array($curl, [ |
|
|
|
|
|
CURLOPT_HTTPGET => 1, |
|
|
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
|
|
|
CURLOPT_RETURNTRANSFER => 1, |
|
|
|
|
|
CURLOPT_HTTPHEADER => $header, |
|
|
|
|
|
CURLOPT_ENCODING => '', |
|
|
|
|
|
CURLOPT_URL => $url, |
|
|
|
|
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.39', |
|
|
|
|
|
CURLOPT_TIMEOUT => 15, |
|
|
|
|
|
]); |
|
|
|
|
|
$response = curl_exec($curl); |
|
|
|
|
|
$err = curl_error($curl); |
|
|
|
|
|
|
|
|
|
|
|
curl_close($curl); |
|
|
|
|
|
|
|
|
|
|
|
if ($err) { |
|
|
|
|
|
echo "cURL Error #:" . $err; |
|
|
|
|
|
} else { |
|
|
|
|
|
echo $response; |
|
|
|
|
|
$res = json_decode($response, true); |
|
|
|
|
|
if (array_key_exists("data", $res) && array_key_exists("video", $res["data"])) { |
|
|
|
|
|
return $res["data"]["video"]; |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new Exception("获取up 视频数量异常"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 手动执行查询 |
|
|
* 手动执行查询 |
|
|
* @param int $mediaId |
|
|
* @param int $mediaId |
|
|
@ -1288,20 +1491,38 @@ done && echo "ok"'); |
|
|
|
|
|
|
|
|
public function downloadDynamics() { |
|
|
public function downloadDynamics() { |
|
|
$env = App::environment(); |
|
|
$env = App::environment(); |
|
|
$list = BilibiliUpVideos::orderBy("id", "desc")->where("id", ">=", "18")->limit(150)->get(); |
|
|
|
|
|
|
|
|
$list = BilibiliUpVideos::orderBy("id", "desc")->offset(0)->limit(150)->get(); |
|
|
|
|
|
// ->where("id", ">=", "0")
|
|
|
foreach ($list as $item) { |
|
|
foreach ($list as $item) { |
|
|
|
|
|
sleep(rand(1, 15)); |
|
|
$mid = $item["mid"]; |
|
|
$mid = $item["mid"]; |
|
|
$offset = null; |
|
|
$offset = null; |
|
|
$response = null; |
|
|
$response = null; |
|
|
$skipFlag = false; |
|
|
|
|
|
|
|
|
$skipFlag = false; |
|
|
|
|
|
$index = 0; |
|
|
do { |
|
|
do { |
|
|
echo "=============== current up is {$item["up_name"]} ==================\n"; |
|
|
|
|
|
$jsonResponse = $this->dynamicsRequest($mid, $offset); |
|
|
|
|
|
|
|
|
$index++; |
|
|
|
|
|
if ($skipFlag) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
sleep(rand(1, 15)); |
|
|
|
|
|
echo "=============== current up is {$item["up_name"]} ==================\n"; |
|
|
|
|
|
$doi = 0; |
|
|
|
|
|
do { |
|
|
|
|
|
$doi++; |
|
|
|
|
|
try { |
|
|
|
|
|
$jsonResponse = $this->dynamicsRequest($mid, $offset); |
|
|
|
|
|
break; |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
Log::error($e->getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} while ($doi < 10); |
|
|
echo $jsonResponse; |
|
|
echo $jsonResponse; |
|
|
$response = json_decode($jsonResponse, true); |
|
|
$response = json_decode($jsonResponse, true); |
|
|
|
|
|
|
|
|
if (array_key_exists("code", $response) && $response["code"] == '0' && array_key_exists("data", $response) && array_key_exists("items", $response["data"])) { |
|
|
if (array_key_exists("code", $response) && $response["code"] == '0' && array_key_exists("data", $response) && array_key_exists("items", $response["data"])) { |
|
|
$dynamics = $response["data"]["items"]; |
|
|
$dynamics = $response["data"]["items"]; |
|
|
|
|
|
$skipFlag = false; |
|
|
foreach ($dynamics as $dynamic) { |
|
|
foreach ($dynamics as $dynamic) { |
|
|
if ($dynamic["type"] == "DYNAMIC_TYPE_DRAW") { |
|
|
if ($dynamic["type"] == "DYNAMIC_TYPE_DRAW") { |
|
|
if (array_key_exists("modules", $dynamic) && |
|
|
if (array_key_exists("modules", $dynamic) && |
|
|
@ -1317,38 +1538,40 @@ done && echo "ok"'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else if ($dynamic["type"] == "DYNAMIC_TYPE_AV") { |
|
|
} else if ($dynamic["type"] == "DYNAMIC_TYPE_AV") { |
|
|
if (array_key_exists("modules", $dynamic) && |
|
|
|
|
|
array_key_exists("module_dynamic", $dynamic["modules"]) && |
|
|
|
|
|
array_key_exists("major", $dynamic["modules"]["module_dynamic"]) && |
|
|
|
|
|
array_key_exists("archive", $dynamic["modules"]["module_dynamic"]["major"]) && |
|
|
|
|
|
array_key_exists("bvid", $dynamic["modules"]["module_dynamic"]["major"]["archive"]) && |
|
|
|
|
|
array_key_exists("title", $dynamic["modules"]["module_dynamic"]["major"]["archive"]) |
|
|
|
|
|
) { |
|
|
|
|
|
$exists = BilibiliVideos::where("aid", "=", $dynamic["modules"]["module_dynamic"]["major"]["archive"]["aid"])->first(); |
|
|
|
|
|
if ($exists !== null) { |
|
|
|
|
|
Log::info("current aid exist skip ================================="); |
|
|
|
|
|
// $skipFlag = true;
|
|
|
|
|
|
break 2; |
|
|
|
|
|
} |
|
|
|
|
|
$bVideo = BilibiliVideos::firstOrCreate(["aid" => $dynamic["modules"]["module_dynamic"]["major"]["archive"]["aid"]], |
|
|
|
|
|
[ |
|
|
|
|
|
"title" => $dynamic["modules"]["module_dynamic"]["major"]["archive"]["title"], |
|
|
|
|
|
"from_type" => 2, |
|
|
|
|
|
"from_up_name" => $item["up_name"], |
|
|
|
|
|
"bv_id" => $dynamic["modules"]["module_dynamic"]["major"]["archive"]["bvid"], |
|
|
|
|
|
"up_mid" => $mid, |
|
|
|
|
|
"collection_mid" => 0, |
|
|
|
|
|
]); |
|
|
|
|
|
if ($bVideo->from_type != 2) { |
|
|
|
|
|
$bVideo->from_type = 3; |
|
|
|
|
|
} |
|
|
|
|
|
$bVideo->bv_id = $dynamic["modules"]["module_dynamic"]["major"]["archive"]["bvid"]; |
|
|
|
|
|
$bVideo->up_mid = $mid; |
|
|
|
|
|
$bVideo->from_up_name = $item["up_name"]; |
|
|
|
|
|
$bVideo->save(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (array_key_exists("modules", $dynamic) && |
|
|
|
|
|
array_key_exists("module_dynamic", $dynamic["modules"]) && |
|
|
|
|
|
array_key_exists("major", $dynamic["modules"]["module_dynamic"]) && |
|
|
|
|
|
array_key_exists("archive", $dynamic["modules"]["module_dynamic"]["major"]) && |
|
|
|
|
|
array_key_exists("bvid", $dynamic["modules"]["module_dynamic"]["major"]["archive"]) && |
|
|
|
|
|
array_key_exists("title", $dynamic["modules"]["module_dynamic"]["major"]["archive"]) |
|
|
|
|
|
) { |
|
|
|
|
|
$exists = BilibiliVideos::where("aid", "=", $dynamic["modules"]["module_dynamic"]["major"]["archive"]["aid"])->first(); |
|
|
|
|
|
if ($exists !== null) { |
|
|
|
|
|
Log::info("current aid exist skip ================================="); |
|
|
|
|
|
$skipFlag = true; |
|
|
|
|
|
// break 2;
|
|
|
|
|
|
} |
|
|
|
|
|
$bVideo = BilibiliVideos::firstOrCreate(["aid" => $dynamic["modules"]["module_dynamic"]["major"]["archive"]["aid"]], |
|
|
|
|
|
[ |
|
|
|
|
|
"title" => $dynamic["modules"]["module_dynamic"]["major"]["archive"]["title"], |
|
|
|
|
|
"from_type" => 2, |
|
|
|
|
|
"from_up_name" => $item["up_name"], |
|
|
|
|
|
"bv_id" => $dynamic["modules"]["module_dynamic"]["major"]["archive"]["bvid"], |
|
|
|
|
|
"up_mid" => $mid, |
|
|
|
|
|
"collection_mid" => 0, |
|
|
|
|
|
]); |
|
|
|
|
|
if ($bVideo->from_type != 2) { |
|
|
|
|
|
$bVideo->from_type = 3; |
|
|
|
|
|
} |
|
|
|
|
|
$bVideo->bv_id = $dynamic["modules"]["module_dynamic"]["major"]["archive"]["bvid"]; |
|
|
|
|
|
$bVideo->up_mid = $mid; |
|
|
|
|
|
$bVideo->from_up_name = $item["up_name"]; |
|
|
|
|
|
$bVideo->save(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
echo "====================== data is not normal ======================\n"; |
|
|
} |
|
|
} |
|
|
if (array_key_exists("data", $response) && array_key_exists("offset", $response["data"])) { |
|
|
if (array_key_exists("data", $response) && array_key_exists("offset", $response["data"])) { |
|
|
$offset = $response["data"]["offset"]; |
|
|
$offset = $response["data"]["offset"]; |
|
|
@ -1363,22 +1586,38 @@ done && echo "ok"'); |
|
|
|
|
|
|
|
|
public function dynamicsRequest($mid, $offset) { |
|
|
public function dynamicsRequest($mid, $offset) { |
|
|
$client = new Client(); |
|
|
$client = new Client(); |
|
|
$headers = [ |
|
|
|
|
|
'authority' => 'api.bilibili.com', |
|
|
|
|
|
|
|
|
// $headers = [
|
|
|
|
|
|
// 'accept' => '*/*',
|
|
|
|
|
|
// 'accept-language' => 'zh-CN,zh;q=0.9',
|
|
|
|
|
|
// 'cache-control' => 'no-cache',
|
|
|
|
|
|
// 'cookie' => 'buvid3=67245DCB-26E6-BFE8-A096-2DCD816F484E66359infoc; b_nut=1711166466; b_lsid=910710766F_18E69782A5E; _uuid=2C7BEEC1-10A8D-DE75-C9DF-E88C755982EE66658infoc; buvid4=72E32FA0-3DA0-B59A-28D0-19ED46EE5F2666682-024032304-9hlK%2FyFTfkthMYAU943pxw%3D%3D; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTE0MjU2NjYsImlhdCI6MTcxMTE2NjQwNiwicGx0IjotMX0.F2zbZtMifzoytWVX--7GF9ScxMJMmzHRWCcJjsxR1n4; bili_ticket_expires=1711425606; buvid_fp=7844041d2a1a51c5f6efcc4061de1838',
|
|
|
|
|
|
// 'origin' => 'https://space.bilibili.com',
|
|
|
|
|
|
// 'pragma' => 'no-cache',
|
|
|
|
|
|
// 'referer' => 'https://space.bilibili.com/496504596/dynamic',
|
|
|
|
|
|
// 'sec-ch-ua' => '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
|
|
|
|
|
|
// 'sec-ch-ua-mobile' => '?0',
|
|
|
|
|
|
// 'sec-ch-ua-platform' => '"macOS"',
|
|
|
|
|
|
// 'sec-fetch-dest' => 'empty',
|
|
|
|
|
|
// 'sec-fetch-mode' => 'cors',
|
|
|
|
|
|
// 'sec-fetch-site' => 'same-site',
|
|
|
|
|
|
// 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
|
|
|
|
|
|
// ];
|
|
|
|
|
|
$headers = [ |
|
|
'accept' => '*/*', |
|
|
'accept' => '*/*', |
|
|
'accept-language' => 'zh-CN,zh;q=0.9', |
|
|
'accept-language' => 'zh-CN,zh;q=0.9', |
|
|
'cache-control' => 'no-cache', |
|
|
'cache-control' => 'no-cache', |
|
|
'cookie' => 'buvid3=EF29B60A-6AA9-0563-A2FA-D92BEFC1B23067735infoc; b_nut=1702217967; b_lsid=2CFDCA64_18C5418E9FE; _uuid=4561010248-344A-4CFE-10D62-6BD31267D5A268133infoc; buvid4=6AF2B782-95B2-B1CF-0490-15EE12B63F7868264-023121014-; buvid_fp=16ca7877abf814d5ed71dfd8c26f15d7; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDI0NzcxNjksImlhdCI6MTcwMjIxNzkwOSwicGx0IjotMX0.y__-5e5q6Nhk_MpRZeLd9CIYw6xdwnmuv4OzA5qKVqw; bili_ticket_expires=1702477109', |
|
|
|
|
|
|
|
|
'cookie' => 'buvid3=BB2A4D5B-11A0-EC98-E67C-F2ECED51252D86432infoc; b_nut=1734395686; b_lsid=BE1058F9B_193D20A03B6; _uuid=710A46510F-EF510-82BC-ADA1-109F10959EFFA691964infoc; buvid_fp=6e25adce2c1a5f6f37bc796e0e5d0ac2; enable_web_push=DISABLE; home_feed_column=5; browser_resolution=1512-857; buvid4=464EFD3C-221D-0F82-BC3B-C2E217DDFBE194492-024121700-IeDz9F592rGhrGUI/Qk4mw%3D%3D; CURRENT_FNVAL=2000; sid=fs8i6afm; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzQ2NTQ5MDYsImlhdCI6MTczNDM5NTY0NiwicGx0IjotMX0.so25MAGIDzGSfgt-5hSDFgweUEE63ciiykyMhsYqsMM; bili_ticket_expires=1734654846', |
|
|
'origin' => 'https://space.bilibili.com', |
|
|
'origin' => 'https://space.bilibili.com', |
|
|
'pragma' => 'no-cache', |
|
|
'pragma' => 'no-cache', |
|
|
'referer' => 'https://space.bilibili.com/385079033/dynamic', |
|
|
|
|
|
'sec-ch-ua' => '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"', |
|
|
|
|
|
|
|
|
'priority' => 'u=1, i', |
|
|
|
|
|
'referer' => 'https://space.bilibili.com/418125910/dynamic', |
|
|
|
|
|
'sec-ch-ua' => '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', |
|
|
'sec-ch-ua-mobile' => '?0', |
|
|
'sec-ch-ua-mobile' => '?0', |
|
|
'sec-ch-ua-platform' => '"macOS"', |
|
|
'sec-ch-ua-platform' => '"macOS"', |
|
|
'sec-fetch-dest' => 'empty', |
|
|
'sec-fetch-dest' => 'empty', |
|
|
'sec-fetch-mode' => 'cors', |
|
|
'sec-fetch-mode' => 'cors', |
|
|
'sec-fetch-site' => 'same-site', |
|
|
'sec-fetch-site' => 'same-site', |
|
|
'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' |
|
|
|
|
|
|
|
|
'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' |
|
|
]; |
|
|
]; |
|
|
if ($offset != null) { |
|
|
if ($offset != null) { |
|
|
$url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?offset={$offset}&host_mid={$mid}&timezone_offset=-480&features=itemOpusStyle"; |
|
|
$url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?offset={$offset}&host_mid={$mid}&timezone_offset=-480&features=itemOpusStyle"; |
|
|
@ -1386,7 +1625,7 @@ done && echo "ok"'); |
|
|
$url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?offset=&host_mid={$mid}&timezone_offset=-480&features=itemOpusStyle"; |
|
|
$url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?offset=&host_mid={$mid}&timezone_offset=-480&features=itemOpusStyle"; |
|
|
} |
|
|
} |
|
|
$request = new Request('GET', $url, $headers); |
|
|
$request = new Request('GET', $url, $headers); |
|
|
$res = $client->sendAsync($request)->wait(); |
|
|
|
|
|
|
|
|
$res = $client->sendAsync($request, ['connect_timeout' => 100, 'debug' => true])->wait(); |
|
|
return $res->getBody(); |
|
|
return $res->getBody(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1425,27 +1664,26 @@ done && echo "ok"'); |
|
|
return preg_replace("#[!'()*/]#", '', $v); // 过滤 value 中的 "!'()*" 字符
|
|
|
return preg_replace("#[!'()*/]#", '', $v); // 过滤 value 中的 "!'()*" 字符
|
|
|
}, $params); |
|
|
}, $params); |
|
|
$query = http_build_query($params); // 序列化参数
|
|
|
$query = http_build_query($params); // 序列化参数
|
|
|
$query = str_replace("&dm_img_str", "&dm_img_list=%5B%5D&dm_img_str", $query); |
|
|
|
|
|
|
|
|
$query = str_replace("&dm_img_str", "&dm_img_list=%5B%5D&dm_img_str", $query); |
|
|
// echo $query;exit;
|
|
|
// echo $query;exit;
|
|
|
$wbi_sign = md5($query . $mixin_key); // 计算 w_rid
|
|
|
$wbi_sign = md5($query . $mixin_key); // 计算 w_rid
|
|
|
$params['w_rid'] = $wbi_sign; |
|
|
$params['w_rid'] = $wbi_sign; |
|
|
return $params; |
|
|
return $params; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function encWbiString($paramString, $img_key, $sub_key) |
|
|
|
|
|
{ |
|
|
|
|
|
$mixin_key = $this->getMixinKey($img_key . $sub_key); |
|
|
|
|
|
|
|
|
public function encWbiString($paramString, $img_key, $sub_key) { |
|
|
|
|
|
$mixin_key = $this->getMixinKey($img_key . $sub_key); |
|
|
$curr_time = round(time()); |
|
|
$curr_time = round(time()); |
|
|
$wts = $curr_time; // 添加 wts 字段
|
|
|
|
|
|
// echo "before $paramString \n";
|
|
|
|
|
|
// preg_replace("#[!'()*/]#", '', $paramString);
|
|
|
|
|
|
// echo "after $paramString \n";
|
|
|
|
|
|
$wbi_sign = md5($paramString . "&wts=" . $wts . $mixin_key); // 计算 w_rid
|
|
|
|
|
|
// echo "\n wbi sign is $wbi_sign \n";exit;
|
|
|
|
|
|
$params['w_rid'] = $wbi_sign; |
|
|
|
|
|
$params["new"] = $paramString . "&w_rid=" . $wbi_sign . "&wts=" . $wts; |
|
|
|
|
|
return $params; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$wts = $curr_time; // 添加 wts 字段
|
|
|
|
|
|
// echo "before $paramString \n";
|
|
|
|
|
|
// preg_replace("#[!'()*/]#", '', $paramString);
|
|
|
|
|
|
// echo "after $paramString \n";
|
|
|
|
|
|
$wbi_sign = md5($paramString . "&wts=" . $wts . $mixin_key); // 计算 w_rid
|
|
|
|
|
|
// echo "\n wbi sign is $wbi_sign \n";exit;
|
|
|
|
|
|
$params['w_rid'] = $wbi_sign; |
|
|
|
|
|
$params["new"] = $paramString . "&w_rid=" . $wbi_sign . "&wts=" . $wts; |
|
|
|
|
|
return $params; |
|
|
|
|
|
} |
|
|
public function getWbiKeys() { |
|
|
public function getWbiKeys() { |
|
|
$img_key = Redis::connection()->get("img_key"); |
|
|
$img_key = Redis::connection()->get("img_key"); |
|
|
$sub_key = Redis::connection()->get("sub_key"); |
|
|
$sub_key = Redis::connection()->get("sub_key"); |
|
|
@ -1467,24 +1705,124 @@ done && echo "ok"'); |
|
|
public function build_params($params) { |
|
|
public function build_params($params) { |
|
|
list($img_key, $sub_key) = $this->getWbiKeys(); |
|
|
list($img_key, $sub_key) = $this->getWbiKeys(); |
|
|
// dump($img_key);
|
|
|
// dump($img_key);
|
|
|
// dump($sub_key);
|
|
|
|
|
|
if (gettype($params) == "string") { |
|
|
|
|
|
$query = $this->encWbiString($params, $img_key, $sub_key); |
|
|
|
|
|
} else { |
|
|
|
|
|
$signed_params = $this->encWbi( |
|
|
|
|
|
$params, |
|
|
|
|
|
$img_key, |
|
|
|
|
|
$sub_key |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
// dump($sub_key);
|
|
|
|
|
|
if (gettype($params) == "string") { |
|
|
|
|
|
$query = $this->encWbiString($params, $img_key, $sub_key); |
|
|
|
|
|
} else { |
|
|
|
|
|
$signed_params = $this->encWbi( |
|
|
|
|
|
$params, |
|
|
|
|
|
$img_key, |
|
|
|
|
|
$sub_key |
|
|
|
|
|
); |
|
|
// dump($signed_params);exit;
|
|
|
// dump($signed_params);exit;
|
|
|
$query = http_build_query($signed_params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$query = http_build_query($signed_params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// print_r($signed_params);
|
|
|
// print_r($signed_params);
|
|
|
return $query; |
|
|
return $query; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function randFloat($min=0, $max=1){ |
|
|
|
|
|
return $min + mt_rand()/mt_getrandmax() * ($max-$min); |
|
|
|
|
|
|
|
|
public function randFloat($min = 0, $max = 1) { |
|
|
|
|
|
return $min + mt_rand() / mt_getrandmax() * ($max - $min); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function GetRandStr($length) { |
|
|
|
|
|
//字符组合
|
|
|
|
|
|
$str = 'ABCDEFGHIJK'; |
|
|
|
|
|
$len = strlen($str) - 1; |
|
|
|
|
|
$randstr = ''; |
|
|
|
|
|
for ($i = 0; $i < $length; $i++) { |
|
|
|
|
|
$num = mt_rand(0, $len); |
|
|
|
|
|
$randstr .= $str[$num]; |
|
|
|
|
|
} |
|
|
|
|
|
return $randstr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getWebId() |
|
|
|
|
|
{ |
|
|
|
|
|
$content = file_get_contents("https://space.bilibili.com/16720403/video"); |
|
|
|
|
|
// echo $content;
|
|
|
|
|
|
$start = '<script id="__RENDER_DATA__" type="application/json">'; |
|
|
|
|
|
// echo "\n" . strlen($start);
|
|
|
|
|
|
$end = '</script>'; |
|
|
|
|
|
$pos1 = strpos($content, $start, 0); |
|
|
|
|
|
$pos2 = strpos($content, $end, $pos1); |
|
|
|
|
|
// echo "\n" . $pos1;
|
|
|
|
|
|
// echo "\n" . $pos2;
|
|
|
|
|
|
$encodeStr = substr($content, $pos1 + strlen($start), $pos2 - $pos1 - strlen($start)); |
|
|
|
|
|
// echo "\n" . urldecode($encodeStr);
|
|
|
|
|
|
return json_decode(urldecode($encodeStr), true)["access_id"]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function queryBiliUpListNew($mediaId = 320491072, $startPos = 0, $limit = 20) { |
|
|
|
|
|
Log::info("schedule queryUpVideoList inner started at: " . date("Y-m-d H:i:s")); |
|
|
|
|
|
|
|
|
|
|
|
// 475250 kyokyo
|
|
|
|
|
|
// 3489535 熊小颖
|
|
|
|
|
|
// 320491072 绯绯
|
|
|
|
|
|
// 10139490 短短
|
|
|
|
|
|
// 116683 咬人猫
|
|
|
|
|
|
// 16539048 小仙若
|
|
|
|
|
|
// 10278125 香草猫饼
|
|
|
|
|
|
// 391073761 女团直拍
|
|
|
|
|
|
// 267781236 韩国女团饭拍直拍
|
|
|
|
|
|
// 23400436 小雪_juvia
|
|
|
|
|
|
$list = BilibiliUpVideos::where("id", "<=", "200") |
|
|
|
|
|
->orderBy('id', 'desc') |
|
|
|
|
|
->offset($startPos) |
|
|
|
|
|
->limit($limit) |
|
|
|
|
|
->get(); |
|
|
|
|
|
// $list = $list->slice(5);
|
|
|
|
|
|
$url = "https://app.bilibili.com/x/v2/space/archive/cursor?order=pubdate&vmid="; |
|
|
|
|
|
foreach ($list as $key => $item) { |
|
|
|
|
|
$aid = null; |
|
|
|
|
|
$i = 0; |
|
|
|
|
|
do { |
|
|
|
|
|
$i++; |
|
|
|
|
|
Log::info("schedule queryUpVideoList current up is {$item['up_name']}, started at: " . date("Y-m-d H:i:s")); |
|
|
|
|
|
echo $item["mid"] . " " . $item["up_name"]; |
|
|
|
|
|
if ($aid != null) { |
|
|
|
|
|
echo " has next \n"; |
|
|
|
|
|
$content = file_get_contents($url . $item["mid"] . "&aid=" . $aid); |
|
|
|
|
|
} else{ |
|
|
|
|
|
echo " start \n"; |
|
|
|
|
|
$content = file_get_contents($url . $item["mid"]); |
|
|
|
|
|
} |
|
|
|
|
|
$jsonContent = json_decode($content, true); |
|
|
|
|
|
if (array_key_exists("data", $jsonContent) && array_key_exists("item", $jsonContent["data"]) && $jsonContent["data"]["item"] != null && count($jsonContent["data"]["item"]) > 0) { |
|
|
|
|
|
$aid = null; |
|
|
|
|
|
foreach ($jsonContent["data"]["item"] as $vItem) { |
|
|
|
|
|
$avid = substr($vItem["three_point"][1]["share_path"], strpos($vItem["three_point"][1]["share_path"], "=") + 1); |
|
|
|
|
|
// echo $avid;exit;
|
|
|
|
|
|
if(BilibiliVideos::where(["bv_id" => $vItem["bvid"]])->exists() && $i > 2) { |
|
|
|
|
|
echo "bvid " . $vItem["bvid"] . " " . $vItem["title"] . " exist skip to next\n"; |
|
|
|
|
|
break 2; |
|
|
|
|
|
} |
|
|
|
|
|
$bVideo = BilibiliVideos::firstOrCreate(["bv_id" => $vItem["bvid"]], |
|
|
|
|
|
[ |
|
|
|
|
|
"title" => $vItem["title"], |
|
|
|
|
|
"from_type" => 2, |
|
|
|
|
|
"from_up_name" => $item["up_name"], |
|
|
|
|
|
"bv_id" => $vItem["bvid"], |
|
|
|
|
|
"aid" => $avid, |
|
|
|
|
|
"up_mid" => $item["mid"], |
|
|
|
|
|
"collection_mid" => 0, |
|
|
|
|
|
]); |
|
|
|
|
|
if ($bVideo->from_type != 2) { |
|
|
|
|
|
$bVideo->from_type = 3; |
|
|
|
|
|
} |
|
|
|
|
|
$bVideo->bv_id = $vItem["bvid"]; |
|
|
|
|
|
$bVideo->up_mid = $item["mid"]; |
|
|
|
|
|
$bVideo->from_up_name = $item["up_name"]; |
|
|
|
|
|
$bVideo->save(); |
|
|
|
|
|
$aid = $vItem["param"]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
usleep(random_int(1000, 10000) * 1000); |
|
|
|
|
|
} while ($jsonContent["data"]["has_next"] && $aid != null); |
|
|
|
|
|
// exit;
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |