youtube movie title

Hello People.

I found this script on the forum, pretty nice idea .
BUT is there any way to set the filename as the
movie title on youtube… ? im still new in applescript
and not very good in shell script :confused:


try
	if (the clipboard) starts with "http://" then
		get the clipboard
	else
		display dialog "Enter a YouTube URL:" default answer "http://youtube.com/watch?v="
		text returned of result
	end if
	
	tell result to set downloadURL to "http://www.youtube.com/v/" & text ((my (offset of "=" in it)) + 1) thru -1
	tell result to if it contains "&" then set downloadURL to text 1 thru ((my (offset of "&" in it)) - 1)
	
	choose file name with prompt "Save YouTube flash video file as:" default name "untitled.flv"
	set outputFile to result as Unicode text
	if (text -4 through -1 of result) is not ".flv" then ¬
		set outputFile to result & ".flv"
	
	do shell script "/usr/bin/curl -I " & (quoted form of downloadURL) & " | /usr/bin/sed -e '/^Location:/!d' -e 's|^.*?|http://youtube.com/get_video?|' | /usr/bin/xargs /usr/bin/curl -L -o " & quoted form of POSIX path of outputFile
	
	display dialog "Script finished!" buttons {"Show Movie", "Close"} default button 2
	
	if (button returned of result) is "Reveal Video File" then
		tell application "Finder"
			activate
			reveal outputFile
		end tell
	end if
on error errMsg number errNum
	if errNum is not -128 then ¬
		display alert ("Error " & errNum) message errMsg buttons {"Cancel"} default button 1
	
	error number -128 -- Cancel
end try



Thanks

  • mkh

Hi mkh,

take a look at this:

try
	if (the clipboard) starts with "http://" then
		set theURL to (get the clipboard)
	else
		set theURL to text returned of (display dialog "Enter a YouTube URL:" default answer "http://youtube.com/watch?v=")
	end if
	
	tell theURL to set downloadURL to "http://www.youtube.com/v/" & text ((my (offset of "=" in it)) + 1) thru -1
	tell result to if it contains "&" then set downloadURL to text 1 thru ((my (offset of "&" in it)) - 1)
	set outputFile to (path to desktop as Unicode text) & paragraph 2 of (do shell script "curl " & quoted form of theURL & " | awk '/title=/'  | cut -f 4 -d '\"' ") & ".flv"
	
	do shell script "/usr/bin/curl -I " & (quoted form of downloadURL) & " | /usr/bin/sed -e '/^Location:/!d' -e 's|^.*?|http://youtube.com/get_video?|' | /usr/bin/xargs /usr/bin/curl -L -o " & quoted form of POSIX path of outputFile
	
	display dialog "Script finished!" buttons {"Show Movie", "Close"} default button 2
	
	if (button returned of result) is "Reveal Video File" then
		tell application "Finder"
			activate
			reveal outputFile
		end tell
	end if
on error errMsg number errNum
	if errNum is not -128 then ¬
		display alert ("Error " & errNum) message errMsg buttons {"Cancel"} default button 1
	
	error number -128 -- Cancel
end try

PS: the file will be saved at desktop instead of the root folder


tell application "Safari"	
       set title to name of document 1
	set title to text 11 thru -1 of title
end tell

set destinationPath to POSIX path of (path to desktop) & title & ".flv"

maybe?

Nice, you seem to save me alot Stefan, thanks :slight_smile:

Maybe someone know a way to obtain the download state of a video download to youtube.

I d like to add a progression bar to show how long will take the importation of the video from youtube.

Thanks for your help,

Francois