video downloader using PHP - HOW?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

video downloader using PHP - HOW?

Post by bluefairy »

how to create a video downloader using php?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: video downloader using PHP - HOW?

Post by Jonah Bron »

Care to enlarge on that?
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post 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 :)
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: video downloader using PHP - HOW?

Post 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?
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post 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?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: video downloader using PHP - HOW?

Post by Jonah Bron »

It should be; I don't know what language you use to make Facebook apps.
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post 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
moeenakhtar
Forum Newbie
Posts: 1
Joined: Mon Aug 16, 2010 12:03 am

Re: video downloader using PHP - HOW?

Post by moeenakhtar »

i worked on facebook app nd used to built these app in php!!!
u will not be getting any prob
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post by bluefairy »

ohh really??can u give me the php?just for our project :(
tnx a lot
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post by bluefairy »

how can you download the video from facebook using the url?
can u give me a hint?
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post by bluefairy »

@jonah: what do you mean by the special key? where can i find that key on youtube??
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: video downloader using PHP - HOW?

Post 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.
bluefairy
Forum Newbie
Posts: 9
Joined: Fri Sep 17, 2010 9:27 pm

Re: video downloader using PHP - HOW?

Post 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');
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: video downloader using PHP - HOW?

Post 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
Post Reply