Joystiq has your stash of criminally complete GTA IV news!

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

Related Headlines

Reader Comments (Page 1 of 1)

Add your comments

Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

When you enter your name and email address, you'll be sent a link to confirm your comment, and a password. To leave another comment, just use that password.

To create a live link, simply type the URL (including http://) or email address and we will make it a live link for you. You can put up to 3 URLs in your comments. Line breaks and paragraphs are automatically converted — no need to use <p> or <br> tags.

New Users

Current Users

TUAW Features


Mac 101 ask-tuaw
Mac News
WWDC (250)
.Mac (57)
Accessories (635)
Airport (74)
Analysis / Opinion (1329)
Apple (1637)
Apple Corporate (555)
Apple Financial (187)
Apple History (45)
Apple Professional (54)
Apple TV (160)
Audio (446)
Bad Apple (118)
Beta Beat (149)
Blogging (84)
Bluetooth (16)
Bugs/Recalls (56)
Cult of Mac (869)
Deals (214)
Desktops (115)
Developer (252)
Education (98)
eMac (10)
Enterprise (138)
Features (396)
Freeware (381)
Gaming (361)
Graphic Design (31)
Hardware (1281)
Holidays (37)
Humor (576)
iBook (65)
iLife (234)
iMac (184)
Internet (325)
Internet Tools (1309)
iTS (967)
iTunes (796)
iWork (21)
Leopard (367)
Mac mini (112)
Mac Pro (53)
MacBook (202)
MacBook Air (79)
Macbook Pro (220)
MobileMe (16)
Multimedia (439)
Odds and ends (1437)
Open Source (277)
OS (910)
Peripherals (208)
Podcasting (182)
Podcasts (89)
Portables (197)
PowerBook (135)
PowerMac G5 (50)
Retail (577)
Retro Mac (48)
Rig of the Week (42)
Rumors (629)
Software (4304)
Software Update (406)
Steve Jobs (252)
Stocking Stuffers (50)
Surveys and Polls (97)
Switchers (112)
The Woz (34)
TUAW Business (235)
Universal Binary (281)
UNIX / BSD (61)
Video (902)
Weekend Review (81)
WIN Business (47)
Wireless (83)
Xserve (39)
iPhone/iPod News
iPhone (1487)
iPod Family (2024)
App Store (17)
SDK (14)
Mac Events
One More Thing (27)
Liveblog (1)
Other Events (226)
Macworld (489)
Mac Learning
AppleScript (2)
Ask TUAW (101)
Blogs (85)
Books (26)
Books and Blogs (62)
Cool tools (443)
Hacks (459)
How-tos (482)
Interviews (43)
Mods (185)
Productivity (586)
Reviews (107)
Security (153)
Terminal Tips (58)
Tips and tricks (563)
Troubleshooting (166)
TUAW Features
iPhone 101 (26)
TUAW Labs (3)
Blast From the Past (17)
TUAW Tips (141)
Flickr Find (34)
Found Footage (80)
Mac 101 (88)
TUAW Interview (31)
Widget Watch (198)
The Daily Best (1)
TUAW Faceoff (4)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Sponsored Links

The Unofficial Apple Weblog (TUAW) bloggers (30 days)

#BloggerPostsCmts
1Cory Bohon862
2Robert Palmer6046
3Steven Sande5723
4Dave Caolo370
5Scott McNulty370
6Mat Lu358
7Erica Sadun282
8Mike Schramm222
9Brett Terpstra210
10Michael Rose1334
11Christina Warren1245
12Joshua Ellis54
13Lisa Hoover26
14Chris Ullrich12
15Jason Clarke11

Featured Galleries

Macworld 2008 Keynote
Macworld 2008 Build-up
Apple Vanity Plates
DiscPainter
Macworld Expo 2007 show floor
The Macworld Faithful in Line
iPhone First Look
AT&T 3G Coverage Map
MobileMe Guided Tour UI Changes

 

    Most Commented On (7 days)

    Recent Comments

    More Apple Analysis

    More from AOL Money and Finance

    Weblogs, Inc. Network

    Other Weblogs Inc. Network blogs you might be interested in: