Check If Youtube and Vimeo-Clips Are Valid

Check if Youtube and Vimeo-clips are valid

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

How to recognize youtube or vimeo site by url?

I think that you are using embed field. If yes, then embed will automatically validate for the proper youtube or video(you have to check for the sites on the configuration page) url. If No, then Pinetree has explained it properly, So use that.

Improving regex for parsing YouTube / Vimeo URLs

I am not sure about your question 3), but provided that your induction on the url forms is correct, the regexes can be combined into one as follows:

/http:\/\/(?:www.)?(?:(vimeo).com\/(.*)|(youtube).com\/watch\?v=(.*?)&)/

You will get the match under different positions (1st and 2nd matches if vimeo, 3rd and 4th matches if youtube), so you just need to handle that.

Or, if you are quite sure that vimeo's id only includes numbers, then you can do:

/http:\/\/(?:www.)?(vimeo|youtube).com\/(?:watch\?v=)?(.*?)(?:\z|&)/

and the provider and the id will apprear under 1st and 2nd match, respcetively.

PHP: How to check whether the URL is Youtube's or vimeo's

As others have noted in the comments, this is a quick and dirty solution that does not handle edge cases well. If the url contains "youtube"(example.com/youtube) it will return a false positive. The parse_url() solution mentioned below is a much more robust solution.


Regular expressions work well for this type of thing, but often strpos or substr are faster performance wise. Check out the PHP documentation for preg_match(). Below the examples there is a note for exactly this thing.

Here is prototype code:

function videoType($url) {
if (strpos($url, 'youtube') > 0) {
return 'youtube';
} elseif (strpos($url, 'vimeo') > 0) {
return 'vimeo';
} else {
return 'unknown';
}
}

Obviously returning a string isn't the best idea, but you get the point. Substitute your own business logic.

how to check the valid Youtube url using jquery

Typically, the thing that most people want is the youtube video ID. To simply match this, use the following regex.

var matches = _videoUrl.match(/watch\?v=([a-zA-Z0-9\-_]+)/);
if (matches)
{
alert('valid');
}

Naturally, the regex could be expanded to include the entire youtube url, but if all you need is the ID, this is the most surefire way I've found.



Related Topics



Leave a reply



Submit