Peter Elst

Founding Partner – Project Cocoon

ActionScript 3.0 – YouTube video

with 16 comments

I’ve been working on some experiments using video and AIR and stumbled across Abdul Qabiz’s work on constructing the FLV download link for YouTube videos. Its actually surprisingly easy to get hold of the FLV asset once you capture the correct query string arguments.

Based on Abdul’s code I wrote an AS3 class that goes through the process of getting the URL to the FLV, dispatches a complete event once ready and has a download method using FileReference to download the actual file. Without a server side proxy, downloading only works when you run the code in AIR or as a projector on the desktop because of the security sandbox.

Using the class is really easy:

var myVideo:YouTubeVideo = new YouTubeVideo("http://youtube.com/watch?v=74HJVf0X020");
myVideo.addEventListener(YouTubeVideoEvent.COMPLETE, onVideoComplete);

private function onVideoComplete(evt:YouTubeVideoEvent):void
{
  trace(evt.video); // URL to the FLV
  myVideo.download([optional proxy URL]); // download FLV
}

I made a quick example in Flex — you just paste in the YouTube URL, it loads in the video and copies the URL to the FLV to the clipboard (rename the downloaded file to .flv). Click here to view source or download the code.

Look forward to your feedback, enjoy!

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.0 Belgium License.

No related posts.

Written by Peter

February 20th, 2008 at 4:23 pm

Posted in AIR, Flex