Created
May 9, 2009 13:14
-
-
Save aalin/109273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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