get youtube title

i have files downloaded from youtube named
video-1.flv
video-2.flv etc
I want to name these files.
I can write an applescript which can take the URL of the videos from the “Get Info” window (precisely, Get Info>>More Info>>Where from), open it in a browser window and then set the name of the file to the title of browser window.

I want to know if there is a better alternative way of doing this.

One alternative that I have thought of is as follows:
All the videos are from a feed.
e.g. feed://gdata.youtube.com/feeds/base/users/bbclearningenglish/uploads?orderby=updated&alt=rss&v=2&client=ytapi-youtube-rss-redirect

If this feed is opened in Safari, I can see the clickable title (the link opens if the title is clicked) of the video
e.g.
The Flatmates episode 3, from BBC Learning English
bbclearningenglish
in the above feed has the link “http://www.youtube.com/watch?v=0AASCQNCo-o

If I could extract the title and link contained in it then I might be able to match the URL in the “Get info” window of the video and set the name of the file to the corresponding title.

Lastly, also let me know if curl or youtube API can help with this.

Thanks.

Hi,

you can retrieve the title with


set theURL to "http://www.youtube.com/watch?v=0AASCQNCo-o"
set theTitle to do shell script "/usr/bin/curl " & quoted form of theURL & " | /usr/bin/grep 'meta name=\"title\"' | /usr/bin/cut  -d '\"' -f 4"

Thanks.
frequently, i get the extra words added like “”"

I get
Lesson 2 - “TH” - English Pronunciation
for http://www.youtube.com/watch?v=1GOJ4eF5L94
instead of “Lesson 2 - TH - English Pronunciation” as seem in the title of Safari or Camino browser window.

easiest way: install UnicodeChecker


set theURL to "http://www.youtube.com/watch?v=1GOJ4eF5L94"
set theTitle to do shell script "/usr/bin/curl " & quoted form of theURL & " | /usr/bin/grep 'meta name=\"title\"' | /usr/bin/cut  -d '\"' -f 4"
tell application "UnicodeChecker"
	repeat while theTitle contains "&" and theTitle contains ";"
		set theTitle to deXHTMLized representation of theTitle -- " --> " --> ";
	end repeat
	quit
end tell

Hi

Here are two alternatives, which do not require any installation.

--set theURL to "http://www.youtube.com/watch?v=0AASCQNCo-o"
set theURL to "http://www.youtube.com/watch?v=1GOJ4eF5L94"
set theTitle to do shell script "/usr/bin/curl " & quoted form of theURL & "  | /usr/bin/grep '<title>' | /usr/bin/sed 's/<title>YouTube - //' |  /usr/bin/textutil -stdin -stdout  -convert txt -format html"

--or
--set theTitle to do shell script "/usr/bin/curl " & quoted form of theURL & "  | /usr/bin/grep '<title>'  |  /usr/bin/perl -ne 'use HTML::Entities;s/.*<title>YouTube - //;s/<\\/title>//;print decode_entities($_);'"

Many thanks, Jacques