Debian Codegraph @

gallery1-to-slideshow

raw
1 #!/bin/bash
2 # gallery1-to-slideshow
3 # was gallery2slideshow
4 # Copyright 2003 Scott Dylewski <scott at dylewski.com>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #
20
21 version='0.8.1'
22
23 changes ()
24 {
25 echo 'Changes:
26 0.8.1
27 Escape colons in subtitles
28 0.7.5
29 No changes
30 0.7.4
31 Fixed bug where no pictures were found with new version of gallery 1.5
32 Fixed bug near line 279 with a missing "fi" statement.
33 0.7.3
34 Changed name from gallery2slideshow to gallery1-to-slideshow to avoid
35 confusion... it does not work on gallery v.2.x albums!
36 Add -b background image option
37 Fix for finding all images in album. Thanks Ivan Espinosa!
38 Added a few more quotes around variables to help with spaces in filenames.
39 0.7.2 Another fix to allow newlines in gallery comments
40 These should correctly get translated into \n characters.
41 Strips out <a href=""> and </a> tags also.
42 0.7.0 Fix to not show hidden pictures for gallery v1.4.3-pl1
43 ( thanks Frederic! )
44 Fixed bug when passing html links in subtitle field
45 dvd-slideshow supports duration in fractional seconds.
46 Allow for "." as the album path
47 0.5.2 -i switch not required for album path
48 0.5.0 Added option (-c duration) to do a crossfade between every picture.
49 This script automatically removes ":" and <return> characters
50 from the comment field.
51 0.4 Added default fade in at beginning and out at end
52 0.3 Added extra file checking before processing for better stability
53 from Scott Merrill <skippy at skippy.net> Thanks!!!
54 0.2 Initial release'
55 }
56
57 help ()
58 {
59 echo "gallery1-to-slideshow $version"
60 echo "gallery1-to-slideshow is part of the dvd-slideshow set of tools."
61 echo 'Copyright 2003 Scott Dylewski <scott at dylewski.com>'
62 echo 'http://freshmeat.net/dvdslideshow'
63 echo '
64 gallery1-to-slideshow description:
65 Generates a text file listing of the pictures visible in a given
66 "Gallery" (http://gallery.sourceforge.net) photo album
67 in order to easily pass the information to dvd_slideshow
68
69 Usage: gallery1-to-slideshow [-o <output_directory>] [-t <time_per_picture>]
70 [-b <background image>] [-c duration] <path_to_album>
71
72 Options:
73 path_to_album
74 Path to the album that you want to generate a slideshow for.
75
76 [-o output_directory]
77 Path to the directory where you want to output file written.
78 Default is the current working directory.
79
80 [-t time_per_picture]
81 Number of seconds that the picture will be visible
82 on the dvd movie. You can edit the output file to make
83 changes to specific lines.
84 Default is 5 seconds.
85
86 [-b <background image>]
87 Specify background image to use for slideshow.
88
89 [-c duration]
90 Add a crossfade between every picture for duration seconds.
91
92 -h or -help
93 Prints this help.
94 '
95 }
96
97 if [ $# -lt 1 ]; then
98 help
99 exit 1
100 fi
101
102
103 ## setup initial variables:
104 debug=0 # 1 or 0
105 crossfade=0
106
107 for arg
108 do
109 case "$arg" in
110 -i) shift ; album_path="$1" ; shift ;;
111 -o) shift; output_dir="$1"; shift ;;
112 -t) shift; duration="$1"; shift ;;
113 -c) shift; crossfade=1; crossfade_duration="$1"; shift ;;
114 -h) help ; exit 0 ; shift ;;
115 -?) help ; exit 0 ; shift ;;
116 -help) help ; exit 0 ; shift ;;
117 esac
118 done
119
120 if [ -z "$album_path" ] ; then
121 album_path="$1"
122 fi
123 if [ -z "$album_path" ] ; then
124 echo "[gallery1-to-slideshow] Error: No album specified"
125 exit 1
126 fi
127 if [ -z "$output_dir" ] ; then
128 output_dir="`pwd`"
129 fi
130 if [ -z "$duration" ] ; then
131 duration="5"
132 fi
133
134 ## check_rm checks to see if the file exists before it's deleted:
135 check_rm ()
136 {
137 if [ -f $1 ] ; then
138 rm $1
139 fi
140 }
141
142 cleanup ()
143 {
144 ## clean up temporary files
145 echo "done"
146 }
147
148 forcequit () ## function gets run when we have some sort of forcequit...
149 {
150 ## clean up temporary files
151 cleanup
152 exit 0
153 }
154
155 trap 'forcequit' INT
156 trap 'forcequit' KILL
157 trap 'forcequit' TERM
158
159 # sanity checking
160 # did the user give us a valid input file to work with?
161 if [ ! -f "$album_path" ]; then
162 # it's not a regular file
163 if [ ! -d "$album_path" ]; then
164 # it's not a directory!
165 echo "[gallery1-to-slideshow] Bad input file (-i $album_path)!"
166 exit 1;
167 else
168 # check for '.' path
169 if [ "$album_path" == '.' ]; then
170 # use current directory
171 album_path="`pwd`"
172 fi
173 # it is a directory, so use album.dat
174 echo "[gallery1-to-slideshow] Using album.dat in $album_path";
175 album_file="album.dat";
176 if [ ! -f "$album_path/$album_file" ]; then
177 # there's no album.dat file there!
178 echo "[gallery1-to-slideshow] No such file $album_path/$album_file!";
179 echo "[gallery1-to-slideshow] Aborting!";
180 exit 1;
181 fi
182 fi
183 else
184 # it is a regular file!
185 echo "[gallery1-to-slideshow] ERROR: you must specify a directory name!"
186 exit 1
187 # album=`basename "${album_path}"`;
188 # album_path=`echo $album_path | sed -e "s/$album//"`;
189 fi
190
191 # make sure $album_path has no trailing slash
192 album_path=`echo "$album_path" | sed -e 's/\/$//'`;
193 album=`basename "${album_path}"`;
194
195 if [ -z "$output_dir" ]; then
196 # no output directory specified!
197 echo "[gallery1-to-slideshow] Invalid output destination (-o $output_dir)!";
198 echo "[gallery1-to-slideshow] *** Using $album_path instead.";
199 output_dir=$album_path;
200 fi
201 if [ ! -d "$output_dir" ]; then
202 # I'm sure it was a simple typo.
203 echo "[gallery1-to-slideshow] Invalid output destination (-o $output_dir)!";
204 echo "[gallery1-to-slideshow] *** Using $album_path instead.";
205 output_dir=$album_path;
206 fi
207
208 # make sure $output_dir has no trailing slash
209 output_dir=`echo $output_dir | sed -e 's/\/$//'`;
210
211 ## now let's do some checking to see if the user put in the full path?
212
213 echo "[gallery1-to-slideshow] path=$album_path"
214 echo "[gallery1-to-slideshow] album=$album"
215 echo "[gallery1-to-slideshow] album_file=$album_file"
216 echo "[gallery1-to-slideshow] output_dir=$output_dir"
217
218 outfile="$output_dir/$album".txt
219 echo "[gallery1-to-slideshow] output file=$output_dir/$album".txt
220
221 ## if title is wanted:
222 summary=`awk -F'"title"' '{print $2}' "${album_path}"/album.dat | awk -F'"' '{print $2}'`
223 #gallery_version=`awk -F'"version"' '{print $2}' "${album_path}"/album.dat | awk -F'"' '{print $2}'`
224 pictures=`awk -F'albumitem' '{print NF}' "${album_path}"/photos.dat`
225 echo "#background:1::black" > "$outfile"
226 echo "#background:0::background.jpg" >> "$outfile"
227 echo "fadein:1" >> "$outfile"
228 echo "title:$duration:$album:$summary" >> "$outfile"
229 echo "[gallery1-to-slideshow] title:$duration:$album:$summary"
230 echo "#background:0::black" >> "$outfile"
231 ## else do not make a title.
232
233 ## fade in after title:
234 echo "fadeout:2" >> "$outfile"
235 echo "background:1" >> "$outfile"
236
237 # add music? this makes it easier to just un-comment stuff
238 echo '# remember format is:' >> "$outfile"
239 echo '# musicfile.mp3:audio_track:[fadein:fadein_time:fadeout:fadeout_time]' >> "$outfile"
240 echo "#musicfile.mp3:1:fadein:1:fadeout:5" >> "$outfile"
241
242 echo 'fadein:1' >> "$outfile"
243
244 ## get the total number of pictures:
245 # anybody know a better way to get rid of potential returns?
246 pictures=`awk -F'albumitem' '{print NF}' "${album_path}"/photos.dat`
247 pictures=`echo $pictures | tr [:space:] ' '`
248 # sometimes the pictures string now has a space in-between
249 # this is from someone entering return (^M) characters in their
250 # comments fields
251 total_pictures=0
252 total_lines=0
253 for i in $pictures ; do
254 total_pictures=$(( $total_pictures + $i ))
255 total_lines=$(( $total_lines + 1 ))
256 done
257 total_pictures=$(( $total_pictures - 1 ))
258
259 pictures2=`awk -F'AlbumItem' '{print NF}' "${album_path}"/photos.dat`
260 pictures2=`echo $pictures2 | tr [:space:] ' '`
261 # sometimes the pictures string now has a space in-between
262 # this is from someone entering return (^M) characters in their
263 # comments fields
264 total_pictures2=0
265 total_lines=0
266 for i in $pictures2 ; do
267 total_pictures2=$(( $total_pictures2 + $i ))
268 total_lines=$(( $total_lines + 1 ))
269 done
270 total_pictures2=$(( $total_pictures2 - 1 ))
271
272 #echo "total_pictures=$total_pictures total_pictures2=$total_pictures2"
273
274 # pick the greater of the two methods:
275 if [ "$total_pictures2" -gt "$total_pictures" ] ; then
276 ## Newer versions of gallery use "AlbumItem" instead of "albumitem"
277 newgallery=1
278 # pictures=`awk -F'AlbumItem' '{print NF}' "${album_path}"/photos.dat`
279 total_pictures="$total_pictures2"
280 echo "[gallery1-to-slideshow] new gallery version"
281 else
282 newgallery=0
283 echo "[gallery1-to-slideshow] old gallery version"
284 fi
285 echo "[gallery1-to-slideshow] total pictures=$total_pictures"
286
287 #pictures=$(( $pictures + 1 ))
288
289 ## yeah, this is slow, but not as slow as typing in everything
290 ## from the gallery yourself...
291 j=1
292 for i in `seq 2 $total_pictures`; do
293 ## get rid of potential newlines in comments sections first:
294 if [ "$newgallery" -eq 1 ] ; then
295 albumitem=`cat "$album_path/photos.dat" | tr '\n' '\a' | awk -F'AlbumItem' '{print $'"$i"'}'`
296 else
297 albumitem=`cat "$album_path/photos.dat" | tr '\n' '\a' | awk -F'albumitem' '{print $'"$i"'}'`
298 fi
299 filename[$j]=`echo "${albumitem}" | awk -F'"name"' '{print $2}' | awk -F'"' '{print $2}'`
300 comment[$j]=`echo "${albumitem}" | awk -F'"caption"' '{print $2}' | awk -F':"' '{print $2}' | awk -F'";' '{print $1}' | tr '\a' ' ' | sed -e 's/\r/\\\\n/' | sed -e 's/<a href.*">//' | sed -e 's/<\/a>//' | sed -e 's/\:/\\\:/g'`
301 hidden[$j]=`echo "${albumitem}" | awk -F'"hidden"' '{print $2}' | awk -F';' '{print $2}'`
302 if [ "${hidden[$j]}" == 'N' ] || [ -z "${hidden[$j]}" ] ; then ## only include this picture if it's shown in the gallery
303 new_filename="${album_path}/${filename[$j]}.jpg"
304 echo "[gallery1-to-slideshow] picture $j of $total_pictures"
305 echo "[gallery1-to-slideshow] filename=${new_filename} comment=${comment[$j]}"
306 ## write to file:
307 ## Fix by Ivan Espinosa 1/2006
308 if [ -r "${new_filename}" ] ; then
309 if [ "$j" -ne 1 ] ; then
310 if [ "$crossfade" -eq 1 ] ; then
311 echo "crossfade:$crossfade_duration:" >> "$outfile"
312 fi
313 fi
314 echo "${new_filename}:$duration:${comment[$j]}" >> "$outfile"
315 fi
316 # if [ "$crossfade" -eq 1 ] && [ "$(($i+1))" -lt "$total_pictures" ] ; then
317 # echo "crossfade:$crossfade_duration:" >> "$outfile"
318 # fi
319 let j=$j+1
320 else
321 echo "[gallery1-to-slideshow] picture $j of $total_pictures Hidden in Gallery"
322 let j=$j+1
323 fi
324 done
325
326 echo ' ' >> "$outfile"
327 echo '# to insert a title slide in the middle of the slideshow, use this:' >> "$outfile"
328 echo '#fadeout:1' >> "$outfile"
329 echo '#background:1' >> "$outfile"
330 echo '#background:1::background.jpg' >> "$outfile"
331 echo '#title:5::Title Text' >> "$outfile"
332 echo '#background:0::black' >> "$outfile"
333 echo '#fadeout:1' >> "$outfile"
334 echo '#fadein:1' >> "$outfile"
335 echo ' ' >> "$outfile"
336
337 ## fade out at end
338 echo "fadeout:1" >> "$outfile"
339 ## stop the music before the final fadeout to the background:
340 echo "silence:1:" >> "$outfile"
341 echo "background:1" >> "$outfile"
342 echo '#fadein:1' >> "$outfile"
343 echo '#background.jpg:1' >> "$outfile"
344
345
346 cleanup
347