Пример #1
0
 public function sort($tid, Request $request)
 {
     $sorts = BiliBiliHelper::getSorts();
     //分类非法检测
     if (!array_has($sorts, $tid)) {
         return $this->returnError('分类不存在');
     }
     $order = $request->get('order', 'hot');
     $page = $request->get('page', 1);
     //页码非法检测
     if ($page < 1) {
         $page = 1;
     }
     //默认取出redis
     if ($order == 'hot' && $page == 1) {
         $redis = new Client();
         $date = $redis->hget('update', 'sort');
         $sort = $redis->hget('sort', $sorts[$tid]);
         $sort = json_decode($sort, true);
     } else {
         try {
             $request_array = ['tid' => $tid, 'order' => $order, 'page' => $page, 'pagesize' => 20];
             $date = date('H:i:s');
             $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/sort?' . http_build_query($request_array));
             $sort = $back['content'];
         } catch (\Exception $e) {
             return $this->returnError('服务器君忙,待会再试吧...');
         }
     }
     return view('sort')->with('content', $sort)->with('tid', $tid)->with('page', $page)->with('date', $date);
 }
Пример #2
0
 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');
 }
Пример #3
0
<?php

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);
Пример #4
0
 public function nicoSort($sort, Request $request)
 {
     $sorts = BiliBiliHelper::getNicoSorts();
     //分类非法检测
     if (!array_has($sorts, $sort)) {
         return $this->returnError('分类不存在');
     }
     $page = $request->get('page', 1);
     //页码非法检测
     $page = $page < 1 ? 1 : $page;
     $page = $page > 2 ? 2 : $page;
     $content = Cache::get('nico_cache');
     $date = Cache::get('refresh_time');
     $lists = array_chunk($content[$sort], 50);
     return view('sort_nico')->with('list', $lists[$page - 1])->with('page', $page)->with('sort', $sort)->with('date', $date)->with('tag_name', $sorts[$sort]);
 }
Пример #5
0
 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);
     }
 }