Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Created November 8, 2012 21:46
Show Gist options
  • Save pjaspers/4041893 to your computer and use it in GitHub Desktop.
Save pjaspers/4041893 to your computer and use it in GitHub Desktop.
Quickly take a maxgif url to boom.
#! /usr/bin/env ruby
#
# Takes an URL from http://maxgif.com and copies the url of the shown gif
#
unless ARGV[0]
banner = <<BANNER
Takes a http://maxfig.com url and copies the direct link to the GIF. If
supplied a second argument, it is used as the name in `boom`.
mx <maxgif url> <optional name>
BANNER
abort banner
end
unless ARGV[0] =~ /maxgif.com/
puts "Not a maxgif.com url, YMMV"
end
require 'open-uri'
require 'cgi'
url = ARGV[0]
name = ARGV[1]
source = `curl -sL #{url} | grep "og:image"`
gif = CGI.unescapeHTML(source.match(/content="(.+)(" property)/)[1])
system("printf '%s' '#{gif.strip}' | pbcopy")
if name
system("boom gifs #{name} #{gif}")
else
puts "Copied #{gif}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment