oohEmbed.com web service, which acts as an API for grabbing information from various media websites. When I say media, I’m referring to YouTube videos, Flickr images, and things like Amazon products. I was on the hunt to give my users from an automotive website the ability to add videos to their comments without having to make things complex. Everyone knows it’s easy to mess up an embed code and have this hodgepodge of code in someone’s comment or post. oohEmbed solves this by using oEmbed and the API from various media giants who have made it possible to easily access their information.

How do you call this information? Through the oohEmbed.com URL schema. Tack on your media URL to the end of the oohembed.com URL:

http://oohembed.com/oohembed/?url=http%3A//www.amazon.com/Myths-Innovation-Scott-Berkun/dp/0596527055/

Here is the kind of raw information oohEmbed outputs:

{
“type”: “photo”,
“version”: “1.0″,
“provider_name”: “Amazon Product Image”,
“url”: “http://ecx.images-amazon.com/images/I/31%2BfVjL2nqL.jpg”,
“height”: “500″,
“width”: “317″,
“thumbnail_url”: “http://ecx.images-amazon.com/images/I/31%2BfVjL2nqL._SL75_.jpg”,
“thumbnail_height”: “75″,
“thumbnail_width”: “48″,
“asin”: “0596527055″,
“title”: “The Myths of Innovation”,
“author_name”: “Scott Berkun”,
“author_url”: “http://www.amazon.com/gp/redirect.html%3FASIN=0596527055%26location=/Myths-Innovation-Scott-Berkun/dp/0596527055″
}

Here is my simple and quick PHP method for accessing oohEmbed and making use of their API structure (with a few comments to explain whats going on):

//Simple function to get the contents from the oohEmbed API.
function oohembedURL($u){
return @file_get_contents(’http://oohembed.com/oohembed/?url=’.$u);
}

//$content is whatever you get your content from. WordPress/Joomla/Drupal, however you can process the raw content before it is visually shown. For WordPress you use $get_the_content();.

$content = $get_the_content();

//Check my $content variable for any type of url
preg_match_all(’>http://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?>’, $content, $matches);
//Grabs the first URL in the content. If there were more than one you do this part differently to process them all, but we’re just focusing on one.
$url = $matches[0][0];

//Run the $url through the oohembedURL function
$ooh = oohembedURL($url);

//if $ooh is empty then we leave the $content variable alone. This is caused by a 404 error from oohEmbed.com when an invalid url is run through the service.
if( !$ooh ){
$newContent = $content;
} else { //else we break up the content and find what in my case is the video embed code.
//explode the API return
$explode = explode(’,', $ooh);

foreach ($explode as $phrase){
//if the $phrase includes “html”: ” then set it to the $embed variable.
if (strstr($phrase, ‘”html”: “‘)) $embed = $phrase;
if(isset($embed)) break;
}

foreach ($explode as $phrase){
//if the $phrase includes “html”:”(there are slightly different embed returns based on what service it comes from) then set it to the $embed2 variable.
if (strstr($phrase, ‘”html”:”‘)) $embed2 = $phrase;
if(isset($embed2)) break;
}

//if no $embed2 variable input the embedding code into the $content
if( !$embed2 ){
//remove the “html”: ” from the string.
$embed = str_replace(’”html”: “‘, ”, $embed);

//trim off the quote from the right side of the string
$embed = rtrim($embed, ‘”‘);

//replace the video url for the new embedded code.
$newContent = str_replace($url, $embed, $content);
}else{ //else if $embed2 exists use this process
//Remove the “html”:” from the string.
$embed2 = str_replace(’”html”:”‘, ”, $embed2);

//Removed the ending quote from the string.
$embed2 = rtrim($embed2, ‘”‘);

//Replace the link in the $content with the new embedding code.
$newContent = str_replace($url, $embed2, $content);
}
//Remove any extra slashes, if any.
$newContent = stripslashes($newContent);
}

oohEmbed caters to a healthy list of media sites. For a full list, visit their website under the ‘configuration’ heading. So far, the service has been flawless. I have not put it through any excessive traffic loads, but I’m sure it can handle it, as the app is hosted through Google App Engine. My only qualm so far with the service is the minor inconsistency I have experienced in the format in which the API information is returned. Otherwise, this is an excellent addition to any website and adds more functionality for the users.