-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouTube.php
More file actions
62 lines (53 loc) · 1.67 KB
/
Copy pathYouTube.php
File metadata and controls
62 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/site/blob/master/LICENSE
*/
namespace Quid\Site\Service;
use Quid\Base;
use Quid\Main;
// youTube
// class that can be used to make requests to the YouTube API
class YouTube extends Main\ServiceVideo
{
// config
protected static array $config = [
'required'=>['provider_url','thumbnail_url','html'],
'video'=>[
'name'=>'title',
'absolute'=>[self::class,'videoAbsolute'],
'thumbnail'=>'thumbnail_url',
'html'=>'html'],
'hostsValid'=>['youtube.com','www.youtube.com'],
'target'=>'https://www.youtube.com/oembed?url=%value%&format=json' // uri target pour youTube
];
// videoAbsolute
// retourne l'uri absolut pour la vidéo youTube
// callback utilisé par la classe video
final public static function videoAbsolute(Main\Video $video):?string
{
$return = null;
$provider = $video->get('provider_url');
$thumbnail = $video->get('thumbnail_url');
if(!empty($provider) && !empty($thumbnail))
{
$path = Base\Uri::path($thumbnail);
$x = Base\Path::arr($path);
$key = $x[1] ?? null;
if(!empty($key))
{
$query = ['v'=>$key];
$change = [];
$change['path'] = 'watch';
$change['query'] = $query;
$return = Base\Uri::change($change,$provider);
}
}
return $return;
}
}
// init
YouTube::__init();
?>