Created
April 27, 2009 12:04
-
-
Save dougal/102456 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 | |
# Copyright (c) Douglas F Shearer 2009 | |
# http://douglasfshearer.com | |
# Distributed under the MIT licence. | |
# Converts a flickr.com user or photo URL to a flic.kr short URL. | |
# | |
### User example: | |
# | |
# $ ./flic.kr http://www.flickr.com/photos/douglasfshearer/ | |
# Result added to clipboard: | |
# | |
# http://flic.kr/douglasfshearer | |
# | |
### Photo example: | |
# | |
# $ ./flic.kr http://www.flickr.com/photos/douglasfshearer/337366577/ | |
# Result added to clipboard: | |
# | |
# http://flic.kr/p/vP6k8 | |
require 'rubygems' | |
begin | |
require('base58') | |
rescue LoadError | |
puts '[Error] base58 gem not installed: http://github.com/dougal/base58/' | |
Process.exit(0) | |
end | |
if ARGV[0][/photos\/[^\/]+\/(\d+)/] | |
result = "http://flic.kr/p/#{Base58.int_to_base58($1.to_i)}" | |
elsif ARGV[0][/photos\/([^\/]+)/] | |
result = "http://flic.kr/#{$1}" | |
end | |
if result | |
`echo #{result} | pbcopy` # Mac OS X Specific. | |
puts "Result added to clipboard:\n\n" | |
puts result | |
else | |
puts 'URL not matched' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment