common = new Common; } public function index ($id, Request $r) { $res = [ 'page' => 'playlist', 'style' => 'watch', 'id' => $id, 'pos' => isset($r->playlistPosition) ? (int)$r->playlistPosition : 1, 'resume' => isset($r->resume) ? (bool)$r->resume : true, 'userinfo' => $this->common->user, ]; $det = $this->getDetail($id); $res['playlist'] = $det; $res['plvid'] = $this->getVideos($det->uuid, 0, $det->videosLength); if ($res['pos'] < 1) $res['pos'] = 1; if ($res['pos'] > $det->videosLength) $res['pos'] = $det->videosLength; $id = 0; foreach ($res['plvid']->data as $k => $v) { if ($v->position == $res['pos']) { $id = $v->video->uuid; $res['detail'] = $this->getVideo($id); } $res['plvid']->data[$k]->video->nameShort = strlen($res['plvid']->data[$k]->video->name) > 45 ? substr($res['plvid']->data[$k]->video->name, 0, 45).'...' : $res['plvid']->data[$k]->video->name; } $res = $this->getComment($id, $res); $tags = []; if (!is_null($res['detail']->tags)) $tags = $res['detail']->tags; else $tags = explode(' ', $res['detail']->title); $res['recommend'] = $this->getRecommend($tags); return view('pages.peertube.w.p', ['res' => $res]); } function getDetail ($id) { return $this->ptapi('/api/v1/video-playlists/'.$id); } function getVideos ($uuid, $start, $count) { return $this->ptapi('/api/v1/video-playlists/'.$uuid.'/videos?start='.$start.'&count='.$count); } function getVideo ($uuid) { return $this->ptapi('/api/v1/videos/'.$uuid); } function getRecommend ($tags) { $tag = ''; foreach ($tags as $t) { $tag .= 'tagsOneOf='.urlencode($t).'&'; } return $this->ptapi('/api/v1/search/videos?start=0&count=6&nsfw=both&'.$tag.'sort=-publishedAt&searchTarget=local'); } function getComment ($id, $res) { $get = null; $res['comment'] = $this->ptapi('/api/v1/videos/'.$id.'/comment-threads'); foreach ($res['comment']->data as $co) { $co->src = 'PT'; } return $res; } }