Facebook Style Youtube, Vimeo, Metacafe, Dailymotion Videos & Soundcloud Audio Url Expander with jQuery & PHP

Last modified on by Karthikeyan K

Today I am going to share  facebook style url expanding videos using jQuery & PHP. This script will take Youtube, Vimeo, SoundCloud, Metacafe, & Dailymotion video url as input and it will return a video as output with automatically fetch the title & description of the respective video.

In my previous post, I had explained how to expand youtube video in facebook style. But here I have done embedding Youtube, Vimeo, Soundcloud, Metacafe & Dailymotion videos/audios using permalinks

Facebook Style Vimeo, Youtube & SoundCloud Url Expander

Facebook Style Vimeo, Youtube & SoundCloud Url Expander

Facebook Style YouTube Video

Facebook Style Youtube Video Expander

Facebook Style Youtube Video Expander

Facebook Style Vimeo Video

Facebook Style Vimeo Video  Expander

Facebook Style Vimeo Video Expander

Facebook Style SoundCloud Audio

Facebook Style SoundCloud Audio Expander

Facebook Style SoundCloud Audio Expander

Features

  1. YouTube Video
  2. Vimeo Video
  3. SoundCloud Audio
  4. Metacafe Video
  5. DailyMotion Video

Requirements

  1. jQuery
  2. SoundCloud Javascript SDK
  3. PHP 5+
  4. CURL Support – used to fetch title & description of the video & also used to get soundcloud audio file

jQuery Code to Expand YouTube Video

jQuery("a.youtube").live("click", function(){
var videoURL = jQuery(this).attr("href");
var regExp_YT = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var youtubeurl = videoURL.match(regExp_YT);
var videoID = youtubeurl[7];
var videoWidth = parseInt(jQuery(this).parent().parent().css("width"));
var videoHeight = Math.ceil(videoWidth*(0.56)+1);
jQuery(this).parent().hide();
jQuery(this).parent().next().css('margin-left', '0');
jQuery(this).parent().parent().prepend('<iframe width="'+videoWidth+'" height="'+videoHeight+'" src="http://www.youtube.com/embed/'+(videoID)+'?rel=0&autoplay=0" frameborder="0" allowfullscreen></iframe>');
return false;
});

jQuery Code to Expand Vimeo Video

jQuery("a.vimeo").live("click", function(){
var videoURL = jQuery(this).attr("href");
var regExp_VMO = /^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/;
var vimeourl = regExp_VMO.exec(videoURL);
var videoID = vimeourl[5];
var videoWidth = parseInt(jQuery(this).parent().parent().css("width"));
var videoHeight = Math.ceil(videoWidth*(0.56)+1);
jQuery(this).parent().hide();
jQuery(this).parent().next().css('margin-left', '0');
jQuery(this).parent().parent().prepend('<iframe src="http://player.vimeo.com/video/'+videoID+'?portrait=0" width="'+videoWidth+'" height="'+videoHeight+'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>');
return false;
});

jQuery Code to Expand SoundCloud Audio

jQuery("a.soundcloud").live("click", function(){
var scURL = jQuery(this).attr("href");
var obj = jQuery(this);
obj.parent().hide();
obj.parent().next().css('margin-left', '0');
jQuery(this).parent().parent().prepend('<div id="sc_audio"></div>');
SC.oEmbed(scURL, {color: "ff0066"}, document.getElementById("sc_audio"));
return false;
});

PHP Function to get YouTube Thumbnail by Url

