1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Ricardo Fiorani |
5
|
|
|
* Date: 30/08/2015 |
6
|
|
|
* Time: 14:38. |
7
|
|
|
*/ |
8
|
|
|
namespace RicardoFiorani\Adapter\Dailymotion; |
9
|
|
|
|
10
|
|
|
use RicardoFiorani\Adapter\AbstractServiceAdapter; |
11
|
|
|
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException; |
12
|
|
|
use RicardoFiorani\Renderer\EmbedRendererInterface; |
13
|
|
|
|
14
|
|
|
class DailymotionServiceAdapter extends AbstractServiceAdapter |
15
|
|
|
{ |
16
|
|
|
const THUMBNAIL_DEFAULT = 'thumbnail'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* AbstractVideoAdapter constructor. |
20
|
|
|
* |
21
|
|
|
* @param string $url |
22
|
|
|
* @param string $pattern |
23
|
|
|
* @param EmbedRendererInterface $renderer |
24
|
|
|
*/ |
25
|
|
|
public function __construct($url, $pattern, EmbedRendererInterface $renderer) |
26
|
|
|
{ |
27
|
|
|
$videoId = strtok(basename($url), '_'); |
28
|
|
|
$this->setVideoId($videoId); |
29
|
|
|
|
30
|
|
|
return parent::__construct($url, $pattern, $renderer); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns the service name (ie: "Youtube" or "Vimeo"). |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getServiceName() |
39
|
|
|
{ |
40
|
|
|
return 'Dailymotion'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns if the service has a thumbnail image. |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
public function hasThumbnail() |
49
|
|
|
{ |
50
|
|
|
return true; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns all thumbnails available sizes. |
55
|
|
|
* |
56
|
|
|
* @return array |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
public function getThumbNailSizes() |
59
|
|
|
{ |
60
|
|
|
return array( |
61
|
|
|
self::THUMBNAIL_DEFAULT, |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $size |
67
|
|
|
* @param bool $forceSecure |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
* @throws InvalidThumbnailSizeException |
71
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function getThumbnail($size, $forceSecure = false) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
if (false == in_array($size, $this->getThumbNailSizes())) { |
|
|
|
|
76
|
|
|
throw new InvalidThumbnailSizeException(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the small thumbnail's url. |
84
|
|
|
* |
85
|
|
|
* @param bool $forceSecure |
86
|
|
|
* @return string |
87
|
|
|
* @throws InvalidThumbnailSizeException |
88
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
89
|
|
|
*/ |
90
|
|
|
public function getSmallThumbnail($forceSecure = false) |
91
|
|
|
{ |
92
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
93
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the medium thumbnail's url. |
98
|
|
|
* |
99
|
|
|
* @param bool $forceSecure |
100
|
|
|
* @return string |
101
|
|
|
* @throws InvalidThumbnailSizeException |
102
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
103
|
|
|
*/ |
104
|
|
|
public function getMediumThumbnail($forceSecure = false) |
105
|
|
|
{ |
106
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
107
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns the large thumbnail's url. |
112
|
|
|
* |
113
|
|
|
* @param bool $forceSecure |
114
|
|
|
* @return string |
115
|
|
|
* @throws InvalidThumbnailSizeException |
116
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
117
|
|
|
*/ |
118
|
|
|
public function getLargeThumbnail($forceSecure = false) |
119
|
|
|
{ |
120
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
121
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the largest thumnbnaail's url. |
126
|
|
|
* @param bool $forceSecure |
127
|
|
|
* @return string |
128
|
|
|
* @throws InvalidThumbnailSizeException |
129
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
130
|
|
|
*/ |
131
|
|
|
public function getLargestThumbnail($forceSecure = false) |
132
|
|
|
{ |
133
|
|
|
//Since this service does not provide other thumbnails sizes we just return the default size |
134
|
|
|
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param bool $forceAutoplay |
139
|
|
|
* @param bool $forceSecure |
140
|
|
|
* @return string |
141
|
|
|
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException |
142
|
|
|
*/ |
143
|
|
|
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) |
144
|
|
|
{ |
145
|
|
|
return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : ''); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
|
|
public function isEmbeddable() |
152
|
|
|
{ |
153
|
|
|
return true; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|