Skip to Content »

FlashApe » FLVFetcher - Directly download youtube and google flv’s into flash

 FLVFetcher - Directly download youtube and google flv’s into flash

  • August 16th, 2007
  • 5:54 pm

Here’s my take on downloading the flv’s directly from youtube and google to stream into flash. It’s made up of two parts - an AS 2 class called FLVFetcher and a php script.

As of right now, to get the path to the flv file you simply add and event listener for the ON_URL event, then all you need to do is pass the video id of the file you wish to load.

For youtube videos, its that is the value of the ‘v’ variable in a url like:
http://www.youtube.com/watch?v=Tkq2Kq-LmJg,

and for google video, its the value of the docid variable in a url like:
http://video.google.com/videoplay?docid=-988708193861222512.

FLVFetcher.fetchByID(id:String, videoType:String);

The class has two constants you can use for the video type, either FLVFetcher.YOU_TUBE or FLVFetcher.GOOGLE.

On the php side, it uses a custom HTTPRequest class to get around server configurations where remote file access is disabled.

You can check it out here and download a zip of the source here.

Some example code:

import com.f1fd.flv.FLVFetcher;
import com.f1fd.flv.FLVFetchEvent;

import mx.utils.Delegate;

// for google, you jsut need the 'docid' variable from the url
var googleID = "-4329042477720699378";

// for youtube vids, all you need is the 'v' variable
var youTubeID="J0TiFPynBgI";

var fetcher = FLVFetcher.getInstance();

this.onEnterFrame = function(){
	init();
	delete this.onEnterFrame;
}

function init(){

	FLVFetcher.PHP_PATH = 'get_video.php';

	fetcher.addEventListener(FLVFetchEvent.ON_URL, Delegate.create(this, onURL));
	fetcher.addEventListener(FLVFetchEvent.ON_ERROR, Delegate.create(this, onError));

	google_button.addEventListener ('click', Delegate.create(this, onGetGoogleClick));

	youtube_button.addEventListener ('click', Delegate.create(this, onGetYouTubeClick));
}

function onGetGoogleClick(){
	fetcher.fetchByID(googleID, FLVFetcher.GOOGLE)
}

// change second param to FLVFetcher.GOOGLE for google videos
function onGetYouTubeClick(){
	fetcher.fetchByID(youTubeID, FLVFetcher.YOU_TUBE)
}

function onURL(evt){
	message_txt.text = 'The URL is : '+newline+evt.data;

	my_vid.contentPath = evt.data;
}

function onError(evt){

}

27 People had this to say...

[…] pm I just updated FLVFetcher so that you can now pass it a full youtube or google video url using FLVFetcher.fetchByURL(url). […]

Gravatar
  • wonder
  • August 21st, 2007
  • 4:19 am

nice work.

i was wondering though :
Is this “legal” / “fair” ?

Can you use youtube /google video to host / stream videos for your own website this way ????
Feels like stealing somebody else’s bandwidth and not giving them the benefit of making a buck through advertising.

just wondering, you know.
I would definitely use this a lot if it would turn out to be ok.

Gravatar
  • rich
  • August 21st, 2007
  • 8:21 am

striclty speaking…no, so use at your own risk. A quick perusal of youtube’s TOS clearly states that you can’t access the contents directly:

C. You agree not to access User Submissions (defined below) or YouTube Content through any technology or means other than the video playback pages of the Website itself, the YouTube Embeddable Player, or other explicitly authorized means YouTube may designate.

However, this is obviously not the first time someone has done this…take neave.tv for example. So, i’m not breaking any new ground here, but it’s up to you if you want to use this or not.

Gravatar
  • Keven
  • August 31st, 2007
  • 7:08 am

Cool beans.

This might be a dumb question (I’m not AS wizard) but how would I load a YouTube video directly into the player automatically (without the user having to click anything)?

For instance: I want to have this video http://youtube.com/watch?v=A4uyN5rQbbU appear when someone goes to the page.

Cheers.

Gravatar
  • rich
  • August 31st, 2007
  • 8:36 am

you can use most of the code above, except you wouldn’t need the lines for the buttons and video ID’s. Then in the init() method, add this line:

fetcher.fetchByURL("http://youtube.com/watch?v=A4uyN5rQbbU")

Gravatar
  • Keven
  • August 31st, 2007
  • 8:42 pm

Awesome!! Thanks rich. Much appreciated.

Gravatar

how someone wondered if it’s fair or not?
IT’S FANTASTIC!! THANKS FOR THE CODE!

Gravatar
  • igr
  • September 9th, 2007
  • 10:32 pm

I have a problem to deploy it on my website. I downloaded the source and uploaded to my site without alterations, yet it didn’t work.
Could it have anything to do with php version or firewall settings?

Gravatar
  • igr
  • September 10th, 2007
  • 2:14 pm

While awaiting the moderation I came up with another question:
will this work if I load FLVFetcher.swf into another swf?

Gravatar
  • Pat
  • September 14th, 2007
  • 12:43 pm

Here is a nice websitbe where you can search, view and download YouTube videos :

ilikeyouyube.com

Enjoy.

Gravatar
  • rich
  • September 14th, 2007
  • 2:52 pm

igr - you may possible have a problem with php version, although I can’t really say for sure without knowing exactly where the error is occuring. Also, it’s not the swf that makes it work, its the actionscript classes, so if you are using the classes you should be able to use them anywhere.

pat - yeah, there are tons of sites and apps that will grab the video for you, but this is more for flash developers who are trying to play the flv’s in their apps.

Gravatar
  • aleandro
  • October 12th, 2007
  • 7:36 pm

the url for the source don’t work!

Gravatar

I tried to download the source files but the link is not working… :-(

Gravatar
  • rich
  • October 15th, 2007
  • 2:54 pm

the link to the source has been fixed.

Gravatar

Hi,
your code work inseide ide (standalone) but when i publish on the web the flv isn’t loaded. Why???

bye SK

Gravatar
  • rich
  • November 2nd, 2007
  • 4:08 pm

Siciliankiòòa - that sounds like a cross-domain issue.

Gravatar

Rich - I suppose! If you take a look the crossodomain policies , you can see youtube and google domain only (http://www.youtube.com/crossdomain.xml). Do you know a possible solution?

Gravatar
  • hollariho
  • November 5th, 2007
  • 6:57 pm

I downloaded the code and I can not get it working.
Looks like the get_video.php can not communicate back to the flash.
Is there special any server settings involved here?
I use Apache, PHP 5+.

Thanks

Gravatar
  • rich
  • November 6th, 2007
  • 1:59 pm

I used php 4 for this. You may need to tweak for php 5.

Gravatar
  • hollariho
  • November 7th, 2007
  • 7:48 am

After the flash calls the get_video.php I got a popup window with the return value. How can I disable this window?

Thanks

Gravatar
  • A-thorn
  • November 12th, 2007
  • 5:16 am

Can you tell me how to change the string in the text input (by default is http://youtube.com/v/zk5w9QPf6ek)???
I’m a little confused… thanks…

Gravatar

thanks for the GREAT post! Very useful…

Gravatar
  • Mus
  • December 26th, 2007
  • 3:43 am

Great tool. However, the google flv fetcher does not seem to work. I would be happy if you post a fix for that.

Thank you.

Gravatar
  • cory
  • April 27th, 2008
  • 9:38 am

hi,
sorry i can’t seem to find the source code for flash 8. can someone prvide me the link please

cheers!

Gravatar
  • Davide
  • May 7th, 2008
  • 12:15 am

Hi there,
the .fla appears to be corrupted and can’t open it :(

Can someone help me to find out a working source?

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>