ActionScript 3.0 - YouTube video
20 02 2008I’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 video’s. 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!




You should make an Air app for this Pet. A lot of people would love it..
Stay tuned Savvas, got something coming next week
Looks really good! I actually wrote a YouTube class along the same principles: http://www.reynaldocolumna.com/blog/archives/new-services-package-added-to-the-reyco1-as3-tools-with-youtube
I always liked the idea of rolling youtube videos from your subscriptions. That way when your cleaning house/working out/etc you dont have to constantly click on the next one. I guess now it can become reality. Cool stuff.
Not trying to be a wennie here, but this may conflict the terms of service. Plus, how does the proxy part work? I believe youtube creates a temporary filename for every request that eventually times out. I wonder if the above solution could break at the whim of youtube?
good point Phillip, it may be in breach of their terms of service so use at your own risk — not promoting anyone to steal bandwidth from YouTube/Google.
They do have an API to get hold of their SWF player that then loads in a particular video, unfortunately can’t use that to cache for offline use. The only way to get an offline copy of a video is using this type of approach.
Unless YouTube drastically changes its redirection mechanism this method should keep working.
Hey Peter you’re firing my examples for the AIR book ;))) Aahahhaah
ciao mate
I tried creating a sample app like the one you have running, but using the FLVPlayback component. I couldn’t figure out what URL to pass into the FLVPlayback component. I tried using evt.video, but it said it through an error I think because it’s not a direct link to the actual flv. How did you get around this?
@Billy Pope — I think the problem you’re having has to do with the FLVPlayback component, for some reason they hardcoded it to expect files with a .flv extension.
What you can do rather than use the FLVPlayback component is create a new Video instance and use NetStream and NetConnection objects. There might be an update to the FLVPlayback component available on the Adobe site since they had to fix this behavior for it to work now they added H.264 support and video files other than .flv can be played back.
Take YouTube Videos with you
YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.
YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.
Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.
Product page: http://www.youtuberobot.com
Direct download link: http://www.youtuberobot.com/download/utuberobot.exe
Company web-site: http://www.youtuberobot.com
E-mail: support@youtuberobot.com