Ok, so my lyrics grabber script is a little messed. This line:
set theURL to "http://www.lyricwiki.org/" & theArtist & ":" & theSong
return theURL
for example returns
If I paste that URL into my browser it goes to the correct page.
However when I try to cURL it like so:
set theURL to "http://www.lyricwiki.org/" & theArtist & ":" & theSong
get theURL
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
I get the html to an error page. Like this
Just wondering if anyone knows whats up with that?
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
end tell
do shell script "curl 'http://lyricwiki.org/api.php?func=getSong&artist=" & simpleString(art) & "&song=" & simpleString(song) & "&fmt=text'"
on simpleString(theString)
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 & "_"
else
set stringOut to stringOut & (character i of theString)
end if
end repeat
return stringOut
end simpleString
try
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"
end if
on error e
if e contains "curl: (28)" then display dialog last paragraph of e -- timeout error
end try
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
on makeURL(txt)
tell application "TextCommands"
set theURL to encode URL txt
end tell
return theURL
end makeURL