use App\Utils\BiliBiliHelper; use App\Utils\RequestUtil; use Illuminate\Support\Facades\Cache; $app = (require __DIR__ . '/bootstrap/app.php'); date_default_timezone_set('PRC'); try { $sort_list = []; foreach (BiliBiliHelper::getSorts() as $key => $value) { $request_array = ['tid' => $key, 'order' => 'hot', 'page' => '1', 'pagesize' => '20']; $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/sort?' . http_build_query($request_array)); $sort_list[$key] = $back['content']; } $index = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/index'); $refresh_time = date('H:i:s'); $bangumi = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/bangumi?type=2'); $bangumi_result = []; for ($i = 0; $i < 7; $i++) { $day_bangumi = []; $bangumi_result[$i] = $day_bangumi; } foreach ($bangumi['content']['list'] as $animation) { if (isset($animation['cover'])) { array_push($bangumi_result[$animation['weekday']], $animation); } } Cache::forever('index_cache', $index['content']); Cache::forever('sort_cache', $sort_list); Cache::forever('bangumi_cache', $bangumi_result); Cache::forever('refresh_time', $refresh_time); dd('ok');
public function test() { $sort_list = []; foreach (BiliBiliHelper::getNicoSorts() as $key => $value) { $back = RequestUtil::normalGetUrl('http://www.nicovideo.jp/ranking/fav/hourly/' . $key . '?rss=2.0&lang=ja-jp'); $xmlDoc = new DOMDocument(); $xmlDoc->loadXML($back); $element = $xmlDoc->documentElement; $chanel = $element->getElementsByTagName('channel')->item(0); $video_array = []; foreach ($chanel->getElementsByTagName('item') as $item) { $inner = []; $inner['title'] = explode(':', $item->getElementsByTagName('title')[0]->nodeValue)[1]; $inner['id'] = explode('watch/', $item->getElementsByTagName('link')[0]->nodeValue)[1]; array_push($video_array, $inner); } $sort_list[$key] = $video_array; } Cache::forever('nico_cache', $sort_list); dd('ok'); }
<?php use App\Utils\BiliBiliHelper; use App\Utils\RequestUtil; use Illuminate\Support\Facades\Cache; $app = (require __DIR__ . '/bootstrap/app.php'); $sort_list = []; foreach (BiliBiliHelper::getNicoSorts() as $key => $value) { $back = RequestUtil::normalGetUrl('http://www.nicovideo.jp/ranking/fav/hourly/' . $key . '?rss=2.0&lang=ja-jp'); $xmlDoc = new DOMDocument(); $xmlDoc->loadXML($back); $element = $xmlDoc->documentElement; $chanel = $element->getElementsByTagName('channel')->item(0); $video_array = []; foreach ($chanel->getElementsByTagName('item') as $item) { $inner = []; $inner['title'] = explode(':', $item->getElementsByTagName('title')[0]->nodeValue)[1]; $inner['id'] = explode('watch/', $item->getElementsByTagName('link')[0]->nodeValue)[1]; array_push($video_array, $inner); } $sort_list[$key] = $video_array; } Cache::forever('nico_cache', $sort_list); dd('ok');
public function searchPage($content, Request $request) { try { $page = $request->get('page', 2); //页码非法检测 if ($page < 2) { $page = 2; } $request_array = ['keyword' => $content, 'page' => $page, 'pagesize' => 8]; $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/search?' . http_build_query($request_array)); $return_array = ['code' => 'success', 'content' => $back['content']]; return response()->json($return_array); } catch (\Exception $e) { $return_array = ['code' => 'error', 'content' => $e->getMessage()]; return response()->json($return_array); } }
while (true) { if ($startId >= $maxId) { $newMaxId = $startId + 1000; $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . "/view/{$newMaxId}"); if ($back['code'] == 200) { $maxId = $newMaxId; } else { echo 'sleep-1-20s \\n'; sleep(20); $startId++; } echo 'sleep-2-10s \\n'; sleep(10); continue; } $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . "/view/{$startId}"); if ($back['code'] != 200) { echo 'sleep-3-10s \\n'; sleep(10); $startId++; continue; } echo strval($startId) . '\\n'; $content = $back['content']; $content['aid'] = $startId; $content["_id"] = $startId; $collVideos->save($content); $collection->save(array("_id" => 1, "startId" => $startId)); $startId++; sleep(8); }
public function viewNico($id) { $request_aray = ['__format' => 'json', 'v' => $id]; try { $back = RequestUtil::normalGetUrl('http://api.ce.nicovideo.jp/nicoapi/v1/video.info?' . http_build_query($request_aray)); $back = json_decode($back, true); $content = $back['nicovideo_video_response']; if ($content['@status'] != 'ok') { throw new Exception('Back error...'); } return view('play_nico')->with('content', $content['video']); } catch (\Exception $e) { return $this->returnError($e->getMessage()); } }
public function test() { try { $sort_list = []; foreach (BiliBiliHelper::getSorts() as $key => $value) { $request_array = ['tid' => $key, 'order' => 'hot', 'page' => '1', 'pagesize' => '20']; $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/sort?' . http_build_query($request_array)); $sort_list[$key] = $back['content']; } $index = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/index'); $refresh_time = date('H:i:s'); $bangumi = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/bangumi?type=2'); $bangumi_result = []; for ($i = 0; $i < 7; $i++) { $day_bangumi = []; $bangumi_result[$i] = $day_bangumi; } foreach ($bangumi['content']['list'] as $animation) { if (isset($animation['cover'])) { array_push($bangumi_result[$animation['weekday']], $animation); } } Cache::forever('index_cache', $index['content']); Cache::forever('sort_cache', $sort_list); Cache::forever('refresh_time', $refresh_time); Cache::forever('bangumi_cache', $bangumi_result); dd('ok'); } catch (\Exception $e) { dd($e); } }