Created
June 29, 2011 00:33
-
-
Save mkaito/1052571 to your computer and use it in GitHub Desktop.
Script that reads currently playing song from MPD via MPC and queries Tinysong for a sharing URL, then spits out a nicely formated text for you to tweet.
This file contains hidden or 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
# coding: utf-8 | |
require 'net/http' | |
require 'json' | |
require 'cgi' | |
require 'extlib' | |
playing = `mpc current`.chomp | |
key = "insert your API key here" | |
url = "http://tinysong.com/b/#{CGI.escape(playing)}?format=json&key=#{key}" | |
resp = Net::HTTP.get_response(URI.parse(url)) | |
tiny = JSON.parse(resp.body) | |
unless tiny.blank? | |
puts "First match: #{tiny['ArtistName']} ♪ #{tiny['SongName']}" | |
puts "#nowplaying \[#{playing}\] #{tiny["Url"]}" | |
else | |
puts "Found nothing. Quit listening to weird shit." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment