Last active
October 7, 2019 13:08
-
-
Save stefanRepac/cff5b5cf557aa324f3dcd211cb22c9a2 to your computer and use it in GitHub Desktop.
Parse Vimeo or YouTube url to get ID. ACF and Get thumbnail from video using vimeo API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VIMEO | |
<?php | |
$url = get_field( 'full_video' ); | |
preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $match); | |
$vimeo_id = $match[3]; | |
$data = file_get_contents("http://vimeo.com/api/v2/video/$vimeo_id.json"); | |
$data = json_decode($data); | |
?> | |
<img src="<?php echo $data[0]->thumbnail_large; ?>"> | |
<iframe src="https://player.vimeo.com/video/<?php echo $vimeo_id; ?>?&loop=1&title=0&byline=0&portrait=0" style="position:absolute;top:0;left:0;width:100%;height:100%;" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> | |
// YOUTUBE | |
<?php $url = get_field( 'yuotube_url' ); | |
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); | |
$youtube_id = $match[1]; | |
?> | |
<img src="http://i3.ytimg.com/vi/<?php echo $youtube_id ?>/maxresdefault.jpg"> | |
<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $youtube_id ?>?rel=0&showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment