Skip to content

Instantly share code, notes, and snippets.

@aalin
Created May 9, 2009 13:14
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 aalin/109273 to your computer and use it in GitHub Desktop.
Save aalin/109273 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
song_name = ARGV.join(" ")
class RukindSongFinder
def initialize(song_name)
@song_name = song_name
end
def print_tab
doc = Hpricot(open('http://www.rukind.org/gdpedia/titles/show/%s' % song_id))
puts('http://www.rukind.org/gdpedia/titles/show/%s' % song_id)
puts doc.at( 'h1').inner_html.center(80)
puts (doc / 'h3 > em').inner_html.center(80)
(doc / 'pre').each do |pre|
pre.children.each do |child|
if child.is_a? Hpricot::Text
puts child
end
end
end
end
def song_id
doc = Hpricot(open('http://www.rukind.org/html/music/gdtunes/menus/titlemenu.html'))
links = (doc / 'table > tr > td > div > a')
links.each do |link|
if clean(link.parent[:id]) == clean(@song_name)
return link[:href].gsub(/.*?(\d+)$/, '\1').to_i
end
end
raise "Song not found: #{ @song_name }"
end
private
def clean(str)
str.gsub(/[^A-Za-z]/, '').downcase
end
end
RukindSongFinder.new(ARGV.join(' ')).print_tab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment