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.

[swf]http://www.peterelst.com/code/youtubedownload/youtubedownload.swf,340,320[/swf]

Look forward to your feedback, enjoy!

Posted
AuthorPeter
CategoriesAIR, Flex