Example #1
0
 /**
  * Get the video id of the post.
  * 
  * @return string
  */
 public function getVideoIdAttribute()
 {
     switch ($this->videoType) {
         case self::VIDEO_TYPE_DAILYMOTION:
             return getDailyMotionId($this->media);
             break;
         case self::VIDEO_TYPE_VIMEO:
             return getVimeoId($this->media);
             break;
         case self::VIDEO_TYPE_YOUTUBE:
             return getYoutubeId($this->media);
             break;
         default:
             throw new \Exception("This posts video type is not valid.");
             break;
     }
 }
/**
 * Returns the html code for an embed responsive video, for a given url.
 * The url has to be either from:
 * - youtube
 * - daily motion
 * - vimeo
 *
 * Returns false in case of failure
 */
function getEmbedVideo($url)
{
    $code = <<<EEE
    <style>
        .embed-container { 
            position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; 
        }
        .embed-container iframe, .embed-container object, .embed-container embed { 
            position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
        }
    </style>
EEE;
    if (false !== ($id = getDailyMotionId($url))) {
        $code .= <<<EEE
<div class='embed-container'><iframe src='http://www.dailymotion.com/embed/video/{$id}' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
EEE;
    } elseif (false !== ($id = getVimeoId($url))) {
        $code .= <<<EEE
<div class='embed-container'><iframe src='http://player.vimeo.com/video/{$id}' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
EEE;
    } elseif (false !== ($id = getYoutubeId($url))) {
        $code .= <<<EEE
<div class='embed-container'><iframe src='http://www.youtube.com/embed/{$id}' frameborder='0' allowfullscreen></iframe></div>
EEE;
    } else {
        $code = false;
    }
    return $code;
}
$dailymotion = ['http://www.dailymotion.com/video/x2jvvep_coup-incroyable-pendant-un-match-de-ping-pong_tv', 'http://www.dailymotion.com/video/x2jvvep_rates-of-exchange-like-a-renegade_music', 'http://www.dailymotion.com/video/x2jvvep', 'http://www.dailymotion.com/hub/x2jvvep_Galatasaray', 'http://www.dailymotion.com/hub/x2jvvep_Galatasaray#video=x2jvvep', 'http://www.dailymotion.com/video/x2jvvep_hakan-yukur-klip_sport', 'http://dai.ly/x2jvvep'];
echo '<h1>Ids</h1>';
foreach ($vimeo as $url) {
    a(getVimeoId($url));
}
echo '<hr>';
foreach ($vimeoInvalid as $url) {
    a(getVimeoId($url));
}
echo '<hr>';
foreach ($youtube as $url) {
    a(getYoutubeId($url));
}
echo '<hr>';
foreach ($dailymotion as $url) {
    a(getDailyMotionId($url));
}
echo '<hr>';
echo '<h1>Thumbnails</h1>';
$mixed = array_merge($vimeo, $youtube, $dailymotion);
foreach ($mixed as $url) {
    $thumb = getVideoThumbnailByUrl($url);
    if (false !== $thumb) {
        echo '<img src="' . $thumb . '" />';
    } else {
        echo 'not found';
    }
    echo '<br>';
    echo getVideoLocation($url);
    echo '<br>';
}
Example #4
0
/**
* Returns the location of the actual video for a given url which belongs to either:
*
*      - youtube
*      - daily motion
*      - vimeo
*
* Or returns false in case of failure.
* This function can be used for creating video sitemaps.
*/
function getVideoLocation($url)
{
    if (false !== ($id = getDailyMotionId($url))) {
        return 'http://www.dailymotion.com/embed/video/' . $id;
    } elseif (false !== ($id = getVimeoId($url))) {
        return 'http://player.vimeo.com/video/' . $id;
    } elseif (false !== ($id = getYoutubeId($url))) {
        return 'http://www.youtube.com/embed/' . $id;
    }
    return false;
}