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-2006 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 require 'booh/rexml/document'
33 require 'booh/booh-lib'
38 [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
40 [ '--config', '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
42 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
45 #- default values for some globals
50 puts _("Usage: %s [OPTION]...") % File.basename($0)
52 printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
57 parser = GetoptLong.new
58 parser.set_options(*$options.collect { |ary| ary[0..2] })
60 parser.each_option do |name, arg|
67 if File.readable?(arg)
68 $xmldoc = REXML::Document.new File.new(arg)
71 die_ _('Config file does not exist or is unreadable.')
74 when '--verbose-level'
75 $verbose_level = arg.to_i
86 die_ _("Missing --config parameter.")
89 $source = $xmldoc.root.attributes['source']
90 $dest = $xmldoc.root.attributes['destination']
93 def utf8_and_entities(string)
94 return utf8(string).gsub('à', 'à').
95 gsub('ç', 'ç').
97 gsub('é', 'é').
99 gsub('è', 'è').
100 gsub('È', 'È').
101 gsub('î', 'î').
104 gsub('ù', 'ù').
108 def parse_webalbum_indextxt(filepath)
110 contents = File.open(filepath).readlines
117 elsif line =~ /^\s*TITLE\s*=\s*(.*)/
119 elsif line =~ /^\s*ABSTRACT\s*=\s*(.*)/
121 elsif line =~ /^\s*IMAGE_LEGEND\s*=\s*(.*)/
123 elsif line =~ /^\s*IMAGE_FILE\s*=\s*(.*)/
124 out[:legends][$1] = legend
135 `find #{$source} -type d`.split("\n").sort.each { |dir|
137 msg 2, _("Handling %s from config list...") % dir
139 if !infos = parse_webalbum_indextxt("#{dir}/index.txt")
143 #- place xml document on proper node
144 xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
146 if infos.has_key?(:title)
147 type = find_subalbum_info_type(xmldir)
148 xmldir.add_attribute("#{type}-caption", utf8_and_entities(infos[:title]))
151 xmldir.elements.each { |element|
152 if %w(image video).include?(element.name)
153 if infos[:legends].has_key?(element.attributes['filename'])
154 element.add_attribute('caption', utf8_and_entities(infos[:legends][element.attributes['filename']]))
166 ios = File.open("#{$conffile}.merged", "w")