1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace RicardoFiorani\Adapter\Dailymotion; |
4
|
|
|
|
5
|
|
|
use RicardoFiorani\Adapter\AbstractServiceAdapter; |
6
|
|
|
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException; |
7
|
|
|
use RicardoFiorani\Renderer\EmbedRendererInterface; |
8
|
|
|
|
9
|
|
|
class DailymotionServiceAdapter extends AbstractServiceAdapter |
10
|
|
|
{ |
11
|
|
|
const THUMBNAIL_DEFAULT = 'thumbnail'; |
12
|
|
|
|
13
|
|
|
public function __construct(string $url, string $pattern, EmbedRendererInterface $renderer) |
14
|
|
|
{ |
15
|
|
|
$videoId = strtok(basename($url), '_'); |
16
|
|
|
$this->setVideoId($videoId); |
17
|
|
|
|
18
|
|
|
return parent::__construct($url, $pattern, $renderer); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getServiceName(): string |
22
|
|
|
{ |
23
|
|
|
return 'Dailymotion'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function hasThumbnail(): bool |
27
|
|
|
{ |
28
|
|
|
return true; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getThumbNailSizes(): array |
32
|
|
|
{ |
33
|
|
|
return array( |
34
|
|
|
self::THUMBNAIL_DEFAULT, |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @throws InvalidThumbnailSizeException |
40
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function getThumbnail(string $size, bool $forceSecure = false): string |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
if (false == in_array($size, $this->getThumbNailSizes())) { |
|
|
|
|
45
|
|
|
throw new InvalidThumbnailSizeException(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws InvalidThumbnailSizeException |
53
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
54
|
|
|
*/ |
55
|
|
|
public function getSmallThumbnail(bool $forceSecure = false): string |
56
|
|
|
{ |
57
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
58
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws InvalidThumbnailSizeException |
63
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
64
|
|
|
*/ |
65
|
|
|
public function getMediumThumbnail(bool $forceSecure = false): string |
66
|
|
|
{ |
67
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
68
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @throws InvalidThumbnailSizeException |
73
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
74
|
|
|
*/ |
75
|
|
|
public function getLargeThumbnail(bool $forceSecure = false): string |
76
|
|
|
{ |
77
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
78
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @throws InvalidThumbnailSizeException |
83
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
84
|
|
|
*/ |
85
|
|
|
public function getLargestThumbnail(bool $forceSecure = false): string |
86
|
|
|
{ |
87
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
88
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
93
|
|
|
*/ |
94
|
|
|
public function getEmbedUrl(bool $forceAutoplay = false, bool $forceSecure = false): string |
95
|
|
|
{ |
96
|
|
|
return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : ''); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function isEmbeddable(): bool |
100
|
|
|
{ |
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|