Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Youtube and Vimeo-clips are valid

Tags:

url

php

I have been trying for quite a while to check if submitted links are valid film-clips from youtube.com or vimeo.com but I didn't succeed.

Any ideas how to check url's like:

http://www.youtube.com/watch?v=jc0rnCBCX2c&feature=fvhl (valid)
http://www.youtube.com/watch?v=jc0FFCBCX2c&feature=fvhl (not valid)
http://www.youtube.com/v/jc0rnCBCX2c (valid)
http://www.youtube.com/v/ddjcddddX2c (not valid)
http://www.vimeo.com/463l522 (not valid)
http://www.vimeo.com/1483909 (valid)
http://www.vimeo.com/lumiblue (not valid)
http://www.youtube.com/user/dd181921 (not valid)

?

I use php.

like image 395
Johan Avatar asked Sep 01 '09 12:09

Johan


2 Answers

If you check the response headers from a request to http://gdata.youtube.com/feeds/api/videos/videoId where videoId is the google video Identifier, you should get a 200 if the video exists and a 400 (bad request) if the video doesn't exist.

// PHP code

// Check if youtube video item exists by the existance of the the 200 response
$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $youtubeId);
if (!strpos($headers[0], '200')) {
    echo "The YouTube video you entered does not exist";
    return false;
}
like image 123
chrismacp Avatar answered Sep 29 '22 12:09

chrismacp


i see a answer in this site : www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23765374.html

and he said :

I would suggest using youtube's API since you are trying to validate if the video exists. or if you don't want to go into API stuff then you can do simple trick. check this link:

http://code.google.com/apis/youtube/developers_guide_php.html#RetrievingVideoEntry

to check for the existence of a video you will need to extract "v" value and send a request that contains the video id to :

http://gdata.youtube.com/feeds/api/videos/videoID

where videoID is the "v" value for example a video FLE2htv9oxc will be queried like this http://gdata.youtube.com/feeds/api/videos/FLE2htv9oxc if it does not exist then you will get a page with "Invalid id" if it exists, will return an XML feed having various info about the video. this way you can check that the video exists.

hope this will get you in the right direction.

the same thing with vimeo , try to look in api documentation in there site. http://www.vimeo.com/api

like image 31
Haim Evgi Avatar answered Sep 29 '22 12:09

Haim Evgi