Skip to content

Instantly share code, notes, and snippets.

@mkaito
Created June 29, 2011 00:33
Show Gist options
  • Save mkaito/1052571 to your computer and use it in GitHub Desktop.
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.
# 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