Skip to content

Instantly share code, notes, and snippets.

@flawiddsouza
Forked from olimagsax/LyricsFetch.rb
Last active May 9, 2016 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flawiddsouza/d9f24d2061ac6b3a7f76f30f0c063e86 to your computer and use it in GitHub Desktop.
Save flawiddsouza/d9f24d2061ac6b3a7f76f30f0c063e86 to your computer and use it in GitHub Desktop.
Updated LyricsFetch.rb
# from https://gist.github.com/Sidysky/11354662
require 'open-uri'
puts "Artist:"
artist = $stdin.gets.chomp
artist = artist.delete " "
puts "Song Name:"
song = $stdin.gets.chomp
song = song.delete " "
url = "http://www.azlyrics.com/lyrics/"
url << artist.downcase
url << "/"
url << song.downcase.gsub("'", '') # gsub to remove single quotes from song title
url << ".html"
puts url
page_content = open(url).read
debut = page_content.index('<!-- Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that. -->')
fin = page_content.index('<br><br>')
debut = debut + 133
fin = fin - 11
lyrics = page_content[debut..fin]
lyrics = lyrics.gsub "<br>", " "
puts lyrics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment