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
- This script was designed to work on Mac OS X Tiger / Leopard.
- 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
Share
Source: http://tuaw.com/tag/AppleScript
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
i use this, i cant find better
http://www.indonesiaindonesia.com/downloadvideos/
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 Permalink rate up rate down ReplyI 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!
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/
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"
@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! :)
Just change the .html extension to .mp4 and that should work. :D
May 12 2008 at 10:22 AM Report abuse Permalink rate up rate down ReplyYou 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!
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! :)
very nice!
Thanks! This will save me the trouble of going through another site to download the FLV!
I prefer just going  + option + A and option clicking on the file directly...
May 12 2008 at 8:25 AM Report abuse Permalink rate up rate down ReplyThe 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
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 Permalink rate up rate down ReplyIf you install perian (free) you can view FLV files through quicktime
May 12 2008 at 8:59 AM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Verizon Leather Sleeve for Tablets for $4 + free shipping
- Wicked Jaw Breaker Noise-Isolating In-Ear Headphones for $6 + free shipping
- Refurb Apple MacBook Air Laptops: 12" 64GB SSD for $699 + free shipping
- JVC Motion Sensing Clock Radio with Dual iPod Docks for $55 + free shipping
- Apple iPhone Headset with Mic for $4 + $2 s&h
- Refurb Apple iPod nano 8GB MP3 Player for $99 + free shipping, 16GB for $119
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



14 Comments