Youtube video launcher

Ok, so I was messing around and I made something that launches the video you enter. It opens the first result that would come up if you were to search for it on youtube. It’s very simple, but I plan to expand on it. Feel free to leave comments, constructive criticism :slight_smile:

Thanks!

--                                        youLaunch - A youtube video searcher
try
	getVidTitle()
	replacePlusAndQuotes(theVid)
	findURL(newVid)
	openURL(idCode)
on error
	display dialog "              Thanks for using youLaunch!" buttons {"OK"} default button 1
end try
on getVidTitle()
	display dialog "Enter the video's name:" default answer "video name" buttons {"Quit", "OK"} default button 2
	set theResult to result
	if button returned of theResult is "Quit" then
		ImExitingRightNowCuzThisIsntDefined
	end if
	global theVid
	set theVid to text returned of theResult
end getVidTitle

on replacePlusAndQuotes(theVid)
	global newVid
	set newVid to ""
	repeat until number of characters in theVid = 1
		set thisLetter to character 1 of theVid
		if thisLetter is " " then
			set thisLetter to "+"
		end if
		if thisLetter is "'" then
			set thisLetter to ""
		end if
		set newVid to newVid & thisLetter
		set theVid to text 2 thru end of theVid
	end repeat
	if theVid is " " then
		set theVid to "+"
	end if
	if thisLetter is "'" then
		set thisLetter to ""
	end if
	set newVid to newVid & theVid
end replacePlusAndQuotes

on findURL(newVid)
	global idCode
	set theYoutubeHTML to "http://www.youtube.com/results?search_query=" & newVid
	
	set theCode to do shell script ("curl " & theYoutubeHTML) without altering line endings
	set idCode to text ((offset of "<h3><a href=\"" in theCode) + 13) thru end of theCode
	set idCode to text 1 thru ((offset of "\"" in idCode) - 1) of idCode
end findURL

on openURL(idCode)
	open location ("http://www.youtube.com" & idCode)
end openURL

Model: Macbook
Browser: Safari 533.21.1
Operating System: Mac OS X (10.6)

Hey! I’m REALLY REALLY new to Applescript but I want to learn as much as I can. I’m not sure if I am using you script right or not but it asks for a video, i enter video title, hit “ok” and nothing happens. :frowning: Any help would be appreciated. I also am working on a program that views youtube video to boost the view count. Not trying to make money off youtube or anything just helping a client. PM me if you think you can help! Thank you so much! :stuck_out_tongue:

Model: MacBook
AppleScript: Version 2.3
Browser: Safari 536.5
Operating System: Mac OS X (10.7)