Created
June 28, 2016 14:48
-
-
Save pablo-sg-pacheco/f069d43c5307cd29bec961489f1456fd to your computer and use it in GitHub Desktop.
Class for get an image from a youtube video URL
This file contains hidden or 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
<?php | |
namespace OOPFunctions\Youtube; | |
if ( !class_exists('\OOPFunctions\Youtube\Youtube') ) { | |
/** | |
* Description of Youtube | |
* | |
* @author Pablo Pacheco <[email protected]> | |
*/ | |
class Youtube { | |
public static function getImageFromYoutubeUrl( $url,$size = '0' ) { | |
$id = self::getYoutubeVideoIdFromUrl($url); | |
$image = self::getImageFromYoutubeId($id,$size); | |
return $image; | |
} | |
public static function getImageFromYoutubeId( $id, $size = '0' ) { | |
return "http://img.youtube.com/vi/{$id}/{$size}.jpg"; | |
} | |
public static function getYoutubeVideoIdFromUrl( $url ) { | |
$queryString = parse_url($url, PHP_URL_QUERY); | |
parse_str($queryString, $params); | |
return $params['v']; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment