Hi, I’ve writen a small script that returns me the lyrics for the playing song in iTunes and I’ve used the call SOAP method! But I’ve some problems with accentuated characters!
Now I’ve found this great solution using cURL! But there’s a problem, If in the song name or the artist there’s the quote ( ’ ) char the script get this error:
how I can solve it?
The script is:
tell application "iTunes"
set song to name of current track
set art to artist of current track
do shell script "curl 'http://lyricwiki.org/api.php?func=getSong&artist=" & simpleString(art) & "&song=" & simpleString(song) & "&fmt=text'"
set n to length of theString
set stringOut to ""
repeat with i from 1 to n
if (character i of theString is " ") then
set stringOut to stringOut & "_"
set stringOut to stringOut & (character i of theString)
set theLyrics to (do shell script "curl -m 10 " & quoted form of ("http://lyricwiki.org/api.php?func=getSong&artist=" & theArtist & "&song=" & theSong & "&fmt=text"))
if theLyrics is "Not found" then
-- do something for "not found"
on error e
if e contains "curl: (28)" then display dialog last paragraph of e -- timeout error
I’m not sure how you’d tell if it timed out. I couldn’t get it to time out, even with a -m of 1. I imagine that you would get a shorter result. So you could use something like (on the below): count characters of lyrics
That could be used to detect “not found” also.
I think it would also be a good idea to escape spaces or other characters that would make it not work. The easiest way is to let someone else do that. I use the free TextCommands scripting addition, which is available in that section of this site.
set theArtist to my makeURL("Sandy Denny")
set theSong to my makeURL("Farewell, Farewell")
set req to quoted form of ("http://lyricwiki.org/api.php?func=getSong&artist=" & theArtist & "&song=" & theSong & "&fmt=text")
set lyrics to do shell script "curl -m 10 " & req
tell application "TextCommands"
set theURL to encode URL txt