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
Contents
Facebook Style YouTube Video
Facebook Style Vimeo Video
Facebook Style SoundCloud Audio
Features
- YouTube Video
- Vimeo Video
- SoundCloud Audio
- Metacafe Video
- DailyMotion Video
Requirements
- jQuery
- SoundCloud Javascript SDK
- PHP 5+
- 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("http://youtu.be/lvOFck4dn_8");
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("http://vimeo.com/65484727");
Please see the 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!
I have subscribed where is the download link?
Hi Sumiti,
Sorry for being late..
please download it from here – https://www.box.com/s/iuzfp9jve3nfeioq78q4
Thanks
But I am unable to download the file.Can you mail me
How can I download this code?
Kindly update the database. It’s more than 24 hours and still it says, email not found in the database.
Give me download link, please.
Give me download link, please.
Great script Thanks
Wonder full script.. but there is no download link please help me.
Great
Thank you
asdas asd assaasd asd
This its just what i need. I cant download anything. Im in the subscriber mail list but i cant download.
Thanks
the script is wnat i needed, please provide the download link , karthik
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.
Hi Rich,
Sorry for being late.. please download it now.. I have updated the subscribers database
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
Hi,
please download it now.. sorry for being late
Thanks
Thanks Karthikeyan for your response and sharing the code . I am able to download it . God bless you .
thanks
great
Thanks Jaimin 🙂
I can’t download code
great!
Thanks Rami 🙂
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.:(
Email does not exist in our database. Please use below form to subscribe
iam subcribed but does n’t allowed download script why
hi karthik,i want face book like extract youtube url,image url,title and description same face book update status model
really nice article
Hi its been more than 10 hours.. I have subscribed but I still can not download the code. Please help!
please download
I cant download the script. it says email doesnt exist in database..help
I cant download the script. it says email doesnt exist in database..help
Molto interessante mi piacerebbe inserirlo nel mio sito come fare per il dwnload?
great stuff
really good! awesome…. shall i give it a try?
Yes Inshaf Sabar… 🙂
is it possible to get the full script ?
Yes Inshaf.. you can download it from here – http://w3lessons.info/demo/facebook-style-url-expander
Thanks
i couldnt… it says “Email does not exist in our database. Please use below form to subscribe”
is it possible to get the full script ?
Yes Inshaf.. you can download it from here – http://w3lessons.info/demo/facebook-style-url-expander
Thanks
Good. Can I create a function to delete the video? if yes, how can I do this?
Good, I m trying, how can I remove the video in this function?
Good !
the download not work
Awesome! I am gonna use it.
Hi ,Great Job
How can I download the code.
thanks!! great job
good job
awesome dude!
thanks!!! great job for community
Hi Can’t download from that link
Hi.. visit this link & enter your email to download – http://w3lessons.info/demo/facebook-style-url-expander
thanks
thanks
Thanks !
call me Karthikeyan K my no 9705107337 i want codes
Hi madhu,
You can download the code from here – http://w3lessons.info/demo/facebook-style-url-expander
Thanks
nice
cool
hi. this script is really cool. can i have a link to download it. thanks
Hi Aldrin,
You can download this script from here – http://w3lessons.info/demo/facebook-style-url-expander
Thanks
Thank you, Karthikeyan, this article is really useful. It might come in handy for my next project.
Thank you very much…
Download script will be ready in next few hours 🙂 please stay in touch
Awesome. I really like your work. Keep it up 😉
please icant download it can you send me dircet link to it
send the code to me