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/sh1#!/bin/dash
2# Copyright (c) 2009-2010 Serge "ftrvxmtrx" Ziryukin2# Copyright (c) 2009-2010 Serge "ftrvxmtrx" Ziryukin
3#3#
4# Permission is hereby granted, free of charge, to any person obtaining4# 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
91You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration91You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration
92(output dir, cover image size, etc.) so you won't need to pass a lot of options92(output dir, cover image size, etc.) so you won't need to pass a lot of options
93every time, just a filename. Script will try to find CUE sheet if it wasn't specified.93every time, just a filename. Script will try to find CUE sheet if it wasn't specified.
94It also supports internal CUE sheets (FLAC, APE and WV)."94It also supports internal CUE sheets (FLAC, APE and WV).\n"
95 95
96msg="echo -e"96msg="printf"
97 97
98emsg () {98emsg () {
99 $msg "${cR}$1${cZ}"99 $msg "${cR}$1${cZ}"
@@ -136,15 +136,15 @@ while [ "$1" ]; do · 36 unmodified lines
136 -nocolors) NOCOLORS=1; update_colors;;136 -nocolors) NOCOLORS=1; update_colors;;
137 -s) SAVE=1;;137 -s) SAVE=1;;
138 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;138 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;
139 -v|--version) $msg "split2${FORMAT} version: ${VERSION}"; exit 0;;139 -v|--version) $msg "split2${FORMAT} version: ${VERSION}\n"; exit 0;;
140 -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;;140 -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1\n"; exit 1;;
141 *)141 *)
142 if [ "${INPATH}" ]; then142 if [ "${INPATH}" ]; then
143 eval "$msg \"${HELP}\""143 eval "$msg \"${HELP}\""
144 emsg "\nUnknown option $1"144 emsg "\nUnknown option $1\n"
145 exit 1145 exit 1
146 elif [ ! -r "$1" ]; then146 elif [ ! -r "$1" ]; then
147 emsg "Unable to read $1"147 emsg "Unable to read $1\n"
148 exit 2148 exit 2
149 else149 else
150 INPATH="$1"150 INPATH="$1"
@@ -162,7 +162,7 @@ if [ ${SAVE} -eq 1 ]; then · 11 unmodified lines
162 echo "REMOVE=${REMOVE}" >> "${CONFIG}"162 echo "REMOVE=${REMOVE}" >> "${CONFIG}"
163 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"163 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"
164 echo "NOCOLORS=${NOCOLORS}" >> "${CONFIG}"164 echo "NOCOLORS=${NOCOLORS}" >> "${CONFIG}"
165 $msg "${cP}Configuration saved$cZ"165 $msg "${cP}Configuration saved$cZ\n"
166fi166fi
167 167
168METAFLAC="metaflac --no-utf8-convert"168METAFLAC="metaflac --no-utf8-convert"
@@ -180,17 +180,17 @@ case ${FORMAT} in · 11 unmodified lines
180 mp3) $msg "$msg_format MP3";;180 mp3) $msg "$msg_format MP3";;
181 ogg) $msg "$msg_format OGG VORBIS";;181 ogg) $msg "$msg_format OGG VORBIS";;
182 wav) $msg "$msg_format WAVE";;182 wav) $msg "$msg_format WAVE";;
183 *) emsg "Unknown output format \"${FORMAT}\""; exit 1;;183 *) emsg "Unknown output format \"${FORMAT}\"\n"; exit 1;;
184esac184esac
185 185
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"
187 187
188# splits a file188# splits a file
189split_file () {189split_file () {
190 FILE="$1"190 FILE="$1"
191 191
192 if [ ! -r "${FILE}" ]; then192 if [ ! -r "${FILE}" ]; then
193 emsg "Can not read the file"193 emsg "Can not read the file\n"
194 return 1194 return 1
195 fi195 fi
196 196
@@ -224,12 +224,12 @@ split_file () { · 27 unmodified lines
224 fi224 fi
225 225
226 if [ "${CUESHEET}" ]; then226 if [ "${CUESHEET}" ]; then
227 $msg "${cP}Found internal cue sheet$cZ"227 $msg "${cP}Found internal cue sheet$cZ\n"
228 CUE="${TMPCUE}"228 CUE="${TMPCUE}"
229 echo "${CUESHEET}" > "${CUE}"229 echo "${CUESHEET}" > "${CUE}"
230 230
231 if [ $? -ne 0 ]; then231 if [ $? -ne 0 ]; then
232 emsg "Unable to save internal cue sheet"232 emsg "Unable to save internal cue sheet\n"
233 return 1233 return 1
234 fi234 fi
235 else235 else
@@ -241,22 +241,22 @@ split_file () { · 5 unmodified lines
241 241
242 # print cue sheet filename242 # print cue sheet filename
243 if [ -z "${CUE}" ]; then243 if [ -z "${CUE}" ]; then
244 emsg "No cue sheet"244 emsg "No cue sheet\n"
245 return 1245 return 1
246 fi246 fi
247 247
248 if [ "${CHARSET}" ]; then248 if [ "${CHARSET}" ]; then
249 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"249 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ\n"
250 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)250 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
251 if [ $? -ne 0 ]; then251 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"
253 return 1253 return 1
254 fi254 fi
255 CUE="${TMPCUE}"255 CUE="${TMPCUE}"
256 echo "${CUESHEET}" > "${CUE}"256 echo "${CUESHEET}" > "${CUE}"
257 257
258 if [ $? -ne 0 ]; then258 if [ $? -ne 0 ]; then
259 emsg "Unable to save converted cue sheet"259 emsg "Unable to save converted cue sheet\n"
260 return 1260 return 1
261 fi261 fi
262 fi262 fi
@@ -286,16 +286,16 @@ split_file () { · 23 unmodified lines
286 fi286 fi
287 fi287 fi
288 288
289 $msg "${cG}Cue sheet :$cZ ${CUE}"289 $msg "${cG}Cue sheet :$cZ ${CUE}\n"
290 $msg "${cG}Cover image :$cZ ${PIC:-not set}"290 $msg "${cG}Cover image :$cZ ${PIC:-not set}\n"
291 291
292 # file removal warning292 # file removal warning
293 if [ ${REMOVE} -eq 1 ]; then293 if [ ${REMOVE} -eq 1 ]; then
294 msg_removal="\n${cR}Also remove original"294 msg_removal="\n${cR}Also remove original"
295 if [ ${FORCE} -eq 1 ]; then295 if [ ${FORCE} -eq 1 ]; then
296 $msg "$msg_removal (WITHOUT ASKING)$cZ"296 $msg "$msg_removal (WITHOUT ASKING)$cZ\n"
297 else297 else
298 $msg "$msg_removal if user says 'y'$cZ"298 $msg "$msg_removal if user says 'y'$cZ\n"
299 fi299 fi
300 fi300 fi
301 301
@@ -305,9 +305,9 @@ split_file () { · 3 unmodified lines
305 TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)305 TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)
306 306
307 if [ -z "${TRACKS_NUM}" ]; then307 if [ -z "${TRACKS_NUM}" ]; then
308 emsg "Failed to get number of tracks from CUE sheet."308 emsg "Failed to get number of tracks from CUE sheet.\n"
309 emsg "There may be an error in the sheet."309 emsg "There may be an error in the sheet.\n"
310 emsg "Running ${GETTAG} %N \"${CUE}\" produces this:"310 emsg "Running ${GETTAG} %N \"${CUE}\" produces this:\n"
311 ${GETTAG} %N "${CUE}"311 ${GETTAG} %N "${CUE}"
312 return 1312 return 1
313 fi313 fi
@@ -326,15 +326,15 @@ split_file () { · 12 unmodified lines
326 fi326 fi
327 fi327 fi
328 328
329 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}"329 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}\n"
330 $msg "${cG}Album :$cZ ${TAG_ALBUM}"330 $msg "${cG}Album :$cZ ${TAG_ALBUM}\n"
331 if [ "${TAG_GENRE}" ]; then331 if [ "${TAG_GENRE}" ]; then
332 $msg "${cG}Genre :$cZ ${TAG_GENRE}"332 $msg "${cG}Genre :$cZ ${TAG_GENRE}\n"
333 fi333 fi
334 if [ "${TAG_DATE}" ]; then334 if [ "${TAG_DATE}" ]; then
335 $msg "${cG}Year :$cZ ${TAG_DATE}"335 $msg "${cG}Year :$cZ ${TAG_DATE}\n"
336 fi336 fi
337 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n"337 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n\n"
338 338
339 # prepare output directory339 # prepare output directory
340 OUT="${DIR}"340 OUT="${DIR}"
@@ -353,14 +353,14 @@ split_file () { · 12 unmodified lines
353 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"353 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
354 fi354 fi
355 355
356 $msg "${cP}Saving tracks to $cZ\"${OUT}\""356 $msg "${cP}Saving tracks to $cZ\"${OUT}\"\n"
357 357
358 if [ ${DRY} -ne 1 ]; then358 if [ ${DRY} -ne 1 ]; then
359 # create output dir359 # create output dir
360 mkdir "${OUT}"360 mkdir "${OUT}"
361 361
362 if [ $? -ne 0 -a ${NOSUBDIRS} -ne 1 ]; then362 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"
364 return 1364 return 1
365 fi365 fi
366 366
@@ -370,14 +370,14 @@ split_file () { · 3 unmodified lines
370 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;370 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
371 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;371 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
372 wav) ENC="wav";;372 wav) ENC="wav";;
373 *) emsg "Unknown output format ${FORMAT}"; exit 1;;373 *) emsg "Unknown output format ${FORMAT}\n"; exit 1;;
374 esac374 esac
375 375
376 # split to tracks376 # split to tracks
377 cuebreakpoints "${CUE}" 2>/dev/null | \377 cuebreakpoints "${CUE}" 2>/dev/null | \
378 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"378 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
379 if [ $? -ne 0 ]; then379 if [ $? -ne 0 ]; then
380 emsg "Failed to split"380 emsg "Failed to split\n"
381 return 1381 return 1
382 fi382 fi
383 383
@@ -387,14 +387,14 @@ split_file () { · 3 unmodified lines
387 if [ $? -eq 0 ]; then387 if [ $? -eq 0 ]; then
388 PIC="${TMPPIC}"388 PIC="${TMPPIC}"
389 else389 else
390 $msg "${cR}Failed to convert cover image$cZ"390 $msg "${cR}Failed to convert cover image$cZ\n"
391 unset PIC391 unset PIC
392 fi392 fi
393 fi393 fi
394 fi394 fi
395 395
396 # set tags and rename396 # set tags and rename
397 $msg "\n${cP}Setting tags$cZ"397 $msg "\n${cP}Setting tags$cZ\n"
398 398
399 i=1399 i=1
400 while [ $i -le ${TRACKS_NUM} ]; do400 while [ $i -le ${TRACKS_NUM} ]; do
@@ -403,14 +403,14 @@ split_file () { · 2 unmodified lines
403 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})403 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
404 f="${OUT}/${FILE_TRACK}.${FORMAT}"404 f="${OUT}/${FILE_TRACK}.${FORMAT}"
405 405
406 $msg "$i: $cG${TAG_TITLE}$cZ"406 $msg "$i: $cG${TAG_TITLE}$cZ\n"
407 407
408 if [ ${NORENAME} -ne 1 ]; then408 if [ ${NORENAME} -ne 1 ]; then
409 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"409 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
410 if [ ${DRY} -ne 1 ]; then410 if [ ${DRY} -ne 1 ]; then
411 mv "$f" "${FINAL}"411 mv "$f" "${FINAL}"
412 if [ $? -ne 0 ]; then412 if [ $? -ne 0 ]; then
413 emsg "Failed to rename track file"413 emsg "Failed to rename track file\n"
414 return 1414 return 1
415 fi415 fi
416 fi416 fi
@@ -514,18 +514,18 @@ split_file () { · 97 unmodified lines
514 ;;514 ;;
515 515
516 *)516 *)
517 emsg "Unknown output format ${FORMAT}"517 emsg "Unknown output format ${FORMAT}\n"
518 return 1518 return 1
519 ;;519 ;;
520 esac520 esac
521 521
522 if [ ${RES} -ne 0 ]; then522 if [ ${RES} -ne 0 ]; then
523 emsg "Failed to set tags for track"523 emsg "Failed to set tags for track\n"
524 return 1524 return 1
525 fi525 fi
526 fi526 fi
527 527
528 $msg " -> ${cP}${FINAL}$cZ"528 $msg " -> ${cP}${FINAL}$cZ\n"
529 529
530 i=$(($i + 1))530 i=$(($i + 1))
531 done531 done
@@ -553,12 +553,12 @@ split_collection () { · 21 unmodified lines
553 NUM_FAILED=0553 NUM_FAILED=0
554 554
555 while read -r FILE; do555 while read -r FILE; do
556 $msg "$cG>> $cC\"${FILE}\"$cZ"556 $msg "$cG>> $cC\"${FILE}\"$cZ\n"
557 unset PIC CUE557 unset PIC CUE
558 split_file "${FILE}"558 split_file "${FILE}"
559 559
560 if [ ! $? -eq 0 ]; then560 if [ ! $? -eq 0 ]; then
561 emsg "Failed to split \"${FILE}\""561 emsg "Failed to split \"${FILE}\"\n"
562 echo "${FILE}" >> "${FAILED}"562 echo "${FILE}" >> "${FAILED}"
563 NUM_FAILED=$((${NUM_FAILED} + 1))563 NUM_FAILED=$((${NUM_FAILED} + 1))
564 fi564 fi
@@ -567,11 +567,11 @@ split_collection () { · 2 unmodified lines
567 done567 done
568 568
569 if [ ${NUM_FAILED} -ne 0 ]; then569 if [ ${NUM_FAILED} -ne 0 ]; then
570 emsg "${NUM_FAILED} file(s) failed to split (already splited?):"570 emsg "${NUM_FAILED} file(s) failed to split (already split?):\n"
571 $msg "${cR}"571 $msg "${cR}\n"
572 sort "${FAILED}" -o "${FAILED}"572 sort "${FAILED}" -o "${FAILED}"
573 cat "${FAILED}"573 cat "${FAILED}"
574 emsg "\nThese files are also listed in ${FAILED}."574 emsg "\nThese files are also listed in ${FAILED}.\n"
575 return 1575 return 1
576 fi576 fi
577 577
@@ -586,22 +586,22 @@ split_dir () { · 8 unmodified lines
586 586
587if [ -d "${INPATH}" ]; then587if [ -d "${INPATH}" ]; then
588 if [ ! -x "${INPATH}" ]; then588 if [ ! -x "${INPATH}" ]; then
589 emsg "Directory \"${INPATH}\" is not accessible"589 emsg "Directory \"${INPATH}\" is not accessible\n"
590 exit 2590 exit 2
591 fi591 fi
592 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n"592 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n\n"
593 split_dir "${INPATH}"593 split_dir "${INPATH}"
594elif [ "${INPATH}" ]; then594elif [ "${INPATH}" ]; then
595 split_file "${INPATH}"595 split_file "${INPATH}"
596else596else
597 emsg "No input filename given. Use -h for help."597 emsg "No input filename given. Use -h for help.\n"
598 exit 1598 exit 1
599fi599fi
600 600
601# exit code of split_dir or split_file601# exit code of split_dir or split_file
602STATUS=$?602STATUS=$?
603 603
604$msg "\n${cP}Finished$cZ"604$msg "\n${cP}Finished$cZ\n"
605 605
606if [ ${STATUS} -ne 0 ]; then606if [ ${STATUS} -ne 0 ]; then
607 exit 3607 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