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){
}
[…] pm I just updated FLVFetcher so that you can now pass it a full youtube or google video url using FLVFetcher.fetchByURL(url). […]