History

use printf instead of echo -e (POSIX-compliance fix)

Serge Zirukin committed 16 years ago

Commit 0b874a31 parent bc944421 file · +49 −49Browse files

Unified · Split

split2flac.sh+49−49
@@ -1,4 +1,4 @@
1−#!/bin/sh
1+#!/bin/dash
22 # Copyright (c) 2009-2010 Serge "ftrvxmtrx" Ziryukin
33 #
44 # Permission is hereby granted, free of charge, to any person obtaining
@@ -91,9 +91,9 @@ It's better to pass \$cP'-p'\$cZ option to see what will happen when actually sp · 86 unmodified lines
9191 You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration
9292 (output dir, cover image size, etc.) so you won't need to pass a lot of options
9393 every time, just a filename. Script will try to find CUE sheet if it wasn't specified.
94−It also supports internal CUE sheets (FLAC, APE and WV)."
94+It also supports internal CUE sheets (FLAC, APE and WV).\n"
9595
96−msg="echo -e"
96+msg="printf"
9797
9898 emsg () {
9999 $msg "${cR}$1${cZ}"
@@ -136,15 +136,15 @@ while [ "$1" ]; do · 36 unmodified lines
136136 -nocolors) NOCOLORS=1; update_colors;;
137137 -s) SAVE=1;;
138138 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;
139− -v|--version) $msg "split2${FORMAT} version: ${VERSION}"; exit 0;;
140− -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;;
139+ -v|--version) $msg "split2${FORMAT} version: ${VERSION}\n"; exit 0;;
140+ -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1\n"; exit 1;;
141141 *)
142142 if [ "${INPATH}" ]; then
143143 eval "$msg \"${HELP}\""
144− emsg "\nUnknown option $1"
144+ emsg "\nUnknown option $1\n"
145145 exit 1
146146 elif [ ! -r "$1" ]; then
147− emsg "Unable to read $1"
147+ emsg "Unable to read $1\n"
148148 exit 2
149149 else
150150 INPATH="$1"
@@ -162,7 +162,7 @@ if [ ${SAVE} -eq 1 ]; then · 11 unmodified lines
162162 echo "REMOVE=${REMOVE}" >> "${CONFIG}"
163163 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"
164164 echo "NOCOLORS=${NOCOLORS}" >> "${CONFIG}"
165− $msg "${cP}Configuration saved$cZ"
165+ $msg "${cP}Configuration saved$cZ\n"
166166 fi
167167
168168 METAFLAC="metaflac --no-utf8-convert"
@@ -180,17 +180,17 @@ case ${FORMAT} in · 11 unmodified lines
180180 mp3) $msg "$msg_format MP3";;
181181 ogg) $msg "$msg_format OGG VORBIS";;
182182 wav) $msg "$msg_format WAVE";;
183− *) emsg "Unknown output format \"${FORMAT}\""; exit 1;;
183+ *) emsg "Unknown output format \"${FORMAT}\"\n"; exit 1;;
184184 esac
185185
186−$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"
186+$msg "\n${cG}Output dir :$cZ ${DIR:?Output directory was not set}\n"
187187
188188 # splits a file
189189 split_file () {
190190 FILE="$1"
191191
192192 if [ ! -r "${FILE}" ]; then
193− emsg "Can not read the file"
193+ emsg "Can not read the file\n"
194194 return 1
195195 fi
196196
@@ -224,12 +224,12 @@ split_file () { · 27 unmodified lines
224224 fi
225225
226226 if [ "${CUESHEET}" ]; then
227− $msg "${cP}Found internal cue sheet$cZ"
227+ $msg "${cP}Found internal cue sheet$cZ\n"
228228 CUE="${TMPCUE}"
229229 echo "${CUESHEET}" > "${CUE}"
230230
231231 if [ $? -ne 0 ]; then
232− emsg "Unable to save internal cue sheet"
232+ emsg "Unable to save internal cue sheet\n"
233233 return 1
234234 fi
235235 else
@@ -241,22 +241,22 @@ split_file () { · 5 unmodified lines
241241
242242 # print cue sheet filename
243243 if [ -z "${CUE}" ]; then
244− emsg "No cue sheet"
244+ emsg "No cue sheet\n"
245245 return 1
246246 fi
247247
248248 if [ "${CHARSET}" ]; then
249− $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"
249+ $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ\n"
250250 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
251251 if [ $? -ne 0 ]; then
252− emsg "Unable to convert cue sheet from ${CHARSET} to utf-8"
252+ emsg "Unable to convert cue sheet from ${CHARSET} to utf-8\n"
253253 return 1
254254 fi
255255 CUE="${TMPCUE}"
256256 echo "${CUESHEET}" > "${CUE}"
257257
258258 if [ $? -ne 0 ]; then
259− emsg "Unable to save converted cue sheet"
259+ emsg "Unable to save converted cue sheet\n"
260260 return 1
261261 fi
262262 fi
@@ -286,16 +286,16 @@ split_file () { · 23 unmodified lines
286286 fi
287287 fi
288288
289− $msg "${cG}Cue sheet :$cZ ${CUE}"
290− $msg "${cG}Cover image :$cZ ${PIC:-not set}"
289+ $msg "${cG}Cue sheet :$cZ ${CUE}\n"
290+ $msg "${cG}Cover image :$cZ ${PIC:-not set}\n"
291291
292292 # file removal warning
293293 if [ ${REMOVE} -eq 1 ]; then
294294 msg_removal="\n${cR}Also remove original"
295295 if [ ${FORCE} -eq 1 ]; then
296− $msg "$msg_removal (WITHOUT ASKING)$cZ"
296+ $msg "$msg_removal (WITHOUT ASKING)$cZ\n"
297297 else
298− $msg "$msg_removal if user says 'y'$cZ"
298+ $msg "$msg_removal if user says 'y'$cZ\n"
299299 fi
300300 fi
301301
@@ -305,9 +305,9 @@ split_file () { · 3 unmodified lines
305305 TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)
306306
307307 if [ -z "${TRACKS_NUM}" ]; then
308− emsg "Failed to get number of tracks from CUE sheet."
309− emsg "There may be an error in the sheet."
310− emsg "Running ${GETTAG} %N \"${CUE}\" produces this:"
308+ emsg "Failed to get number of tracks from CUE sheet.\n"
309+ emsg "There may be an error in the sheet.\n"
310+ emsg "Running ${GETTAG} %N \"${CUE}\" produces this:\n"
311311 ${GETTAG} %N "${CUE}"
312312 return 1
313313 fi
@@ -326,15 +326,15 @@ split_file () { · 12 unmodified lines
326326 fi
327327 fi
328328
329− $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}"
330− $msg "${cG}Album :$cZ ${TAG_ALBUM}"
329+ $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}\n"
330+ $msg "${cG}Album :$cZ ${TAG_ALBUM}\n"
331331 if [ "${TAG_GENRE}" ]; then
332− $msg "${cG}Genre :$cZ ${TAG_GENRE}"
332+ $msg "${cG}Genre :$cZ ${TAG_GENRE}\n"
333333 fi
334334 if [ "${TAG_DATE}" ]; then
335− $msg "${cG}Year :$cZ ${TAG_DATE}"
335+ $msg "${cG}Year :$cZ ${TAG_DATE}\n"
336336 fi
337− $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n"
337+ $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n\n"
338338
339339 # prepare output directory
340340 OUT="${DIR}"
@@ -353,14 +353,14 @@ split_file () { · 12 unmodified lines
353353 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
354354 fi
355355
356− $msg "${cP}Saving tracks to $cZ\"${OUT}\""
356+ $msg "${cP}Saving tracks to $cZ\"${OUT}\"\n"
357357
358358 if [ ${DRY} -ne 1 ]; then
359359 # create output dir
360360 mkdir "${OUT}"
361361
362362 if [ $? -ne 0 -a ${NOSUBDIRS} -ne 1 ]; then
363− emsg "Failed to create output directory (already split?)"
363+ emsg "Failed to create output directory (already split?)\n"
364364 return 1
365365 fi
366366
@@ -370,14 +370,14 @@ split_file () { · 3 unmodified lines
370370 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
371371 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
372372 wav) ENC="wav";;
373− *) emsg "Unknown output format ${FORMAT}"; exit 1;;
373+ *) emsg "Unknown output format ${FORMAT}\n"; exit 1;;
374374 esac
375375
376376 # split to tracks
377377 cuebreakpoints "${CUE}" 2>/dev/null | \
378378 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
379379 if [ $? -ne 0 ]; then
380− emsg "Failed to split"
380+ emsg "Failed to split\n"
381381 return 1
382382 fi
383383
@@ -387,14 +387,14 @@ split_file () { · 3 unmodified lines
387387 if [ $? -eq 0 ]; then
388388 PIC="${TMPPIC}"
389389 else
390− $msg "${cR}Failed to convert cover image$cZ"
390+ $msg "${cR}Failed to convert cover image$cZ\n"
391391 unset PIC
392392 fi
393393 fi
394394 fi
395395
396396 # set tags and rename
397− $msg "\n${cP}Setting tags$cZ"
397+ $msg "\n${cP}Setting tags$cZ\n"
398398
399399 i=1
400400 while [ $i -le ${TRACKS_NUM} ]; do
@@ -403,14 +403,14 @@ split_file () { · 2 unmodified lines
403403 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
404404 f="${OUT}/${FILE_TRACK}.${FORMAT}"
405405
406− $msg "$i: $cG${TAG_TITLE}$cZ"
406+ $msg "$i: $cG${TAG_TITLE}$cZ\n"
407407
408408 if [ ${NORENAME} -ne 1 ]; then
409409 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
410410 if [ ${DRY} -ne 1 ]; then
411411 mv "$f" "${FINAL}"
412412 if [ $? -ne 0 ]; then
413− emsg "Failed to rename track file"
413+ emsg "Failed to rename track file\n"
414414 return 1
415415 fi
416416 fi
@@ -514,18 +514,18 @@ split_file () { · 97 unmodified lines
514514 ;;
515515
516516 *)
517− emsg "Unknown output format ${FORMAT}"
517+ emsg "Unknown output format ${FORMAT}\n"
518518 return 1
519519 ;;
520520 esac
521521
522522 if [ ${RES} -ne 0 ]; then
523− emsg "Failed to set tags for track"
523+ emsg "Failed to set tags for track\n"
524524 return 1
525525 fi
526526 fi
527527
528− $msg " -> ${cP}${FINAL}$cZ"
528+ $msg " -> ${cP}${FINAL}$cZ\n"
529529
530530 i=$(($i + 1))
531531 done
@@ -553,12 +553,12 @@ split_collection () { · 21 unmodified lines
553553 NUM_FAILED=0
554554
555555 while read -r FILE; do
556− $msg "$cG>> $cC\"${FILE}\"$cZ"
556+ $msg "$cG>> $cC\"${FILE}\"$cZ\n"
557557 unset PIC CUE
558558 split_file "${FILE}"
559559
560560 if [ ! $? -eq 0 ]; then
561− emsg "Failed to split \"${FILE}\""
561+ emsg "Failed to split \"${FILE}\"\n"
562562 echo "${FILE}" >> "${FAILED}"
563563 NUM_FAILED=$((${NUM_FAILED} + 1))
564564 fi
@@ -567,11 +567,11 @@ split_collection () { · 2 unmodified lines
567567 done
568568
569569 if [ ${NUM_FAILED} -ne 0 ]; then
570− emsg "${NUM_FAILED} file(s) failed to split (already splited?):"
571− $msg "${cR}"
570+ emsg "${NUM_FAILED} file(s) failed to split (already split?):\n"
571+ $msg "${cR}\n"
572572 sort "${FAILED}" -o "${FAILED}"
573573 cat "${FAILED}"
574− emsg "\nThese files are also listed in ${FAILED}."
574+ emsg "\nThese files are also listed in ${FAILED}.\n"
575575 return 1
576576 fi
577577
@@ -586,22 +586,22 @@ split_dir () { · 8 unmodified lines
586586
587587 if [ -d "${INPATH}" ]; then
588588 if [ ! -x "${INPATH}" ]; then
589− emsg "Directory \"${INPATH}\" is not accessible"
589+ emsg "Directory \"${INPATH}\" is not accessible\n"
590590 exit 2
591591 fi
592− $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n"
592+ $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n\n"
593593 split_dir "${INPATH}"
594594 elif [ "${INPATH}" ]; then
595595 split_file "${INPATH}"
596596 else
597− emsg "No input filename given. Use -h for help."
597+ emsg "No input filename given. Use -h for help.\n"
598598 exit 1
599599 fi
600600
601601 # exit code of split_dir or split_file
602602 STATUS=$?
603603
604−$msg "\n${cP}Finished$cZ"
604+$msg "\n${cP}Finished$cZ\n"
605605
606606 if [ ${STATUS} -ne 0 ]; then
607607 exit 3

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t