diff --git a/config/module.config.php b/config/module.config.php index 3ed4155..0517260 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -17,6 +17,16 @@ return [ Form\PeertubeVideoBlockForm::class => Form\PeertubeVideoBlockForm::class, ], ], + 'media_ingesters' => [ + 'factories' => [ + 'PeertubeVideo_media' => Service\Media\Ingester\PeertubeMediaFactory::class, + ], + ], + 'media_renderers' => [ + 'invokables' => [ + 'PeertubeVideo_media' => Media\Renderer\PeertubeMediaRenderer::class, + ], + ], 'DefaultSettings' => [ 'PeertubeVideoBlockForm' => [ 'url' => '', diff --git a/src/Form/PeertubeVideoBlockForm.php b/src/Form/PeertubeVideoBlockForm.php index 80e46bd..38e1325 100644 --- a/src/Form/PeertubeVideoBlockForm.php +++ b/src/Form/PeertubeVideoBlockForm.php @@ -10,6 +10,7 @@ class PeertubeVideoBlockForm extends Form public function init() { + /* $this->add([ 'name' => 'o:block[__blockIndex__][o:data][url]', 'type' => Element\Text::class, @@ -17,7 +18,7 @@ class PeertubeVideoBlockForm extends Form 'label' => 'Video URL', ] ]); - + */ $this->add([ 'name' => 'o:block[__blockIndex__][o:data][ratio]', 'type' => Element\Select::class, diff --git a/src/Media/Ingester/PeertubeMediaIngester.php b/src/Media/Ingester/PeertubeMediaIngester.php new file mode 100644 index 0000000..cc2838e --- /dev/null +++ b/src/Media/Ingester/PeertubeMediaIngester.php @@ -0,0 +1,69 @@ +client = $client; + } + public function getLabel() + { + return 'PeerTube video'; // @translate + } + public function getRenderer() + { + return 'PeertubeVideo_media'; + } + public function form(PhpRenderer $view, array $options = []) + { + $input = new Text('o:media[__index__][o:source]'); + $input->setOptions([ + 'label' => 'Video URL', // @translate + 'info' => 'URL for the video to embed.', // @translate + ]); + $input->setAttributes([ + 'required' => true, + ]); + return $view->formRow($input); + } + public function ingest(Media $media, Request $request, ErrorStore $errorStore) + { + // Validate the request data. + $data = $request->getContent(); + if (!isset($data['o:source'])) { + $errorStore->addError('o:source', 'No video URL specified'); + return; + } + // Get the video JSON data. + + //$url = urlencode($data['o:source']); + $url = $data['o:source']; + $parsed_url = parse_url(trim($url)); + $base_url = $parsed_url['scheme']. '://' .$parsed_url['host']; + $path_parts = explode("/", $parsed_url['path']); + $api_url .= $base_url . '/api/v1/videos/' . end($path_parts); + $response = $this->client->setUri($api_url)->send(); + if (!$response->isOk()) { + $errorStore->addError('o:source', sprintf( + 'Error reading video: %s (%s) %s', + $response->getReasonPhrase(), + $response->getStatusCode(), + $base_url + )); + return false; + } + // Set the Media source and data. + $media->setSource($url); + $media->setData(json_decode($response->getBody(), true)); + } +} diff --git a/src/Media/Renderer/PeertubeMediaRenderer.php b/src/Media/Renderer/PeertubeMediaRenderer.php new file mode 100644 index 0000000..6b788b8 --- /dev/null +++ b/src/Media/Renderer/PeertubeMediaRenderer.php @@ -0,0 +1,28 @@ +source()); + if (parse_url($url, PHP_URL_QUERY)) { + $url .= '&peertubeLink=0'; + } else { + $url .= '?peertubeLink=0'; + } + $html = '