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
39 require 'booh/rexml/document'
42 require 'booh/booh-lib'
47 [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
49 [ '--config', '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
51 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
54 #- default values for some globals
59 puts _("Usage: %s [OPTION]...") % File.basename($0)
61 printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
66 parser = GetoptLong.new
67 parser.set_options(*$options.collect { |ary| ary[0..2] })
69 parser.each_option do |name, arg|
76 if File.readable?(arg)
77 $xmldoc = REXML::Document.new File.new(arg)
80 die_ _('Config file does not exist or is unreadable.')
83 when '--verbose-level'
84 $verbose_level = arg.to_i
95 die_ _("Missing --config parameter.")
98 $source = $xmldoc.root.attributes['source']
99 $dest = $xmldoc.root.attributes['destination']
102 def utf8_and_entities(string)
103 return utf8(string).gsub('à', 'à').
104 gsub('ç', 'ç').
105 gsub('ô', 'ô').
106 gsub('é', 'é').
107 gsub('ê', 'ê').
108 gsub('è', 'è').
109 gsub('È', 'È').
110 gsub('î', 'î').
113 gsub('ù', 'ù').
117 def parse_album_captionstxt(filepath)
119 contents = File.open(filepath).readlines
123 if line =~ /^(.*)\t(.*)\t(.*)/
124 out[:legends][$1] = $2 + "\n" + $3
125 elsif line =~ /^(.*)\t(.*)/
126 out[:legends][$1] = $2
137 `find #{$source} -type d`.sort.each { |dir|
139 msg 2, _("Handling %s from config list...") % dir
141 if !infos = parse_album_captionstxt("#{dir}/captions.txt")
145 #- place xml document on proper node
146 xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
148 #if infos.has_key?(:title)
149 # type = find_subalbum_info_type(xmldir)
150 # xmldir.add_attribute("#{type}-caption", utf8_and_entities(infos[:title]))
153 xmldir.elements.each { |element|
154 if %w(image video).include?(element.name)
155 if infos[:legends].has_key?(element.attributes['filename'])
156 element.add_attribute('caption', utf8_and_entities(infos[:legends][element.attributes['filename']]))
168 ios = File.open("#{$conffile}.merged", "w")