Skip to content

Instantly share code, notes, and snippets.

@moxet
Last active November 23, 2015 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moxet/f95781ab6cd712a2d9df to your computer and use it in GitHub Desktop.
Save moxet/f95781ab6cd712a2d9df to your computer and use it in GitHub Desktop.
The snippet is used to fetch thumbnail of a facebook video from any type of URL format.
function get_thumb($url)
{
$url = trim($url);
if(substr($url, -1)=="/")
{
$url = substr($url, 0, -1);
}
$urls = [$url];
$ids = [];
foreach ($urls as $url)
{
$tmp = explode('/', $url);
if (strtolower($tmp[count($tmp) - 2] == 'videos')) {
$ids[$url] = $tmp[count($tmp) - 1];
continue;
}
parse_str(parse_url($url)['query'], $query);
if (!empty($query['v']))
{
$ids[$url] = $query['v'];
}
if(substr($url, -1)=="r"){
$ids[$url] = $tmp[6];
}
if(substr($url, -1)=="y"){
$ids[$url] = $tmp[5];
}
if(substr($tmp["3"], 0, 1)=="v"){
$matches = array();
$t = preg_match('/=(.*?)\&/s', $tmp["3"], $matches);
$ids[$url] = $matches[1];
}
if(strpos($tmp[3], "video") !== false & substr($tmp[3], -1)!="r")
{
$ids[$url] = str_replace("video.php?v=", "", $tmp[3]);
}
}
$imgurl = $ids[$url];
echo "https://graph.facebook.com/$imgurl/picture/";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment