2022-02-05 14:05:00 +09:00
|
|
|
<?php
|
|
|
|
|
2022-02-11 22:41:29 +09:00
|
|
|
namespace App\Http\Controllers;
|
2022-02-05 14:05:00 +09:00
|
|
|
use Illuminate\Http\Request;
|
2022-02-11 22:41:29 +09:00
|
|
|
use App\Http\Controllers\Common;
|
2022-02-05 14:05:00 +09:00
|
|
|
// use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class Account extends Common {
|
|
|
|
private $common;
|
2022-02-10 02:28:54 +09:00
|
|
|
private $count;
|
2022-02-05 14:05:00 +09:00
|
|
|
|
|
|
|
public function __construct () {
|
|
|
|
$this->common = new Common;
|
2022-02-10 02:28:54 +09:00
|
|
|
$this->count = 25;
|
2022-02-05 14:05:00 +09:00
|
|
|
}
|
|
|
|
|
2022-02-10 02:28:54 +09:00
|
|
|
public function index ($id, $cat='video-channels', $page=0) {
|
2022-02-05 14:05:00 +09:00
|
|
|
$res = [
|
|
|
|
'page' => 'account',
|
|
|
|
'style' => 'account',
|
|
|
|
'cat' => $cat,
|
2022-02-10 02:28:54 +09:00
|
|
|
'paginate' => $page,
|
|
|
|
'pagetotal' => 500,
|
2022-02-05 14:05:00 +09:00
|
|
|
'userinfo' => $this->common->user,
|
|
|
|
];
|
2022-02-10 02:28:54 +09:00
|
|
|
|
2022-02-05 14:05:00 +09:00
|
|
|
$res['owner'] = $this->getOwner($id);
|
|
|
|
if (!empty($res['owner'])) $res['owner']->totalVideo = 0;
|
2022-02-10 02:28:54 +09:00
|
|
|
$res['channel'] = $this->getChannel($id, $cat, ($page*$this->count), $this->count);
|
2022-02-05 14:05:00 +09:00
|
|
|
if (!empty($res['owner'])) {
|
2022-02-10 02:28:54 +09:00
|
|
|
if ($cat == 'video-channels') {
|
|
|
|
$stats = $this->ptapi('/api/v1/accounts/'.$id.'/videos?start=0&count=0&skipCount=false&nsfw=both');
|
|
|
|
$res['owner']->totalVideo = $stats->total;
|
|
|
|
foreach ($res['channel']->data as $k => $v) {
|
|
|
|
$res['channel']->data[$k]->video = $this->getVideo($v->name.'@'.$v->host);
|
|
|
|
$res['owner']->followersCount += $v->followersCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$stats = $this->ptapi('/api/v1/accounts/'.$id.'/video-channels?start=0&count=20');
|
|
|
|
$res['owner']->totalVideo = $res['channel']->total;
|
|
|
|
foreach ($stats->data as $k => $v) {
|
|
|
|
$res['channel']->data[$k]->video = $this->getVideo($v->name.'@'.$v->host);
|
|
|
|
$res['owner']->followersCount += $v->followersCount;
|
|
|
|
}
|
2022-02-05 14:05:00 +09:00
|
|
|
}
|
|
|
|
}
|
2022-02-10 02:28:54 +09:00
|
|
|
|
|
|
|
return view('pages.peertube.a', ['res' => $res, 'cat' => $cat]);
|
2022-02-05 14:05:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function getOwner ($id) {
|
|
|
|
return $this->ptapi('/api/v1/accounts/'.$id);
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:28:54 +09:00
|
|
|
function getChannel ($id, $cat, $start, $count) {
|
|
|
|
if ($cat == 'video-channels') $count = 5;
|
|
|
|
$sort = $cat == 'video-channels' ? '-updatedAt&withStats=false' : '-publishedAt&skipCount=false&nsfw=both';
|
|
|
|
return $this->ptapi('/api/v1/accounts/'.$id.'/'.$cat.'?start='.$start.'&count='.$count.'&sort='.$sort);
|
2022-02-05 14:05:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function getVideo ($id) {
|
2022-02-10 02:28:54 +09:00
|
|
|
return $this->ptapi('/api/v1/video-channels/'.$id.'/videos?start=0&count=5&sort=-publishedAt&skipCount=false&nsfw=both');
|
2022-02-05 14:05:00 +09:00
|
|
|
}
|
|
|
|
}
|