5 # A.k.a `Best web-album Of the world, Or your money back, Humerus'.
7 # The acronyn sucks, however this is a tribute to Dragon Ball by
8 # Akira Toriyama, where the last enemy beaten by heroes of Dragon
9 # Ball is named "Boo". But there was already a free software project
10 # called Boo, so this one will be it "Booh". Or whatever.
13 # Copyright (c) 2004 Guillaume Cottenceau <gc3 at bluewin.ch>
15 # This software may be freely redistributed under the terms of the GNU
16 # public license version 2.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 [ '--help', '-h', GetoptLong::NO_ARGUMENT, "Get help message" ],
29 [ '--no-check', '-n', GetoptLong::NO_ARGUMENT, "Don't check for needed external programs at startup" ],
31 [ '--source', '-s', GetoptLong::REQUIRED_ARGUMENT, "Directory which contains original images/videos as files or subdirs" ],
32 [ '--destination', '-d', GetoptLong::REQUIRED_ARGUMENT, "Directory which will contain the web-album" ],
33 [ '--clean', '-c', GetoptLong::NO_ARGUMENT, "Clean destination directory" ],
35 [ '--theme', '-t', GetoptLong::REQUIRED_ARGUMENT, "Select HTML theme to use" ],
37 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, "Set max verbosity level (0: warnings, 1: important messages, " +
38 "2: other messages)" ],
41 #- default values for some globals
43 $convert = 'convert -interlace line +profile "*"'
47 puts "Usage: #{File.basename($0)} [OPTION]..."
49 printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
53 def msg(verbose_level, msg)
54 if verbose_level <= $verbose_level
56 warn "Warning: #{msg}"
69 parser = GetoptLong.new
70 parser.set_options(*$options.collect { |ary| ary[0..2] })
72 parser.each_option do |name, arg|
82 $source = arg.sub(%r|/$|, '')
83 if !File.directory?($source)
84 die "Argument to --source must be a directory"
87 $dest = arg.sub(%r|/$|, '')
88 if File.exists?($dest) && !File.directory?($dest)
89 die "If --destination exists, it must be a directory"
92 system("rm -rf #{$dest}")
97 when '--verbose-level'
98 $verbose_level = arg.to_i
108 die 'Missing --source parameter.'
111 die 'Missing --destination parameter.'
115 def check_installation
119 %w(convert transcode exif).each { |prg|
120 if !system("which #{prg} >/dev/null")
121 die "The `#{prg}' program is typically needed. Re-run with --no-check if you're sure you're fine without it."
126 def replace_line(surround, keyword, line)
128 contents = eval "$#{keyword}"
129 line.sub!(/#{surround}#{keyword}#{surround}/, contents)
131 die "No `#{keyword}' found for substitution"
135 def build_html_skeleton
136 theme_file = File.open("themes/#{$theme}/skeleton.html").readlines
137 msg 2, "Read theme `#{$theme}'"
138 for line in theme_file
139 while line =~ /~~~(\w+)~~~/
140 replace_line('~~~', $1, line)
152 `find #{$source} -type d`.each { |dir|
154 msg 2, "Examining #{dir}..."
155 images = Dir["#{dir}/*.{jpg,JPG,jpeg,JPEG,gif,GIF,bmp,BMP,png,PNG}"]
156 msg 2, "\t#{images.length} images"
157 videos = Dir["#{dir}/*.{mov,MOV,avi,AVI,mpg,MPG,mpeg,MPEG,wmv,WMV,asx,ASX}"]
158 msg 2, "\t#{videos.length} videos"
160 dest_dir = dir.sub(/^#{Regexp.quote($source)}/, $dest)
161 system("mkdir -p #{dest_dir}")
162 msg 2, "Outputting in #{dest_dir}..."
166 dest_img = img.sub(/^#{Regexp.quote($source)}/, $dest).
167 sub(/\.[^\.]+$/, '') + '-704.jpg'
168 final_images << File.basename(dest_img)
169 if !File.exists?(dest_img)
171 orientation = `exif #{img}`.detect { |line| line =~ /^Orientation/ }
172 if orientation =~ /right - top/
173 convert_options += '-rotate 90 '
175 if orientation =~ /left - bottom/
176 convert_options += '-rotate -90 '
178 sys "#{$convert} #{convert_options}-geometry 704x528 #{img} #{dest_img}"
182 html = $skeleton.collect { |l| l.clone }
183 images4js = final_images.collect { |img| "\"#{img}\"" }.join(', ')
185 i.sub!(/~~images~~/, images4js)
186 i.sub!(/~~title~~/, File.basename(dir))
189 File.open("#{dest_dir}/index.html", "w").write(html)
196 $skeleton = build_html_skeleton