dougal (owner)

Revisions

gist: 102456 Download_button fork
public
Public Clone URL: git://gist.github.com/102456.git
Embed All Files: show embed
Flic.kr URL Generation Script #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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