Skip to Content

AppleScript: download YouTube videos

Keeping with the "self-built apps," I'm going to show you how to build your own YouTube downloader. Sure you could use applications like TubeSock, but where's the fun in that? This application will download the YouTube flash video from a pasted link, and all with a little AppleScript.


Continue reading to learn how to build the YouTube downloader.


Building the script

Just copy the following script into the Script Editor.app (/Applications/AppleScript/Script Editor.app):

set pageURL to display dialog "Enter the URL of the YouTube video's page:" default answer ""

set AppleScript's text item delimiters to "?v="
set v_id to item 2 of text items of text returned of pageURL
set pageURL to "http://www.youtube.com/v/" & v_id

set locationURL to do shell script "curl -I " & pageURL & " | grep ^Location | grep -o 'video_id=.*'"
set AppleScript's text item delimiters to "&t="
set t_id to item 2 of text items of locationURL

set downloadURL to "http://youtube.com/get_video?video_id=" & v_id & "&t=" & t_id

open location downloadURL



Saving the script
Let's save this AppleScript as an AppleScript application. To do this, just click File > Save. Type in a name for your appliction and choose "Application Bundle" from the "Format" drop-down box.



Running the script
To run the YouTube downloader, double-click on the AppleScript application that you just created. When the script starts, it will display a dialog asking you for a YouTube URL (this is the URL that you copy from the address bar, not from the YouTube embed). Paste the URL and click "OK." The application will then start running and run a couple background processes -- in about 1-2 minutes (depending on internet connection / Mac speed) your default browser will begin downloading a file named "get_video.flv."

Once the download has finished, you can convert the flash video into something that you can look at natively. I recommend a free application called iSquint -- you can drop the flash video onto the iSquint app and convert it into numerous formats including iPod and Apple TV.

Additional notes
  1. This script was designed to work on Mac OS X Tiger / Leopard.
  2. While this script was designed and tested to work with Safari 3.0 and Firefox, it can be used with other browsers; however, if you are experiencing difficulties with your default browser, try Safari or Firefox


Categories

Features How-tos

Keeping with the "self-built apps," I'm going to show you how to build your own YouTube downloader. Sure you could use applications like...
 

Add a Comment

*0 / 3000 Character Maximum

14 Comments

Filter by:
download youtube

i use this, i cant find better


http://www.indonesiaindonesia.com/downloadvideos/

June 30 2008 at 10:27 PM Report abuse rate up rate down Reply
youtube downloader

Here is a great tutorial about how to download youtube videos fast and easily,http://www.ehow.com/video_2287260_handle-youtube-downloader.html,it's really worth reading.

May 25 2008 at 11:24 PM Report abuse rate up rate down Reply
Matthew Dunlop

I tried the script a couple of times the other day (with a nice bit of Automater to automatically put it in an iTunes format using iSquint) but it now keeps bring up an error message and highlights this line---

set locationURL to do shell script "curl -I " & pageURL & " | grep ^Location | grep -o 'video_id=.*'"

Can someone help me here?
I tried it just normally in applescript but it does the same thing!
Help me please I want Youtube videos on mY iPod Touch offline!

May 21 2008 at 6:54 AM Report abuse rate up rate down Reply
Javier

Can someone help me by teaching me how I can download the video from Tudou.com?
It is a China version of Youtube. It's got my fav astrology programs, I'm like dying to keep all of them!! =p

http://www.tudou.com/programs/view/G9AlwaVFR74/

May 18 2008 at 12:09 PM Report abuse rate up rate down Reply
mark

If you change the last "set" of the script to the following, you can automatically download .mp4 versions of the videos if they are available.

set downloadURL to "http://youtube.com/get_video?video_id=" & v_id & "&t=" & t_id & "&fmt=18"

May 12 2008 at 1:38 PM Report abuse rate up rate down Reply
Queco Jones

@Ryan Humphreys: That works but, the file always ends up saved with a ".html" extension added to it (no matter what I name it)... any idea on how to avoid that?

TIA,

PS: Thanks! :)

May 12 2008 at 10:12 AM Report abuse rate up rate down Reply
1 reply to Queco Jones's comment
Ryan Humphreys

Just change the .html extension to .mp4 and that should work. :D

May 12 2008 at 10:22 AM Report abuse rate up rate down Reply
Ryan Humphreys

You can use a bookmarklet to download the MP4 directly from YouTube. Just create a bookmark with this as the URL:

javascript:if%20(document.getElementById('download-youtube-video')==null%20&&%20!!(document.location.href.match(/http://[a-zA-Z.]*youtube.com/watch/)))%20{var%20yt_mp4_path='http://www.youtube.com/get_video?fmt=18&video_id='+swfArgs['video_id']+'&t='+swfArgs['t'];%20var%20div_embed=document.getElementById('watch-embed-div');div_embed.innerHTML=div_embed.innerHTML+'%3Cbr%20/%3E%20%3Cspan%20id='download-youtube-video'%3E%3Ca%20href=''+yt_mp4_path+''%3EDownload%20as%20MP4%3C/a%3E%20'+%20%20((navigator.userAgent.indexOf('Safari')!=-1)?'(control-click%20and%20select%20%3Ci%3EDownload%20linked%20file%20as%3C/i%3E)':('(right-click%20and%20select%20%3Ci%3ESave%20'+%20(navigator.appName=='Microsoft%20Internet%20Explorer'?'target':'link')%20+'%20as)%3C/i%3E'))+'%3C/span%3E';}void(0);

Then when you are on YouTube and want to download a video, click the bookmarklet and underneath the video info will appear a link saying Download as MP4. Then just Command-click on the link and choose Download Linked File As...

And there you have it, an iPod ready MP4 of the YouTube video. Hope this helps!

May 12 2008 at 8:42 AM Report abuse rate up rate down Reply
1 reply to Ryan Humphreys's comment
Queco Jones

That works but, the file always ends up saved with a ".html" extension added to it (no matter what I name it)... any idea on how to avoid that?

TIA,

PS: Thanks! :)

May 12 2008 at 10:17 AM Report abuse rate up rate down Reply
Neshy

very nice!

Thanks! This will save me the trouble of going through another site to download the FLV!

May 12 2008 at 8:26 AM Report abuse rate up rate down Reply
Luigi193

I prefer just going  + option + A and option clicking on the file directly...

May 12 2008 at 8:25 AM Report abuse rate up rate down Reply
The Tuesday Night Tech Show

The only downside to this is that you have to convert it at the end; there is a nice Firefox greasemonkey extension that you can install that gives you a new link that downloads the actual MP4 of the video instead; no conversion needed and better quality!
----------------------

Free iPhone-Only Ringtones
ringtoneyouriphone.blogspot.com

May 12 2008 at 8:17 AM Report abuse rate up rate down Reply
2 replies to The Tuesday Night Tech Show's comment
Macskeeball

Indeed, and there is also a bookmarklet (Javascript stored as a bookmark, with the ability to act on the current page) available, for those who don't use Firefox. http://googlesystem.blogspot.com/2008/04/download-youtube-videos-as-mp4-files.html

May 12 2008 at 8:45 AM Report abuse rate up rate down Reply
Tom Waterhouse

If you install perian (free) you can view FLV files through quicktime

May 12 2008 at 8:59 AM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.