#!/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