Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Google-is-your-friend-edition :-)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Google-is-your-friend-edition :-)
Authored by: SwissMike on Jul 10, '03 02:49:52PM

I adapted the script to use Google's "I'm feeling lucky" feature, as my musical taste didn't seem to match the given site. The results are much better for me now, YMMV.

property nameOfTrack : ""
property nameOfAlbum : ""
property nameOfArtist : ""

tell application "iTunes"
copy name of current track to nameOfTrack
copy album of current track to nameOfAlbum
copy artist of current track to nameOfArtist

set nameOfTrack to my parseWord(nameOfTrack)
set nameOfAlbum to my parseWord(nameOfAlbum)
set nameOfArtist to my parseWord(nameOfArtist)

my openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
end tell

on parseWord(myWord)
set myDelims to {"(", ")", "!", "'", "-", "@", "#", "$", "%", ¬
"^", "&", "*", "-", "+", "=", ":", ";", ",", ".", "/", "<", ¬
">", "?", "{", "}", "[", "]"}
repeat with currentDelim in myDelims
set AppleScript's text item delimiters to currentDelim
set myWords to every text item of myWord
set AppleScript's text item delimiters to {""}
set myWord to myWords as string
end repeat

-- convert double spaces to single
set AppleScript's text item delimiters to " "
set myWords to every text item of myWord
set AppleScript's text item delimiters to {" "}
set myWord to myWords as string

-- get rid of spaces
set AppleScript's text item delimiters to {" "}
set myWords to every text item of myWord
set AppleScript's text item delimiters to {"+"}
set myWord to myWords as string
return myWord
end parseWord

on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
tell application "Safari"
activate
make new document at end of documents
--set URL of document 1 to "http://www.getlyrics.com/lyrics.php?Artist=" & ¬
nameOfArtist & "&Album=" & nameOfAlbum & "&Song=" & nameOfTrack
set URL of document 1 to ¬
"http://www.google.com/search?hl=en&ie=ISO-8859-1&btnI=I%27m+Feeling+Lucky&q=-site:amazon.com+-site:moviepundit.com+" & ¬
nameOfArtist & "+" & nameOfTrack & "+Lyrics"
end tell
end openBrowser


------------
Changes:
- adapted textdelimiters to Google's searchformat
- excluded Amazon.com and Moviepundit.com from the search-results, as they often appeared as result with a site to buy the CD, not the lyrics of the song
- i'm just using the artist and the song, not the album for the search, as with latter one i frequently got "album-overview" sites and not sites specifically for that song as result

Issues:
- Whenever i get a .htm File as a result, Safari downloads it instead of showing it in the browser... How can that be avoided?



[ Reply to This | # ]
Google-is-your-friend-edition :-)
Authored by: demmons65 on Jul 10, '03 08:18:11PM

Tried this version and it went 3 for 3, including a couple songs I figured might not be in anyone's lyric database.

Thanks to all that contributed and inspired the others to improve a good script.

--
d a v e

---
--
d a v e



[ Reply to This | # ]
Google-is-your-friend-edition :-)
Authored by: p4ul13 on Jul 10, '03 11:02:51PM
I like this version. I added one line to mine though. Whenever I got results; Safari would open a blank window and then present the lyrics. I found this annoying, so I made the following change:

on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
tell application "Safari"
activate
close window
make new document at end of documents
set URL of document 1 to ¬
"http://www.google.com/search?hl=en&ie=ISO-8859-1&btnI=I%27m+Feeling+Lucky&q=-site:amazon.com+-site:moviepundit.com+" & ¬
nameOfArtist & "+" & nameOfTrack & "+Lyrics"
end tell
end openBrowser


I'm still trying to figure out the .htm issue mentioned above...

[ Reply to This | # ]
For use with all browsers
Authored by: pwestbro on Jul 11, '03 04:19:52PM
For those that don't want to be forced to use Safari, I have modified the script to open the web page in the default browser:
property nameOfTrack : ""
property nameOfAlbum : ""
property nameOfArtist : ""

tell application "iTunes"
	copy name of current track to nameOfTrack
	copy album of current track to nameOfAlbum
	copy artist of current track to nameOfArtist
	
	set nameOfTrack to my parseWord(nameOfTrack)
	set nameOfAlbum to my parseWord(nameOfAlbum)
	set nameOfArtist to my parseWord(nameOfArtist)
end tell
tell application "Finder"
	open location "http://www.google.com/search?hl=en&ie=ISO-8859-1&btnI=I%27m+Feeling+Lucky&q=-site:amazon.com+-site:moviepundit.com+" & nameOfArtist & "+" & nameOfTrack & "+Lyrics"
end tell

on parseWord(myWord)
	set myDelims to {"(", ")", "!", "'", "-", "@", "#", "$", "%", ¬
		"^", "&", "*", "-", "+", "=", ":", ";", ",", ".", "/", "", "?", "{", "}", "[", "]"}
	repeat with currentDelim in myDelims
		set AppleScript's text item delimiters to currentDelim
		set myWords to every text item of myWord
		set AppleScript's text item delimiters to {""}
		set myWord to myWords as string
	end repeat
	
	-- convert double spaces to single
	set AppleScript's text item delimiters to " "
	set myWords to every text item of myWord
	set AppleScript's text item delimiters to {" "}
	set myWord to myWords as string
	
	-- get rid of spaces
	set AppleScript's text item delimiters to {" "}
	set myWords to every text item of myWord
	set AppleScript's text item delimiters to {"+"}
	set myWord to myWords as string
	return myWord
end parseWord



[ Reply to This | # ]
.htm problem and solution
Authored by: ThreeDayMonk on Jul 11, '03 11:57:52PM

The problem is not a ".htm" problem per se. As far as I can tell, all the .htm files are returned from the same site: www.musicsonglyrics.com. They appear to have set their server up rather badly, so that content-type is set to server-parsed instead of text/html. Even trying to visit the site is impossible in Safari!

That's why Safari downloads it: it doesn't know how to handle it. Compare that with Internet Explorer (Windows version), which tries to guess the format, and therefore happily interprets anything as HTML that looks like it, with predictable, negative consequences for security. Safari behaves correctly, as does Camino. IE:mac doesn't know what to do—it can't handle the page, according to my brief test.

The solution? Add -site:musicsonglyrics.com to the Google request. Works for me.



[ Reply to This | # ]