Since the video sharing phenomenon began, many web developers struggle with the problem of embeding the videos without knowing anything but the url where the video page is. Many users didn’t know anything about embed code, how to put videos on their blog or other tehnical stuff like that, so developers tried to find ways of getting the video embed code from url.
The solution was to parse the html of that page, to look for the <embed> tag. However this solution was not very reliable, because any change to the html of the video website, would mess the parsing, making this method to not work anymore.
Fortunetlly, recently, a new format appear: oembed . There are a number of video sharing sites already implementing this service like:
- youtube.com
- dailymotion.com
- vimeo.com
- blip.tv
- hulu.com
- viddler.com
- revision3.com
- qik.com
- scribd.com
- wordpress.tv
- tare.ro
additionally oohembed attempt to offer this functionality for other sites.
So, with this script, we can transform the url that user enters in the text box, into a nice little embed code to put in our site:
<?php $oembedUrls = array ( 'www.youtube.com' => 'http://www.youtube.com/oembed?url=$1&format=json', 'www.dailymotion.com' => 'http://www.dailymotion.com/api/oembed?url=$1&format=json', 'www.vimeo.com' => 'http://vimeo.com/api/oembed.xml?url=$1&format=json', 'www.blip.tv' => 'http://blip.tv/oembed/?url=$1&format=json', 'www.hulu.com' => 'http://www.hulu.com/api/oembed?url=$1&format=json', 'www.viddler.com' => 'http://lab.viddler.com/services/oembed/?url=$1&format=json', 'www.qik.com' => 'http://qik.com/api/oembed?url=$1&format=json', 'www.revision3.com' => 'http://revision3.com/api/oembed/?url=$1&format=json', 'www.scribd.com' => 'http://www.scribd.com/services/oembed?url=$1&format=json', 'www.wordpress.tv' => 'http://wordpress.tv/oembed/?url=$1&format=json', 'www.5min.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.collegehumor.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.thedailyshow.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.funnyordie.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.livejournal.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.metacafe.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.xkcd.com' => 'http://www.oohembed.com/oohembed/?url=$1', 'www.yfrog.com' => 'http://www.oohembed.com/oohembed/?url=$1' ); ?> <html> <head> </head> <body> <form name="oembed_form" action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input type="text" name="url" value="<?=$_POST['url']?>" size="50"> <input type="submit" name="Show" value="Show Video"> </form> <? if (!empty($_POST['url'])){ $parts = parse_url($_POST['url']); $host = $parts['host']; if (empty($host) || !array_key_exists($host,$oembedUrls)){ echo 'Unrecognized host'; } else { $oembedContents = @file_get_contents(str_replace('$1',$_POST['url'],$oembedUrls[$host])); $oembedData = @json_decode($oembedContents); $embedCode = $oembedData->html; echo "Embed code for <a href='".$_POST['url']."' target='_blank'>".$_POST['url']."</a> :<br>".$embedCode; } } ?>
If you want you can test the script here
No related posts.
Amazing!!! Bookmarked this web page that has this remarkable solutions. Will appear back again to see if there are any updates. You, the creator, are a grasp. Thank you
I don’t say this often… But I love you! I was trying to do something for the hulu videos and never worked. Thank you!
Hi, thanks for this quite easy and fast solution. Do you have any solution to pass an autoplay to TRUE in the code ?
Also, vimeo links don’t work for me with this process !
great work..
can you help me to do the same thing but to get the video thumbnail
i need something to get (youtube & metacafe &..)videos thumbnail
i trying use this ..but didn’t work well ..
<?
// we make a function, so it will easy to applicate
function getinput($url)
{
$regexp= "http:\/\/www\.youtube\.com\/watch\?v=(.*)(.*)";
if(preg_match_all("/$regexp/siu", $url, $matches))
return $matches[1][0];
}
// Catch Youtube Thumbnail Image from IRON MAN 2 UPDATE MOVIE
$youtube_url = “http://www.youtube.com/watch?v=1TiYlG21VAQ”;
$thumbnail_of_youtube = getinput($youtube_url);
// The thumbnail image of Youtube always has a pattern like this : http://i1.ytimg.com/vi/[videoid]/default.jpg
echo ‘‘;
?>
so can any one help me please ..
I’m gone to inform my little brother, that he should also visit this website on regular basis to take updated from most recent information.
magnificent submit, very informative. I wonder why the other specialists of this sector
do not understand this. You must continue your writing. I am confident, you have a great readers’ base already!
What’s up, of course this article is actually pleasant and I have learned lot of things from it on the topic of blogging. thanks.
svozmqiq.dpef/ofu, Cialis no prescription, gostcwc.
iwocfqiq.dpef/ofu, Semenax side, TngLjDb, Free multiplayer online blackjack, vysJpka, Play online blackjack for money, zGBMSlV, Vimax vs vigrx, EBUOtvb, Tramadol and ambien, twkEpps, Volume pills review, GJJpxMq.
ysamrqiq.dpef/ofu, Semenax, WRHJnOK, Buy viagra onli, UZAUbiy, Low blood sugar ambien withdrawal, VrDMRHO, Raspberry ketone, mZXmwGS, Sbi india forex rates, brhDyoi, Phen375 webmd, hNgNLYC.
lchdkqiq.dpef/ofu, Buy viagra in canada, LqzqANM.
qxqdzqiq.dpef/ofu, Ioption, apRXOkA.
My coder is trying to persuade me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using WordPress on several websites for about a year and am
concerned about switching to another platform. I have heard very good things about blogengine.
net. Is there a way I can import all my wordpress posts into it?
Any kind of help would be really appreciated!
rflwjqiq.dpef, Cialis soft tabs half, uzGfuGs.
Can I just say what a comfort to discover somebody who truly understands what they
are discussing on the web. You definitely understand how to bring a problem to light and make it important.
A lot more people have to read this and understand this
side of your story. It’s surprising you aren’t more popular since you certainly possess the gift.
jusngqiq.dpef, Where to buy dapoxetine, gSoHSCW.
jvygtqiq.dpef, Phen375 customer reviews best weight loss supplements t, cGxdIjp, Garcinia Cambogia For Weight Loss, LnsupWd, Semenax Australia, SQMqejt, Cialis comparison, RbskXlN, Hersolution Gel, GiDtPZH, How long can sildenafil citrate be stored, fbmFPaM.
Hi, I think your blog might be having browser compatibility issues.
When I look at your website in Opera, it looks fine but when opening in Internet Explorer, it
has some overlapping. I just wanted to give you a
quick heads up! Other then that, great blog!
cegaoqiq.dpef, Spela Casino, izYxLKb.
Just desire to say your article is as astounding. The clearness for your submit is just spectacular and
that i can assume you are an expert on this subject.
Well with your permission allow me to grab your feed to stay updated with drawing close
post. Thanks 1,000,000 and please keep up the enjoyable work.
zqpqyqiq.dpef, Buying levitra in mexico, RZimfRJ, Volumepills work, LygzBXH, Casino virtuel en ligne, TiZIIja, Lucky club online casino, ybWTPya, Electronic cigarette safety, renKWfJ, Where can i buy tadalafil, Hmxtkbt.
Hi my friend! I want to say that this article is
awesome, great written and include approximately all significant
infos. I would like to look extra posts like this .
This is a topic which is near to my heart.
.. Take care! Exactly where are your contact details though?
Feel free to surf to my blog post; how to grow taller at 18 female
Hello! I could have sworn I’ve visited this website before but after going through a few of the articles I realized it’s new to me.
Nonetheless, I’m definitely delighted I came across it and I’ll be bookmarking it and checking back often!
qxcocqiq.dpef/ofu, Stendra, DCtbhEz, [url=http://stendratreatment.com/]When stendra will be available[/url], MLUjGhN, http://stendratreatment.com/ When stendra will be available, TFmFTqt.
hello! , Nice creating really a great deal of! percentage many of us keep in contact excess around your document about America online? I would like a specialist about this space or room to fix the issue. Possibly that’s a person! Looking forward to look a person.
I was recommended this website by my cousin.
I am not sure whether this post is written by him as nobody else know such
detailed about my difficulty. You’re wonderful! Thanks!
my site; vacuum cleaner quest wonderland online
http://www.sharkindo.com/Polo Ralph Lauren Outlet Online
http://www.moonlightcarriagecompany.com/Sac Vanessa Bruno
Hey there! I’ve been following your weblog for some time now and finally got the courage to go ahead and give you a shout out from Huffman Texas! Just wanted to tell you keep up the fantastic work!
Do you have a spam problem on this blog; I also am a blogger, and
I was curious about your situation; many of us have developed some nice procedures and we are
looking to swap methods with others, why not shoot me an email
if interested.