common = new Common; } public function index ($id) { $res = []; $res['detail'] = $this->getDetail($id); $res['comment'] = $this->getComment($id); $res['recommend'] = $this->getRecommend($res['detail']->tags); return view('pages.peertube.w', ['res' => $res]); } function getDetail ($id) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/videos/'.$id); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $get = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if (!$get) return $err; $get = json_decode($get); return $get; } public function getRecommend ($tags) { $ch = curl_init(); $tag = ''; foreach ($tags as $t) { $tag .= 'tagsOneOf='.urlencode($t).'&'; } curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/search/videos?start=0&count=6&nsfw=both&'.$tag.'sort=-publishedAt&searchTarget=local'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $get = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if (!$get) return $err; $get = json_decode($get); if (isset($get->status) && $get->status == 404) return []; return $get; } public function getComment ($id) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/videos/'.$id.'/comment-threads'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $get = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if (!$get) return $err; $get = json_decode($get); if (isset($get->status) && $get->status == 404) return []; return $get; } }