1
1
<?php
2
- /**
3
- * Created by PhpStorm.
4
- * User: Ricardo Fiorani
5
- * Date: 29/08/2015
6
- * Time: 14:56.
7
- */
2
+
8
3
namespace RicardoFiorani \Adapter \Vimeo ;
9
4
10
5
use RicardoFiorani \Adapter \AbstractServiceAdapter ;
@@ -42,18 +37,19 @@ class VimeoServiceAdapter extends AbstractServiceAdapter
42
37
*/
43
38
public function __construct ($ url , $ pattern , EmbedRendererInterface $ renderer )
44
39
{
45
- $ videoId = $ this ->getVideoIdByPattern ($ url , $ pattern );
40
+ $ videoData = $ this ->getVideoDataFromServiceApi ($ url );
41
+ $ videoId = $ videoData ->video_id ;
46
42
$ this ->setVideoId ($ videoId );
47
- $ videoData = $ this ->getVideoDataFromServiceApi ();
48
43
44
+ //oEmbed only provides one size now :(
49
45
$ this ->setThumbnails (array (
50
- self ::THUMBNAIL_SMALL => $ videoData[ self :: THUMBNAIL_SMALL ] ,
51
- self ::THUMBNAIL_MEDIUM => $ videoData[ self :: THUMBNAIL_MEDIUM ] ,
52
- self ::THUMBNAIL_LARGE => $ videoData[ self :: THUMBNAIL_LARGE ] ,
46
+ self ::THUMBNAIL_SMALL => $ videoData-> thumbnail_url ,
47
+ self ::THUMBNAIL_MEDIUM => $ videoData-> thumbnail_url ,
48
+ self ::THUMBNAIL_LARGE => $ videoData-> thumbnail_url ,
53
49
));
54
50
55
- $ this ->setTitle ($ videoData[ ' title ' ] );
56
- $ this ->setDescription ($ videoData[ ' description ' ] );
51
+ $ this ->setTitle ($ videoData-> title );
52
+ $ this ->setDescription ($ videoData-> description );
57
53
58
54
return parent ::__construct ($ url , $ pattern , $ renderer );
59
55
}
@@ -227,21 +223,6 @@ public function isEmbeddable()
227
223
return true ;
228
224
}
229
225
230
- /**
231
- * @param string $url
232
- * @param string $pattern
233
- *
234
- * @return int
235
- */
236
- private function getVideoIdByPattern ($ url , $ pattern )
237
- {
238
- $ match = array ();
239
- preg_match ($ pattern , $ url , $ match );
240
- $ videoId = $ match [2 ];
241
-
242
- return $ videoId ;
243
- }
244
-
245
226
/**
246
227
* Uses the Vimeo video API to get video info.
247
228
*
@@ -251,17 +232,16 @@ private function getVideoIdByPattern($url, $pattern)
251
232
*
252
233
* @throws ServiceApiNotAvailable
253
234
*/
254
- private function getVideoDataFromServiceApi ()
235
+ private function getVideoDataFromServiceApi ($ url )
255
236
{
256
- $ contents = file_get_contents ('http ://vimeo.com/api/v2/video/ ' . $ this -> getVideoId () . ' .php ' );
237
+ $ contents = file_get_contents ('https ://vimeo.com/api/oembed.json?url= ' . urlencode ( $ url ) );
257
238
if (false === $ contents ) {
258
239
throw new ServiceApiNotAvailable (
259
240
'Service "%s" could not reach it \'s API. Check if file_get_contents() function is available. ' ,
260
241
$ this ->getServiceName ()
261
242
);
262
243
}
263
- $ hash = unserialize ($ contents );
264
244
265
- return reset ( $ hash );
245
+ return json_decode ( $ contents );
266
246
}
267
247
}
0 commit comments