slitaz-tools view tinyutils/burnbox @ rev 345

Add mp3,backup,dvd-video,vcd,svcd modes to burnbox
author Rohit Joshi <jozee@slitaz.org>
date Mon May 04 18:54:07 2009 +0000 (2009-05-04)
parents af65458ca488
children cb6c487bb8c3
line source
1 #!/bin/sh
2 #
3 # Gtkdialog box to burn CD or DVD using Wodim with basic options. Burnbox
4 # can burn ISO images, blank rewritable CD or create audio CD with WAV.
5 #
6 # (c) - SliTaz GNU/Linux 2009 - GNU GPL v3
8 # Authors : Christophe Lincoln <pankso@slitaz.org>
9 # Rohit Joshi <jozee@slitaz.org>
10 #
11 VERSION=20090504
12 TMPDIR="/tmp/burn-cd"
15 chk_install()
16 {
17 for pkg in $@
18 do
19 if [ ! -d /var/lib/tazpkg/installed/${pkg} ]; then
20 UNINSTALLED="$UNINSTALLED $pkg"
21 fi
22 done
23 if [ ! "$UNINSTALLED" = "" ] ; then
24 xterm -bg gray93 -fg black -geometry 80x16 -title "INSTALL PACKAGE" \
25 -e "echo -n \"this option depends on $UNINSTALLED Please install and try again\"; sleep 4;"
26 fi
27 }
29 # Display audio cd size.
30 audio_cd_stats()
31 {
32 AUDIO_CD_SIZE=`du -m $TMPDIR | awk '{print $1}'`
33 TRACK_NB=`ls -1 $TMPDIR | wc -l`
34 echo -n "Total tracks: $AUDIO_CD_SIZE Mb"
35 }
37 # Display cd/dvd size.
38 disk_stats()
39 {
40 DISK_SIZE=`du -m $TMPDIR | awk '{print $1}'`
41 TRACK_NB=`ls -1 $TMPDIR | wc -l`
42 echo -n "Total size: $DISK_SIZE Mb"
43 }
45 decode_ogg()
46 {
47 if ls $TMPDIR | grep -q .ogg; then
48 cd $TMPDIR
49 xterm -bg gray93 -fg black -geometry 80x16 -title "Oggdec" \
50 -e 'for i in *.ogg; do oggdec "$i" && rm "$i"; done; sleep 2'
51 fi
52 }
54 decode_mp3()
55 {
57 if ls $TMPDIR | grep -q .mp3; then
58 cd $TMPDIR
59 UNINSTALLED=""
60 chk_install "mpg123"
61 if [ "$UNINSTALLED" = "" ] ; then
62 xterm -bg gray93 -fg black -geometry 80x16 -title "mpg123" \
63 -e 'for file in *.mp3; do
64 mpg123 --rate 44100 --stereo --buffer 3072 --resync -w `basename "$file" .mp3`.wav "$file" && rm "$file";
65 done; sleep 2'
67 fi
68 fi
69 }
71 decode_video()
72 {
73 # convert videos into a VCD/SVCD/DVD compatible mpg video format
74 if ls $TMPDIR | grep -q ".avi\|.mov\|.wmv\|.flv" ; then
75 cd $TMPDIR
76 UNINSTALLED=""
77 chk_install "ffmpeg"
79 if [ "$UNINSTALLED" = "" ] ; then
80 xterm -bg gray93 -fg black -geometry 80x16 -title "ffmpeg" \
81 -e ' echo -n "Select target type (pal-vcd ntsc-vcd pal-svcd ntsc-svcd pal-dvd ntsc-dvd) "; read TARGET_OPTIONS
82 for file in *.avi *.wmv *.mov *.flv; do
83 ext=`echo "${file##*.}"`
84 output_file=`basename "$file" .$ext`.mpg
85 ffmpeg -i "$file" -target "$TARGET_OPTIONS" "$output_file" && rm "$file";
86 done; sleep 2;
87 '
88 fi
89 fi
92 }
94 # convert spaces in filename with _ and remove special characters "()'&" {}\! and translate uppercase to lowercase
95 fix_filename()
96 {
97 ls /tmp/burn-cd/* | while read file
98 do
99 mv "$file" `echo $file | tr ' ' '_' | tr -d '[{}(),\!&]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g' `
100 done
102 }
104 # We must think about " space " between directory/track and
105 # filter directory copy to avoid copying other files than audio.
106 # Only burning non-compressed wav format is supported directly.
108 copy_audio_file()
109 {
110 if ls "$NEW_TRACK" | grep -q .ogg; then
111 cp "${NEW_TRACK%.ogg}.ogg" $TMPDIR
112 fix_filename
113 decode_ogg
114 elif ls "$NEW_TRACK" | grep -q ".[m\|M][p\|P]3"; then
115 # cp "${NEW_TRACK%.mp3}.mp3" $TMPDIR
116 cp "$NEW_TRACK" "$TMPDIR"
117 fix_filename
118 decode_mp3
119 else
120 cp "${NEW_TRACK%.wav}.wav" $TMPDIR
121 fi
122 }
125 copy_audio_dir()
126 {
128 for i in .wav .ogg .mp3
129 do
130 cp "$NEW_DIR"/*$i $TMPDIR 2>/dev/null
131 done
132 fix_filename
133 decode_ogg
134 decode_mp3
135 }
137 # Only burning mpg video format is supported directly. MPEG-1 video for vcd and MPEG-2 for svcd and dvd
138 copy_video_file()
139 {
140 if ls "$NEW_TRACK" | grep -q ".mpg\|.mpeg"; then
141 cp "${NEW_TRACK%.mp*}.mpg" $TMPDIR
142 elif ls "$NEW_TRACK" | grep -q ".avi\|.mov\|.wmv\|.flv"; then
143 ext=`echo "${NEW_TRACK##*.}"`
144 cp "${NEW_TRACK%.$ext}.$ext" $TMPDIR
145 fix_filename
146 if "$CHECKBOX_DECODE" ; then decode_video ; fi
147 else
148 echo "mpg format supported"
149 fi
150 }
152 copy_video_dir()
153 {
154 for i in .mpg .avi .mov .wmv .mpeg .flv
155 do
156 cp "$NEW_DIR"/*$i $TMPDIR 2>/dev/null
157 done
158 fix_filename
159 if "$CHECKBOX_DECODE" ; then decode_video ; fi
160 }
162 copy_file()
163 {
164 case "$BURN_MODE" in
165 audio-cd)
166 copy_audio_file ;;
167 vcd|svcd|video-dvd)
168 copy_video_file ;;
169 *)
170 cp "$NEW_TRACK" $TMPDIR ; fix_filename ;;
171 esac
173 }
175 copy_dir()
176 {
177 case "$BURN_MODE" in
178 audio-cd)
179 copy_audio_dir ;;
180 vcd|svcd|video-dvd)
181 copy_video_dir ;;
182 *)
183 cp "$NEW_DIR" $TMPDIR 2>/dev/null
184 fix_filename ;;
185 esac
186 }
187 # =====ISO=====
188 burn_iso()
189 {
190 xterm -bg gray93 -fg black -geometry 80x16 -title "Wodim" \
191 -e "wodim -v speed=$SPEED dev=$DEVICE $OPTIONS $ISO_IMAGE; sleep 4"
192 }
193 # =====AUDIO=====
194 # Use -pad to avoid file size error.
195 burn_audio()
196 {
197 UNINSTALLED=""
198 chk_install "cdrkit"
199 if [ "$UNINSTALLED" = "" ] ; then
200 xterm -bg gray93 -fg black -geometry 80x16 -title "Wodim:AUDIO" \
201 -e " echo \"BURN TYPE SELECTED = $BURN_MODE \"; sleep 1;
202 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao -audio $TMPDIR/*.wav; sleep 4
203 "
204 fi
205 }
206 # =====DATA=====
207 burn_cddata()
208 {
209 UNINSTALLED=""
210 chk_install "cdrkit"
211 if [ "$UNINSTALLED" = "" ] ; then
212 xterm -bg gray93 -fg black -geometry 80x16 -title "Wodim:CD DATA" \
213 -e " echo \"BURN TYPE SELECTED = $BURN_MODE \"; sleep 1;
214 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao -data $TMPDIR/*; sleep 4
215 "
216 fi
217 }
219 burn_dvddata()
220 {
221 UNINSTALLED=""
222 chk_install "dvd+rw-tools"
223 if [ "$UNINSTALLED" = "" ] ; then
224 xterm -bg gray93 -fg black -geometry 80x16 -title "growisofs:DVD DATA" \
225 -e " echo \"BURN TYPE SELECTED = $BURN_MODE \"; sleep 1;
226 # no iso-file available
227 growisofs -dvd-compat -speed=$SPEED -pad -J -r -f -Z $DEVICE $TMPDIR/*; sleep 4
228 "
229 fi
230 }
232 # ====VIDEO=====
233 burn_dvdvideo()
234 {
235 UNINSTALLED=""
236 chk_install "dvd+rw-tools"
238 # current assumption: compatible dvd-video format
239 if [ "$UNINSTALLED" = "" ] ; then
240 xterm -bg gray93 -fg black -geometry 80x16 -title "growisofs:DVD VIDEO" \
241 -e " echo \"BURN TYPE SELECTED = $BURN_MODE\"; sleep 1;
242 growisofs -dvd-video -udf -pad -J -r -f -Z $DEVICE -speed=$SPEED $TMPDIR/*; sleep 2
243 "
244 fi
245 }
246 burn_vcd()
247 {
248 UNINSTALLED=""
249 chk_install "vcdimager"
250 if [ "$UNINSTALLED" = "" ] ; then
251 mkdir -p $TMPDIR/vcd
252 xterm -bg gray93 -fg black -geometry 80x16 -title "vcdimager:VCD" \
253 -e " echo \"BURN TYPE SELECTED = $BURN_MODE $UNINSTALLED \"; sleep 1;
254 vcdimager -t vcd2 -l VCD -c $TMPDIR/vcd/vcd.cue -b $TMPDIR/vcd/vcd.bin $TMPDIR/*.mpg; sleep 2;
255 # cdrdao write --device $DEVICE $TMPDIR/vcd/vcd.cue; sleep 2
256 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao cuefile=$TMPDIR/vcd/vcd.cue ; sleep 2
257 "
258 fi
260 }
262 burn_svcd()
263 {
264 UNINSTALLED=""
265 chk_install "vcdimager"
266 if [ "$UNINSTALLED" = "" ] ; then
267 mkdir -p $TMPDIR/svcd
268 xterm -bg gray93 -fg black -geometry 80x16 -title "vcdimager:SVCD" \
269 -e " echo \"BURN TYPE SELECTED = $BURN_MODE\"
270 vcdimager -t svcd -l SVCD -c $TMPDIR/svcd/svcd.cue -b $TMPDIR/svcd/svcd.bin $TMPDIR/*.mpg; sleep 2;
271 # cdrdao write --device $DEVICE $TMPDIR/svcd/svcd.cue; sleep 2;
272 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao cuefile=$TMPDIR/svcd/svcd.cue ; sleep 2
273 "
274 fi
275 }
277 # =====CLONE=====
278 rip_disc()
279 {
280 SUGGESTED="cdrkit-isoinfo"
281 if ! "$CHECKBOX_FOLDER" ; then SAVE_DISC="/tmp/burn-cd" ; fi
282 if [ -d /var/lib/tazpkg/installed/${SUGGESTED} ]; then
283 xterm -bg gray93 -fg black -geometry 80x16 -title "dd" \
284 -e ' echo "RIPPING DISK AT $SAVE_DISC..."
285 COUNT=`isoinfo -d -i $DEVICE | grep "^Volume size is:" | cut -d " " -f 4`
286 BLOCK=`isoinfo -d -i $DEVICE | grep "^Logical block size is:" | cut -d " " -f 5`
287 dd if=$DEVICE of=$SAVE_DISC/image.iso bs=$BLOCK count=$COUNT; sleep 4
288 sleep 2;'
289 else
290 xterm -bg gray93 -fg black -geometry 80x16 -title "dd" \
291 -e ' echo " Though you dont have the cdrkit-extras package installed, \
292 you can still rip but it may be slower"
293 echo -n "would you like to continue (y/N)? : "; read ans
294 if [ "$ans" = "y" ]; then
295 echo "RIPPING DISK AT $SAVE_DISC...."
296 dd if=$DEVICE of=$SAVE_DISC/image.iso;
297 sleep 2;
298 fi
299 '
300 fi
301 if ! "$CHECKBOX_FOLDER" ; then
302 ISO_IMAGE="/tmp/burn-cd/image.iso"
303 xterm -bg gray93 -fg black -geometry 80x16 -title "dd" \
304 -e ' echo -e " ---Please insert EMPTY DISK at $DEVICE ---\n ---press ENTER to continue..." && read close;'
305 burn_iso
306 fi
307 }
309 blank_dvd()
310 {
311 xterm -bg gray93 -fg black -geometry 80x16 -title "growisofs:DVD ERASE" \
312 -e "growisofs -Z $DEVICE=/dev/zero"
313 }
315 burn_disc()
316 {
317 case "$BURN_MODE" in
318 audio*)
319 burn_audio ;;
320 data-cd*)
321 burn_cddata ;;
322 data-dvd*)
323 burn_dvddata;;
324 video*)
325 burn_dvdvideo;;
326 vcd*)
327 burn_vcd;;
328 svcd*)
329 burn_svcd;;
330 esac
332 }
333 # Main GTK interface
334 MAIN_DIALOG='
335 <window title="SliTaz - Burnbox" icon-name="drive-optical">
336 <vbox>
338 <notebook labels="General|ISO image or rip| Burn CD/DVD (Audio,Video,Data)">
340 <vbox>
341 <frame Information>
342 <text>
343 <label>
344 "Burn CD, Video CD and DVD using Wodim, Vcdimager and Growisofs.
346 Audio CD use uncompressed WAV (OGG, MP3 are decoded).
347 VCD/SVCD use MPG files (AVI, FLV, MOV, WMV are decoded).
349 Before burning, please verify device writer settings or add options if needed."
350 </label>
351 </text>
352 </frame>
353 <frame Settings>
354 <hbox>
355 <text use-markup="true">
356 <label>"<b>Device: </b>"</label>
357 </text>
358 <entry>
359 <default>/dev/cdrom</default>
360 <variable>DEVICE</variable>
361 </entry>
362 </hbox>
363 <hbox>
364 <text use-markup="true">
365 <label>"<b>Speed: </b>"</label>
366 </text>
367 <entry>
368 <input>cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3</input>
369 <variable>SPEED</variable>
370 </entry>
371 </hbox>
372 <hbox>
373 <text use-markup="true">
374 <label>"<b>Options: </b>"</label>
375 </text>
376 <entry>
377 <default>-eject -multi</default>
378 <variable>OPTIONS</variable>
379 </entry>
380 <button>
381 <input file icon="help"></input>
382 <action>xterm -sb -bg gray93 -fg black -geometry 95x25 -title "wodim help" -e "wodim --help ; echo -e \"----\nENTER to continue...\" && read close"</action>
383 </button>
384 </hbox>
385 </frame>
386 <frame Blank CD/DVD-RW>
387 <hbox>
388 <text use-markup="true">
389 <label>"<b>Option: </b>"</label>
390 </text>
391 <entry>
392 <variable>BLANK_OPTS</variable>
393 <default>fast</default>
394 </entry>
395 <button>
396 <input file icon="help"></input>
397 <action>xterm -bg gray93 -fg black -geometry 80x15 -title "wodim blank=help" -e "wodim blank=help ; echo -e \"----\nENTER to continue...\" && read close"</action>
398 </button>
399 <button>
400 <label>Blank disk</label>
401 <input file icon="forward"></input>
402 <action>xterm -bg gray93 -fg black -title "Wodim" -e "wodim -v -blank=$BLANK_OPTS dev=$DEVICE; sleep 2"</action>
403 </button>
404 </hbox>
405 </frame>
406 </vbox>
408 <vbox>
409 <frame Select ISO and burn>
411 <text>
412 <label>
413 "
414 You can create or manipulate ISO images with ISO Master utility
415 or use genisoimage from the command line.
416 "
417 </label>
418 </text>
420 <hbox>
421 <text use-markup="true">
422 <label>"<b>ISO path:</b>"</label>
423 </text>
424 <entry>
425 <variable>ISO_IMAGE</variable>
426 </entry>
427 <button>
428 <input file stock="gtk-cdrom"></input>
429 <action type="fileselect">ISO_IMAGE</action>
430 </button>
431 </hbox>'
432 # Burn iso button.
433 MAIN_DIALOG=${MAIN_DIALOG}"
434 <hbox>
435 <button>
436 <label>Burn disk</label>
437 <input file icon=\"forward\"></input>
438 <action>$0 burn_iso</action>
439 </button>
440 </hbox>"
441 # Backup CD
442 MAIN_DIALOG=${MAIN_DIALOG}'
443 </frame>
444 <frame Select CD/DVD-RW and rip>
445 <text>
446 <label>
447 "You can also clone or rip a CD/DVD. Just specify the path and click burn disk or use dd from the command line. Input is taken from the DEVICE settings
448 "
449 </label>
450 </text>
451 <checkbox>
452 <label>Save output in folder (Unselect to backup on disc) </label>
453 <variable>CHECKBOX_FOLDER</variable>
454 <default>true</default>
455 <action>if true enable:SAVE_DISC</action>
456 <action>if true enable:OPENBUTTON</action>
457 <action>if false disable:SAVE_DISC</action>
458 <action>if false disable:OPENBUTTON</action>
459 </checkbox>
460 <hbox>
461 <text use-markup="true">
462 <label>"<b>Output CD/DVD rip at:</b>"</label>
463 </text>
464 <entry accept="directory">
465 <label>Select a folder to save cloned disk to</label>
466 <variable>SAVE_DISC</variable>
467 </entry>
468 <button>
469 <input file stock="gtk-open"></input>
470 <variable>OPENBUTTON</variable>
471 <action type="fileselect">SAVE_DISC</action>
472 </button>
473 </hbox>
474 '
475 # Burn backup button.
476 MAIN_DIALOG=${MAIN_DIALOG}"
477 <hbox>
478 <button>
479 <label>Burn disk</label>
480 <input file icon=\"forward\"></input>
481 <action>$0 rip_disc</action>
482 </button>
483 </hbox>"
484 MAIN_DIALOG=${MAIN_DIALOG}'
485 </frame>
487 </vbox>
488 <vbox>
489 <tree icon_name="audio-x-generic">
490 <width>500</width><height>200</height>
491 <variable>TRACKS_LIST</variable>
492 <label>Track name (Double-click to remove a track)</label>
493 <input>ls -1 /tmp/burn-cd</input>
494 <action>rm "/tmp/burn-cd/$TRACKS_LIST"</action>
495 <action>refresh:TRACKS_LIST</action>
496 <action>refresh:TRACKS_SIZE</action>
497 </tree>'
498 # Select burn audio-cd, data-cd, dvd-video or vcd/svcd
499 MAIN_DIALOG=${MAIN_DIALOG}'
500 <frame>
501 <hbox>
502 <text>
503 <label> Burn type: </label>
504 </text>
505 <combobox>'
506 tmp2="${MAIN_DIALOG}"
507 for i in audio-cd data-cd data-dvd video-dvd vcd svcd; do
508 [ "$i" = "$BURN_MODE" ] || tmp2="$tmp2<item>$i</item>"
509 done
510 tmp3='
511 <variable>BURN_MODE</variable>
512 </combobox>
513 <checkbox>
514 <label> Enable decoding video</label>
515 <variable>CHECKBOX_DECODE</variable>
516 <default>true</default>
517 </checkbox>
518 </hbox>
519 '
520 MAIN_DIALOG="$tmp2$tmp3"
521 # Select, add and burn audio buttons.
522 MAIN_DIALOG=${MAIN_DIALOG}"
523 <hbox>
524 <text>
525 <label> File: </label>
526 </text>
527 <entry accept=\"filename\">
528 <label>Select an Audio/Video/data track</label>
529 <variable>NEW_TRACK</variable>
530 </entry>
531 <button>
532 <input file stock=\"gtk-open\"></input>
533 <action type=\"fileselect\">NEW_TRACK</action>
534 </button>
535 <button>
536 <label>Add</label>
537 <input file stock=\"gtk-add\"></input>
538 <action>$0 copy_file</action>
539 <action>refresh:TRACKS_LIST</action>
540 <action>refresh:TRACKS_SIZE</action>
541 </button>
542 </hbox>
543 <hbox>
544 <text>
545 <label> Folder:</label>
546 </text>
547 <entry accept=\"directory\">
548 <label>Select an Audio/Video/Data track</label>
549 <variable>NEW_DIR</variable>
550 </entry>
551 <button>
552 <input file stock=\"gtk-open\"></input>
553 <action type=\"fileselect\">NEW_DIR</action>
554 </button>
555 <button>
556 <label>Add</label>
557 <input file stock=\"gtk-add\"></input>
558 <action>$0 copy_dir</action>
559 <action>refresh:TRACKS_LIST</action>
561 <action>refresh:TRACKS_SIZE</action>
562 </button>
563 </hbox>"
565 MAIN_DIALOG=${MAIN_DIALOG}"
566 <hbox>
567 <text>
568 <variable>TRACKS_SIZE</variable>
569 <input>$0 audio_cd_stats</input>
570 </text>
571 <button>
572 <label>Clean</label>
573 <input file stock=\"gtk-clear\"></input>
574 <action>rm -rf $TMPDIR/*</action>
575 <action>refresh:TRACKS_LIST</action>
576 <action>refresh:TRACKS_SIZE</action>
577 <action>clear:NEW_TRACK</action>
578 <action>clear:NEW_DIR</action>
579 </button>
580 <button>
581 <label>Burn disk</label>
582 <input file icon=\"forward\"></input>
583 <action>$0 burn_disc</action>
584 </button>
585 </hbox>
586 </frame>
587 </vbox> "
588 #
589 #
590 # tmp3=
591 export MAIN_DIALOG=${MAIN_DIALOG}'
593 </notebook>
595 <hbox>
596 <button>
597 <label>Exit</label>
598 <input file icon="exit"></input>
599 <action type="exit">Exit</action>
600 </button>
601 </hbox>
603 </vbox>
604 </window>
605 '
607 # Script can be called with an arg to exec a function.
608 if [ -n "$1" ]; then
609 $1
610 else
611 mkdir -p $TMPDIR
612 gtkdialog --center --program=MAIN_DIALOG >/dev/null
613 rm -rf $TMPDIR
614 fi
616 exit 0