Peter Elst

Flash Platform Consultant
  • Home
  • About me
  • Articles
  • Downloads
  • Contact me

ActionScript 3.0 - YouTube video

20 02 2008

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 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!

« on AIR tour comes to Europe FITC Amsterdam - RIA meets Desktop »



Actions

  • rss Comments rss
  • trackback Trackback

Informations

  • Date : 20 February 2008
  • Categories : AIR, Flex

10 responses to “ActionScript 3.0 - YouTube video”

20 02 2008
savvasmalamas (16:39:51) :

You should make an Air app for this Pet. A lot of people would love it..

20 02 2008
Peter (16:42:08) :

Stay tuned Savvas, got something coming next week ;)

20 02 2008
reyco1 (18:24:31) :

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

20 02 2008
Jonathan (18:31:40) :

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.

21 02 2008
Phillip Kerman (00:00:29) :

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?

21 02 2008
Peter (00:10:38) :

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.

21 02 2008
Marco Casario (19:33:16) :

Hey Peter you’re firing my examples for the AIR book ;))) Aahahhaah
ciao mate

27 02 2008
Billy Pope (00:11:20) :

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?

28 02 2008
Peter (10:52:02) :

@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.

5 03 2008
steveking (08:49:49) :

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

Leave a comment

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





Training Partners

multimediacollege

SkillsMatter

  • Categories

    • AIR RSS category feed
    • Ajax RSS category feed
    • CSS RSS category feed
    • Eclipse RSS category feed
    • Events RSS category feed
    • Flash RSS category feed
    • Flash Lite RSS category feed
    • Flex RSS category feed
    • Gadgets RSS category feed
    • General RSS category feed
    • JSFL RSS category feed
    • Mac RSS category feed
    • Open Source RSS category feed
    • PHP RSS category feed
    • Podcasts RSS category feed
    • Publications RSS category feed
    • Rants RSS category feed
    • Reviews RSS category feed
    • Thought of the Day RSS category feed
    • Training RSS category feed
    • Video RSS category feed
  • Resources

    • Aral Balkan
    • Guy Watson
    • Chafic Kazoun
    • AndrĂ© Michelle
    • Francis Bourre
    • Veronique Brossier
    • Ralf Bokelberg
    • Jesse Warden
    • Brajeshwar Oinam
    • Mario Klingemann
    • Burak Kalayci
    • Serge Jespers
    • Matt Voerman
    • Darron Schall
    • Stefan Richter
    • Josh Tynjala
    • Peter Hall
    • Keith Peters
    • Abdul Qabiz
    • Owen van Dijk

     
     

    Adobe Community Expert

    See my profile on LinkedIn



    Harz Ferienwohnung Suchmaschinenoptimierung Geschenkideen Harz Ferienwohnung Pagerank Webkatalog Webhosting