このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/Peertube/Watch.php

79 行
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Peertube;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Peertube\Common;
// use Illuminate\Support\Facades\Log;
class Watch extends Common {
private $common;
public function __construct () {
$this->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;
}
}