function get_youtube_thumbnail($url)
{
$parse = parse_url($url);
if(!empty($parse['query'])) {
preg_match("/v=([^&]+)/i", $url, $matches);
$id = $matches[1];
} else {
//to get basename
$info = pathinfo($url);
$id = $info['basename'];
}
$img = "http://img.youtube.com/vi/$id/1.jpg";
return $img;
}
//usuage
echo get_youtube_thumbnail(&quot;http://youtu.be/lvOFck4dn_8&quot;);

PHP Function to get Viemo Thumbnail by Url

//function is used to get vimeo link ID
function parse_vimeo($link)
{
$regexstr = '~
# Match Vimeo link and embed code
(?:<iframe [^>]*src=")? # If iframe match up to first quote of src
(?: # Group vimeo url
https?:\/\/ # Either http or https
(?:[\w]+\.)* # Optional subdomains
vimeo\.com # Match vimeo.com
(?:[\/\w]*\/videos?)? # Optional video sub directory this handles groups links also
\/ # Slash before Id
([0-9]+) # $1: VIDEO_ID is numeric
[^\s]* # Not a space
) # End group
"? # Match end quote if part of src
(?:[^>]*></iframe>)? # Match the end of the iframe
(?:<p>.*</p>)? # Match any title information stuff
~ix';

preg_match($regexstr, $link, $matches);
return $matches[1];
}

function get_vimeo_thumbnail($url)
{
$id = parse_vimeo($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = unserialize(curl_exec($ch));
$output = $output[0]['thumbnail_medium'];
curl_close($ch);
return $output;
}
//usage
echo get_vimeo_thumbnail(&quot;http://vimeo.com/65484727&quot;);

Please see the live demo

View Live Demo

Please comment your thoughts about this script. So that I will make this script available to download 🙂

Please don’t forget to share and subscribe to latest updates of the blog. Also any comments and feedback are all welcome!

Thanks!

You May Also Like

68 Responses

  1. naveen says:

    send the code to me

  2. Slaviša Perišić says:

    Thank you, Karthikeyan, this article is really useful. It might come in handy for my next project.

  3. Aldrin Aquino Brion says:

    hi. this script is really cool. can i have a link to download it. thanks

  4. madhu says:

    call me Karthikeyan K my no 9705107337 i want codes

  5. Karthiga says:

    Hi Can’t download from that link

  6. jose carlos campos says:

    thanks!!! great job for community

  7. drashan says:

    awesome dude!

  8. santosh says:

    good job

  9. Eduardo says:

    thanks!! great job

  10. Jai says:

    Hi ,Great Job
    How can I download the code.

  11. Muhammad Sajid says:

    Awesome! I am gonna use it.

  12. Hamid Benhamid says:

    the download not work

  13. k32u4s8yp1 says:

    Good !

  14. Guest says:

    Good, I m trying, how can I remove the video in this function?

  15. Kelvin says:

    Good. Can I create a function to delete the video? if yes, how can I do this?

  16. inshaf sabar says:

    really good! awesome…. shall i give it a try?

  17. kamicase says:

    great stuff

  18. daniele says:

    Molto interessante mi piacerebbe inserirlo nel mio sito come fare per il dwnload?

  19. piodogs says:

    I cant download the script. it says email doesnt exist in database..help

  20. piodogs says:

    I cant download the script. it says email doesnt exist in database..help

  21. ricca1976 says:

    please download

  22. AG says:

    really nice article

  23. Sunkari Subbarayudu says:

    hi karthik,i want face book like extract youtube url,image url,title and description same face book update status model

  24. Sunkari Subbarayudu says:

    iam subcribed but does n’t allowed download script why

  25. Sunkari Subbarayudu says:

    Email does not exist in our database. Please use below form to subscribe

  26. Mohammad Afzal says:

    I have tried to download the code but the it throws validation that “Email does not exist in our database. Please use below form to subscribe” Please help me out.:(

  27. Rami Almaqssoud says:

    great!

  28. jadfaisal says:

    thanks

  29. Chaitu says:

    Thanks for this one . I subscribed to the email . But still I am not able to download after 20 hours .It says ”
    Email does not exist in our database. Please use below form to subscribe ” If I try to subscribe it says ” is already subscribed to the mailing list of W3lessons.info ” . Could you please check it and allow me to download it ?

    Thank You

  30. Rich says:

    I subscribed yesterday, but still cannot download scripts. Have responded to the email, but no luck so far. Can you please update your database? Thank you very much.

  31. Pasupathy says:

    the script is wnat i needed, please provide the download link , karthik

  32. Juan says:

    This its just what i need. I cant download anything. Im in the subscriber mail list but i cant download.
    Thanks

  33. cristian vargas acevedo says:

    asdas asd assaasd asd

  34. Bojan Antonijevic says:

    Thank you

  35. RatsCoder says:

    Great

  36. Bongo Choice says:

    Wonder full script.. but there is no download link please help me.

  37. Mragank Shekhar Soni says:

    Great script Thanks

  38. MarioDKR says:

    Give me download link, please.

  39. MarioDKR says:

    Give me download link, please.

  40. Viswalinga Surya S says:

    Kindly update the database. It’s more than 24 hours and still it says, email not found in the database.

  41. Manu Knight says:

    How can I download this code?

  42. Sumiti Monga says:

    I have subscribed where is the download link?

Leave a Reply

Your email address will not be published. Required fields are marked *