slitaz-tools view boxes/burn-box @ rev 983

tazbox video: allow window resize
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 26 13:51:02 2016 +0200 (2016-05-26)
parents 3be081525506
children 491239328786
line source
1 #!/bin/sh
2 #
3 # Burn-box a small front end to cdrkit powered by Yad/GTK. Keep the main
4 # window uncluttered and use a wizard to create audio/video/data CD/DVD.
5 # The main box lets users burn an ISO and audio files from a single directory.
6 #
7 # Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
8 #
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
12 . /lib/libtaz.sh
13 export TEXTDOMAIN='slitaz-boxes' # i18n
16 # LibTaz parser and store options. Burn-box can be used with an ISO image
17 # or an audio directory in option: burn-box --iso=/path/to/image.iso
19 [ "$iso" ] || iso=" "
20 [ "$audio" ] || audio="$HOME"
23 # Internal variables
25 boxopts="--height=300 --width=620"
26 icon='drive-optical'
27 options="-eject -multi"
28 speed=$(fgrep "drive speed" /proc/sys/dev/cdrom/info | cut -f3)
29 tmpdir=$(mktemp -d)
32 #
33 # Functions
34 #
37 # Help and usage
39 usage() {
40 newline; _ 'Burn-box a small front end to cdrkit powered by Yad/GTK.'
41 newline; boldify $(_ 'Usage:')
42 echo " $(basename $0) [$(_n 'command')|$(_n 'option')] [$(_n 'file')]"
44 newline; boldify $(_ 'Commands:')
45 optlist "\
46 wodim-help|-wh $(_n 'Show all Wodim options')
47 iso|-i $(_n 'Burn an ISO image')
48 audio|-a $(_n 'Create and burn an audio CD')
49 blank $(_n 'Erase a RW disk')"
51 newline; boldify $(_ 'Options:')
52 echo "\
53 --iso=$(_n '/path/to/image.iso')
54 --audio=$(_n '/path/to/directory')"
56 newline; boldify $(_ 'Examples:')
57 echo "\
58 $(basename $0) iso $(_n '/path/to/image.iso')
59 $(basename $0) --iso=$(_n '/path/to/image.iso')"
60 newline
61 }
64 # Ouput a command to a Yad/GTK box. Usage: cmd | out --title="Title" --tail
66 gtkout() {
67 yad --window-icon=$icon $boxopts \
68 --margins=4 --fontname=monospace \
69 --text-info "$@" --button="gtk-close:1"
70 }
73 # Decode audio files with: decode [file]
75 decode_audio() {
76 _ 'Decoding files from: %s' "$audio"
77 for f in "$audio"/*.*
78 do
79 debug "handling $f"
80 case "$f" in
81 *.wav)
82 cp -f "$f" $tmpdir ;;
83 *.mp3|*.MP3|*.ogg)
84 ext=${f##*.}
85 if [ ! -f "${f%.$ext}.wav" ]; then
86 decode "$f"
87 mv ${f%.$ext}.wav $tmpdir
88 fi ;;
89 esac
90 done
91 }
94 # Burn an ISO image.
96 burn_iso() {
97 if [ "${iso##*.}" != "iso" ]; then
98 _ 'Not an ISO image: "%s"' "$iso"; exit 1
99 fi
100 wodim -v speed=$speed $options "$iso"
101 }
104 # Burn some audio tracks from a directory.
106 burn_audio() {
107 decode_audio
108 echo "TODO: check_size"
109 du -sh $tmpdir
110 wodim -v speed=$speed $options -pad -dao -audio $tmpdir/*.wav
111 rm -rf $tmpdir
112 }
115 # Main GUI box function with pure Yad spec
117 burn_main() {
118 yad --title="$(_ 'Burn-box')" --window-icon=$icon $boxopts \
119 --image=$icon --image-on-top \
120 --text="<b>$(_n 'Burn ISO images and audio files [data in next releases]')</b>" \
121 --form \
122 --field="$(_n 'Drive speed:')" "$speed" \
123 --field="$(_n 'Wodim options:')" " $options" \
124 --field="$(_n 'ISO image:'):FL" "$iso" \
125 --field="$(_n 'Audio files:'):DIR" "$audio" \
126 --button="$(_n 'Wodim help'):$0 wodim-help" \
127 --button="$(_n 'Blank CD'):$0 blank" \
128 --button="$(_n 'Burn'):0" \
129 --button="gtk-close:1"
130 }
133 # Main function
135 burn() {
136 # Store box results
137 main=$(burn_main)
139 # Deal with --button values
140 case $? in
141 0) continue ;;
142 *) exit 0 ;;
143 esac
145 # Get values from $main
146 eval $(echo $main | awk -F'|' \
147 '{printf "speed=\"%s\" options=\"%s\" iso=\"%s\" audio=\"%s\"", $1, $2, $3, $4}')
148 speed=${speed%%,*} # first from comma separated list
150 # Handle ISO image
151 if [ "$iso" != "(null)" ]; then
152 burn_iso 2>&1 | gtkout --title="$(_n 'Burning ISO')" --tail
153 fi
155 # Handle Audio files.
156 if [ "$audio" != "$HOME" ]; then
157 burn_audio 2>&1 | gtkout --title="$(_n 'Burning Audio')" --tail
158 fi
159 }
162 #
163 # Commands
164 #
166 case "$1" in
167 -h|--help)
168 usage ;;
169 wodim-help|-wh)
170 wodim --help 2>&1 | gtkout --title="$(_n 'Wodim Help')" ;;
171 iso|-i)
172 # Let burn an ISO from cmdline: burn-box -i /path/to/image.iso
173 [ "$iso" == " " ] && iso="$2"
174 if [ ! -f "$iso" ]; then
175 _ 'Missing ISO image "%s"' "$iso"; exit 1
176 fi
177 burn_iso ;;
178 audio|-a)
179 # Let create an audio CD from cmdline: burn-box -a /path/to/audio
180 [ "$2" ] && audio="$2"
181 [ "$audio" == "$HOME" ] && unset audio
182 if [ ! -d "$audio" ]; then
183 _ 'Missing audio directory "%s"' "$audio"; exit 1
184 fi
185 burn_audio ;;
186 blank)
187 wodim -v -blank=fast 2>&1 | gtkout --title="$(_n 'Blank disk')" --tail ;;
188 ""|--*)
189 burn ;;
190 *)
191 usage ;;
192 esac
194 exit 0