Mild Fuzz
Mild Fuzz

Reputation: 30741

How can I check to see if a Vimeo video exists?

Currently, I have a function that builds a vimeo player based on a vimeo ID

function create_video_player_by_ID($video_id){
    $player = '<iframe src="http://player.vimeo.com/video/';
    $player .= $video_id.'" ';
    $player .= 'width="'.$this->width.'" ';
    $player .= 'height="'.$this->height.'" ';
    $player .=  'frameborder="0"></iframe>';



    return $player;
}

Currently, I get a vimeo appology in the player window is the ID is invalid, but I would like to do more with that. How can I get a boolean to return before the video player, so I can do something else an failure?

Upvotes: 2

Views: 5026

Answers (4)

Pawan Verma
Pawan Verma

Reputation: 1279

In the documentation, it clearly mentioned that how can we get a video from Vimeo. You need to hit an URL with video id if the video exit then the response code is 200 otherwise if video does not exist then it will give 404 response. See here

https://developer.vimeo.com/api/reference/videos#get_video

Upvotes: 0

Rodgath
Rodgath

Reputation: 575

You can use the HEAD request method using the video URL.

function check_remote_video_exists($video_url) {

    $headers = @get_headers($video_url);

    return (strpos($headers[0], '200') > 0) ? true : false;
}

Check your vimeo URL like so:

if (check_remote_video_exists('YOUR_VIMEO_VIDEO_URL')) {

    // video exists, do stuff

} else {

    // video does not exist, do other stuff

}

Hope this helps someone.

Upvotes: 1

Brad Dougherty
Brad Dougherty

Reputation: 920

For embedding purposes, the best approach would be to make a call to oEmbed with the video url. It will return a non-200 code if the video cannot be embedded.

Vimeo oEmbed docs

Upvotes: 0

Anon
Anon

Reputation: 1330

Try doing a HEAD request on the src URL to make sure it returns status 200 instead of 404.

You can also use the video API to get information about an idea. See their docs.

Upvotes: 0

Related Questions