ok, so I have a Ruby script that fetches lyrics from a website. Here it is.
[code]require ‘net/http’
require ‘open-uri’
require ‘pp’
require ‘uri’
second_word = false
artist=“”
song=“”
ARGV.each {|arg|
if arg.include?(“^”)
second_word = true
end
if second_word
song+= arg.to_s + " "
else
artist+= arg.to_s + " "
end}
artist.chop!
song=song.gsub(/^/, “”).chop!
def generate_search_url(query, input2)
query= URI.escape(query.chomp).gsub(/%20/, '+')
#fixes e
query = query.gsub(/%C3%A9|%C3%A8/, 'e')
input2 = URI.escape(input2.chomp).gsub(/%20/, '+')
input2 = input2.gsub(/%C3%A9|%C3%A8/, 'e')
search_url="http://leoslyrics.com/advanced.php?artistmode=0&artist="+ query + "&albummode=0&album=&songmode=0&song="+ input2 + "&mode=0"
return search_url
end
#returns lyrics
def parse_search_result(url)
product_page=false
temp = “”
product_ids=Array.new
#source = Net::HTTP.get(URI.parse(url))
source = open(URI.parse(url)).read
prod_exp=//listlyrics\S."/
prod_exp=~source
if $& != nil
found=true
end
if found
#re=/http://i.walmart.com/i/p/.(.gif|.jpg)&product_id.*/
new_url = “http://www.leoslyrics.com” + $&.gsub(/"/, “”)
source2 = open(URI.parse(new_url)).read
re=/<font\sface=\"Trebuchet\sMS,\sVerdana,\sArial\"\ssize=-1>/
re =~ source2
#finish extracting lyrics
re2 = /<\/font>/
re2 =~ $'
lyrics = $`
if lyrics != nil
lyrics = lyrics.gsub(/<br\s\/>/, "\n").gsub(/'/, "'").lstrip
puts lyrics
end
end
end
parse_search_result(generate_search_url(artist, song))[/code]
Now I want the result of this script put into a scroll view. How would I do this?
Wait, what’s the problem? The subject mentions using a ruby script, but then you actually ask how to put the result of the script into a text view; To me, that would suggest that you don’t have any problem getting a result from the script mentioned in the title. (I’m assuming you meant a text view that is inside of a scroll view.)
yes…thats exactly what i was asking…i want the result of the ruby script (which should be some lyrics) inside a text view. I’m not sure how to do this.
bump (I edited my first post a little.)
that script was just a ruby script i found on the internet…
I have been looking for a way to fetch lyrics ever since www.lyricsdir.com used a special javascript to block the -curl command…if you know a better way please do tell.
So do you have a result from the ruby script or not?
i know jack all about Ruby…to me the last line looks like the final result. I cud be wrong…
I would add the ruby script to your project, and then use it with do shell script
. Then, you could use the result like you normally would.
so i would put that whole ruby script in a do shell script command?
i really would rather accomplish this in applescript…
i tried this:
on getlyrics() --method to get lyrics...
set theSong to edittext(theSong) --convert the texts
set theArtist to edittext(theArtist)
get "http://www.absolutelyrics.com/lyrics/view/" & theArtist & "/" & theSong
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='realText'>"}
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)
end getlyrics
but it gave me the wrong part of the website…
EDIT: fixed! it all works now!
do any of the AS gurus here have a better way to obtain lyrics. The script above works fine but absolutelyrics.com is not the greatest lyrics site. If it were possible to somehow use www.leoslyrics.com, that would be awesome.
You could save it as a resource in your app, and call it from do shell script
.
You may be able to make something based on this: How to script songs lyrics retrieval