Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Last active August 29, 2015 14:23
Show Gist options
  • Save davidbalbert/9f0e576f14a5603f3588 to your computer and use it in GitHub Desktop.
Save davidbalbert/9f0e576f14a5603f3588 to your computer and use it in GitHub Desktop.
Ubiq.im command line client. Share Spotify and Rdio links with everyone.
#!/usr/bin/env ruby
if ARGV.empty?
$stderr.puts("usage: #{$0} rdio-or-spotify-url")
exit 1
end
require 'net/http'
require 'uri'
# https://open.spotify.com/track/4O2bsDch5ycLo6HZj8zoJk => spotify:track:4O2bsDch5ycLo6HZj8zoJkend
def expand_url(url)
u = URI(url)
if u.scheme =~ /https?/ && u.host.include?("spotify")
type, id = u.path[1..-1].split("/")
"spotify:#{type}:#{id}"
else
u.to_s
end
end
uri = URI("http://ubiq.im/new")
res = Net::HTTP.post_form(uri, 'url' => expand_url(ARGV[0]))
unless res.is_a? Net::HTTPFound
$stderr.puts("#{$0}: error: didn't get a Net::HTTPFound response.")
exit 1
end
link = uri.dup
link.path = res["Location"]
if `uname`.chomp == "Darwin"
system("printf #{link} | pbcopy")
end
puts link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment