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>
14 # Copyright (c) 2007 Stephane Fillod
16 # This software may be freely redistributed under the terms of the GNU
17 # public license version 2.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 # <directory><tab><title>
26 # <picfilename><tab><title><tab><texte>
27 # <directory>".captions.txt"
28 # <picfilename><tab><title><tab><texte>
29 # <directory>/<picfilename>".txt"
32 # Since Booh requires UTF-8, you may need to convert caption files:
33 # $ recode ISO-8859-1..UTF-8 captions.txt
44 require 'booh/rexml/document'
47 require 'booh/booh-lib'
52 [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
54 [ '--config', '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
56 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
59 #- default values for some globals
64 puts _("Usage: %s [OPTION]...") % File.basename($0)
66 printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
71 parser = GetoptLong.new
72 parser.set_options(*$options.collect { |ary| ary[0..2] })
74 parser.each_option do |name, arg|
81 if File.readable?(arg)
82 $xmldoc = REXML::Document.new File.new(arg)
85 die_ _('Config file does not exist or is unreadable.')
88 when '--verbose-level'
89 $verbose_level = arg.to_i
100 die_ _("Missing --config parameter.")
103 $source = $xmldoc.root.attributes['source']
104 $dest = $xmldoc.root.attributes['destination']
107 def utf8_and_entities(string)
108 return utf8(string).gsub('à', 'à').
109 gsub('ç', 'ç').
110 gsub('ô', 'ô').
111 gsub('é', 'é').
112 gsub('ê', 'ê').
113 gsub('è', 'è').
114 gsub('È', 'È').
115 gsub('î', 'î').
118 gsub('ù', 'ù').
122 def parse_album_captionstxt(filepath)
124 contents = File.open(filepath).readlines
128 if line =~ /^(.*)\t(.*)\t(.*)/
129 out[:legends][$1] = $2 + "\n" + $3
130 elsif line =~ /^(.*)\t(.*)/
131 out[:legends][$1] = $2
142 `find #{$source} -type d`.split("\n").sort.each { |dir|
144 msg 2, _("Handling %s from config list...") % dir
146 if !infos = parse_album_captionstxt("#{dir}/captions.txt")
150 #- place xml document on proper node
151 xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
153 #if infos.has_key?(:title)
154 # type = find_subalbum_info_type(xmldir)
155 # xmldir.add_attribute("#{type}-caption", utf8_and_entities(infos[:title]))
158 xmldir.elements.each { |element|
159 if %w(image video).include?(element.name)
160 if infos[:legends].has_key?(element.attributes['filename'])
161 element.add_attribute('caption', utf8_and_entities(infos[:legends][element.attributes['filename']]))
173 ios = File.open("#{$conffile}.merged", "w")