Page 1 of 1

video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 9:45 pm
by bluefairy
how to create a video downloader using php?

Re: video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 10:08 pm
by Jonah Bron
Care to enlarge on that?

Re: video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 10:22 pm
by bluefairy
our project is a video downloader

it's like getting the url of the video from youtube and click button to download the file.

any idea on how to download a video using php script?

we badly need it.tnx :)

Re: video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 10:33 pm
by Jonah Bron
There is a URL on Youtube that gives you the raw file, but you need the ID of the video, and a special key that is given every time the page is loaded. Use file_get_contents() to get the page, and then extract ID and the key, then put those on the special URL. I think the URL is http://www.youtube.com/get_video?video_id=[video id here]&t=[special key here].

If you look at the source of this userscript you can probably figure out how to extract both of those values.

http://1024k.de/bookmarklets/scripts/vi ... be.user.js

I probably shouldn't ask this, but what's wrong with the other 23,920,438,002 Youtube videos already out there?

Re: video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 10:45 pm
by bluefairy
tnx for the info..
i'll try it..

actually our project is an application for facebook
which is a video downloader that can download videos from facebook and youtube

is it also the same on Facebook? like getting the url and those special key?

Re: video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 10:58 pm
by Jonah Bron
It should be; I don't know what language you use to make Facebook apps.

Re: video downloader using PHP - HOW?

Posted: Fri Sep 17, 2010 11:15 pm
by bluefairy
uhh.,i'm really worried.. :cry:

i will just use php for both..i hope i can make it..
tnx again..God bless you

Re: video downloader using PHP - HOW?

Posted: Sat Sep 18, 2010 1:14 am
by moeenakhtar
i worked on facebook app nd used to built these app in php!!!
u will not be getting any prob

Re: video downloader using PHP - HOW?

Posted: Mon Sep 20, 2010 7:02 am
by bluefairy
ohh really??can u give me the php?just for our project :(
tnx a lot

Re: video downloader using PHP - HOW?

Posted: Mon Sep 20, 2010 7:06 am
by bluefairy
how can you download the video from facebook using the url?
can u give me a hint?

Re: video downloader using PHP - HOW?

Posted: Tue Sep 21, 2010 4:23 am
by bluefairy
@jonah: what do you mean by the special key? where can i find that key on youtube??

Re: video downloader using PHP - HOW?

Posted: Tue Sep 21, 2010 2:17 pm
by Jonah Bron
Did you look at the userscript I linked to?

Code: Select all

scriptmedia=document.getElementsByTagName('script');
      for(i=0;i<scriptmedia.length;++i)
       {
        source=scriptmedia[i].text.match(/"video_id": "\S+".+"t": "\S+"/i);
It shows right there how to extract the ID and the key. Loop through all script elements and look for that regex. It contains the ID and the key.

Re: video downloader using PHP - HOW?

Posted: Wed Sep 29, 2010 8:30 pm
by bluefairy
@ jonah: i can't figure out where you get the variables 1 & 2?

source=String(source).replace(/"video_id": "(\S+)".+"t": "(\S+)"/i,'http:\/\/www.youtube.com\/get_video?video_id=$1&t=$2');

Re: video downloader using PHP - HOW?

Posted: Wed Sep 29, 2010 11:12 pm
by Jonah Bron
That's Javascript, not PHP. Variables don't start with $ in Javascript. Those are backward shortcuts for the regex replacement. $0 gives you the entire match, $1 gives you the contents of the first parentheses set, $2 gives you the contents of the second parentheses set, and so on and so forth.

Read this for more info:
http://www.regular-expressions.info/refreplace.html