ummmm…i don’t know…i’m getting this error: can’t get text item 2 of “”
this is what it looks like so far…it doesnt work though…but i got the lowercase thingie to work
set song_search to display dialog "What is the song called?" default answer ""
set the_song to the text returned of song_search as string
set artist_search to display dialog "Who is the artist?" default answer ""
set the_artist to the text returned of artist_search as string
tell application "TextCommands"
set the_artist to the_artist
set the_artist_lower to lowercase the_artist
end tell
tell application "TextCommands"
set the_song to the_artist
set the_song_lower to lowercase the_artist
end tell
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set the_song_lower to text items of the_song_lower
set the_artist_lower to text items of the_artist_lower
set AppleScript's text item delimiters to {"-"}
set the_song_lower to the_song_lower as Unicode text
set the_artist_lower to the_artist_lower as Unicode text
set AppleScript's text item delimiters to ASTID
set the_URL to "http://www.lyricsdir.com/" & the_artist_lower & "-" & the_song_lower & "-lyrics.html"
set lyricHTMLSource to (do shell script "curl " & the_URL)
(* Chop off all of the text before the number *)
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set lyricHTMLSource2 to text item 2 of lyricHTMLSource
(* Chop off all of the text after the number *)
set AppleScript's text item delimiters to {"<"}
set the_lyrics to text item 1 of lyricHTMLSource2
(* Set out delimiters back to normal *)
set AppleScript's text item delimiters to {""}
return the_lyrics
hendo13, check the shell script result. I get nothing, even when done in the Terminal.
Edit: I had to change the referer to get something.
do shell script "/usr/bin/curl --user-agent '' " -- whatever else
Edit: Try something like this:
display dialog "What is the song called?" default answer ""
set theSong to text returned of result
display dialog "Who is the artist?" default answer ""
set theArtist to text returned of result
set theSong to lowercase(theSong)
set theArtist to lowercase(theArtist)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theSong to text items of theSong
set theArtist to text items of theArtist
set AppleScript's text item delimiters to {"-"}
set theSong to theSong as Unicode text
set theArtist to theArtist as Unicode text
set AppleScript's text item delimiters to {""} -- Not really needed here, but we're not using any error handling on the shell script, so.
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text) -- removes a newline
-- proper way to set the delimiters back (that's why you "saved" them earlier!)
set AppleScript's text item delimiters to ASTID
return theLyrics
on lowercase(someText)
return do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().encode('utf8')\" " & quoted form of someText
end lowercase