Created
November 12, 2009 18:00
-
-
Save ttscoff/233120 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 -rjcode -Ku | |
# TextMate command to get the first url | |
# from a Songza.fm search for the selected text. | |
# Input: Selected Text or Word | |
# Output: Show as Tool Tip | |
require ENV['TM_SUPPORT_PATH'] + '/lib/escape' | |
require 'open-uri' | |
require 'rubygems' | |
require 'hpricot' | |
term = STDIN.read | |
url = "http://songza.fm/?q="+e_url(term) | |
begin | |
doc = Hpricot(open(url)) | |
rescue | |
puts "Error processing provided url" | |
exit | |
end | |
postsec = doc.search("//ul[@id='results']").first | |
song = postsec.search("//a[@class='song']").first | |
songlink = 'http://songza.fm'+song.attributes['href'] | |
songname = song.attributes['title'] | |
shorturl = open("http://is.gd/api.php?longurl=#{songlink}").read | |
%x{echo #{shorturl}|pbcopy} | |
puts %Q{The url for "#{songname}" is in the clipboard.} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment