|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://dukt.net/videos/ |
|
4
|
|
|
* @copyright Copyright (c) Dukt |
|
5
|
|
|
* @license https://github.com/dukt/videos/blob/v2/LICENSE.md |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace dukt\videos\web\twig\variables; |
|
9
|
|
|
|
|
10
|
|
|
use Craft; |
|
11
|
|
|
use dukt\videos\models\Video; |
|
12
|
|
|
use dukt\videos\Plugin as Videos; |
|
13
|
|
|
|
|
14
|
|
|
class VideosVariable |
|
15
|
|
|
{ |
|
16
|
|
|
// Public Methods |
|
17
|
|
|
// ========================================================================= |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Get Embed. |
|
21
|
|
|
* |
|
22
|
|
|
* @param $videoUrl |
|
23
|
|
|
* @param array $embedOptions |
|
24
|
|
|
* |
|
25
|
|
|
* @return mixed |
|
26
|
|
|
* @throws \yii\base\InvalidConfigException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getEmbed($videoUrl, array $embedOptions = []) |
|
29
|
|
|
{ |
|
30
|
|
|
return Videos::$plugin->getVideos()->getEmbed($videoUrl, $embedOptions); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get a video from its URL. |
|
35
|
|
|
* |
|
36
|
|
|
* @param $videoUrl |
|
37
|
|
|
* @param bool $enableCache |
|
38
|
|
|
* @param int $cacheExpiry |
|
39
|
|
|
* |
|
40
|
|
|
* @return Video|null |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getVideoByUrl($videoUrl, bool $enableCache = true, int $cacheExpiry = null): ?\dukt\videos\models\Video |
|
43
|
|
|
{ |
|
44
|
|
|
try { |
|
45
|
|
|
return Videos::$plugin->getVideos()->getVideoByUrl($videoUrl, $enableCache, $cacheExpiry); |
|
46
|
|
|
} catch (\Exception $exception) { |
|
47
|
|
|
Craft::info('Couldn’t get video from its url (' . $videoUrl . '): ' . $exception->getMessage(), __METHOD__); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return null; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Alias for the `getVideoByUrl()` method. |
|
55
|
|
|
* |
|
56
|
|
|
* @param $videoUrl |
|
57
|
|
|
* @param bool $enableCache |
|
58
|
|
|
* @param int $cacheExpiry |
|
59
|
|
|
* @return Video|null |
|
60
|
|
|
*/ |
|
61
|
|
|
public function url($videoUrl, bool $enableCache = true, int $cacheExpiry = null): ?\dukt\videos\models\Video |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->getVideoByUrl($videoUrl, $enableCache, $cacheExpiry); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|