Unified · Split
| @@ -49,37 +49,50 @@ unset CUE · 48 unmodified lines | ||
| 49 | 49 | unset CHARSET |
| 50 | 50 | FORCE=0 |
| 51 | 51 | |
| 52 | −HELP="Usage: split2\${FORMAT}.sh [OPTIONS] FILE | |
| 53 | − -o DIRECTORY * - set output directory | |
| 54 | − -cue FILE - use file as a cue sheet | |
| 55 | − -f FORMAT - use specified output format (current is \${FORMAT}) | |
| 56 | − -c FILE * - use file as a cover image | |
| 57 | − -cuecharset CHARSET - convert cue sheet from CHARSET to UTF-8 (no conversion by default) | |
| 58 | − -nc * - do not set any cover images | |
| 59 | − -cs WxH * - set cover image size (current is \${PIC_SIZE}) | |
| 60 | − -d * - create artist/album subdirs | |
| 61 | − -nd * - do not create any subdirs | |
| 62 | − -r * - rename tracks to include title | |
| 63 | − -nr * - do not rename tracks (numbers only, e.g. '01.\${FORMAT}') | |
| 64 | − -p - dry run | |
| 65 | − -D * - delete original file | |
| 66 | − -nD * - do not remove the original | |
| 67 | − -f - force deletion without asking | |
| 68 | − -s - save configuration to \"\${CONFIG}\" | |
| 52 | +cR="\033[31m" | |
| 53 | +cG="\033[32m" | |
| 54 | +cP="\033[36m" | |
| 55 | +cU="\033[4m" | |
| 56 | +cZ="\033[0m" | |
| 57 | + | |
| 58 | +HELP="${cG}split2flac splits one big ${cU}APE/FLAC/WV$cZ$cG file to ${cU}FLAC/MP3/OGG$cZ$cG tracks with tagging and renaming. | |
| 59 | + | |
| 60 | +Usage: ${cZ}split2${FORMAT}.sh [${cU}OPTIONS$cZ] ${cU}FILE$cZ [${cU}OPTIONS$cZ]$cZ | |
| 61 | + $cG-p$cZ - dry run | |
| 62 | + $cG-o ${cU}DIRECTORY$cZ $cR*$cZ - set output directory | |
| 63 | + $cG-cue ${cU}FILE$cZ - use file as a cue sheet | |
| 64 | + $cG-f ${cU}FORMAT$cZ - use specified output format $cP(current is ${FORMAT})$cZ | |
| 65 | + $cG-c ${cU}FILE$cZ $cR*$cZ - use file as a cover image | |
| 66 | + $cG-cuecharset ${cU}CHARSET$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default) | |
| 67 | + $cG-nc ${cR}*$cZ - do not set any cover images | |
| 68 | + $cG-cs ${cU}WxH$cZ $cR*$cZ - set cover image size $cP(current is ${PIC_SIZE})$cZ | |
| 69 | + $cG-d $cR*$cZ - create artist/album subdirs | |
| 70 | + $cG-nd $cR*$cZ - do not create any subdirs | |
| 71 | + $cG-r $cR*$cZ - rename tracks to include title | |
| 72 | + $cG-nr $cR*$cZ - do not rename tracks (numbers only, e.g. '01.${FORMAT}') | |
| 73 | + $cG-D $cR*$cZ - delete original file | |
| 74 | + $cG-nD $cR*$cZ - do not remove the original | |
| 75 | + $cG-F$cZ - force deletion without asking | |
| 76 | + -s - save configuration to $cP\"${CONFIG}\"$cZ | |
| 69 | 77 | -h - print this message |
| 70 | − -H - print README | |
| 71 | 78 | |
| 72 | −* - option has effect on configuration if -s option passed. | |
| 73 | −NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one. | |
| 74 | −Supported FORMATs: flac, mp3, ogg." | |
| 79 | +$cR*$cZ - option has effect on configuration if $cP'-s'$cZ option passed. | |
| 80 | +${cP}NOTE: $cG'-c some_file.jpg -s'$cP only ${cU}allows$cZ$cP cover images, it doesn't set a default one. | |
| 81 | +${cZ}Supported $cU${cG}FORMATs${cZ}: flac, mp3, ogg. | |
| 75 | 82 | |
| 76 | −README="split2flac splits one big APE/FLAC/WV file to FLAC/MP3/OGG tracks with tagging and renaming. | |
| 77 | −It's better to pass '-p' option to see what will happen when actually splitting tracks. | |
| 78 | −You may want to pass '-s' option for the first run to save default configuration | |
| 83 | +It's better to pass $cP'-p'$cZ option to see what will happen when actually splitting tracks. | |
| 84 | +You may want to pass $cP'-s'$cZ option for the first run to save default configuration | |
| 79 | 85 | (output dir, cover image size, etc.) so you won't need to pass a lot of options |
| 80 | 86 | every time, just a filename. |
| 81 | 87 | Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets." |
| 82 | 88 | |
| 89 | +msg="echo -e" | |
| 90 | + | |
| 91 | +fatal ( ) { | |
| 92 | + $msg "${cR}$1${cZ}" | |
| 93 | + exit 1 | |
| 94 | +} | |
| 95 | + | |
| 83 | 96 | # parse arguments |
| 84 | 97 | while [ "$1" ]; do |
| 85 | 98 | case "$1" in |
| @@ -97,18 +110,15 @@ while [ "$1" ]; do · 11 unmodified lines | ||
| 97 | 110 | -p) DRY=1;; |
| 98 | 111 | -D) REMOVE=1;; |
| 99 | 112 | -nD) REMOVE=0;; |
| 100 | − -f) FORCE=1;; | |
| 113 | + -F) FORCE=1;; | |
| 101 | 114 | -s) SAVE=1;; |
| 102 | − -h) eval "echo \"${HELP}\""; exit 0;; | |
| 103 | − -H) echo "${README}"; exit 0;; | |
| 115 | + -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;; | |
| 104 | 116 | *) |
| 105 | 117 | if [ -r "${FILE}" ]; then |
| 106 | − echo "Unknown option $1" | |
| 107 | − eval "echo \"${HELP}\"" | |
| 108 | − exit 1 | |
| 118 | + eval "$msg \"${HELP}\"" | |
| 119 | + fatal "\nUnknown option $1" | |
| 109 | 120 | elif [ ! -r "$1" ]; then |
| 110 | − echo "Unable to read $1" | |
| 111 | − exit 1 | |
| 121 | + fatal "Unable to read $1" | |
| 112 | 122 | else |
| 113 | 123 | FILE="$1" |
| 114 | 124 | fi;; |
| @@ -120,6 +130,18 @@ METAFLAC="metaflac --no-utf8-convert" · 5 unmodified lines | ||
| 120 | 130 | VORBISCOMMENT="vorbiscomment -R -a" |
| 121 | 131 | ID3TAG="id3tag -2" |
| 122 | 132 | |
| 133 | +# print input filename | |
| 134 | +$msg "${cG}Input file :$cZ ${FILE:?No input filename given. Use -h for help.}$cZ" | |
| 135 | + | |
| 136 | +# check & print output format | |
| 137 | +msg_format="${cG}Output format :$cZ" | |
| 138 | +case ${FORMAT} in | |
| 139 | + flac) $msg "$msg_format FLAC";; | |
| 140 | + mp3) $msg "$msg_format MP3";; | |
| 141 | + ogg) $msg "$msg_format OGG VORBIS";; | |
| 142 | + *) fatal "Unknown output format \"${FORMAT}\"";; | |
| 143 | +esac | |
| 144 | + | |
| 123 | 145 | # search for a cue sheet if not specified |
| 124 | 146 | if [ -z "${CUE}" ]; then |
| 125 | 147 | CUE="${FILE}.cue" |
| @@ -138,8 +160,7 @@ if [ -z "${CUE}" ]; then · 12 unmodified lines | ||
| 138 | 160 | echo "${CUESHEET}" > "${CUE}" |
| 139 | 161 | |
| 140 | 162 | if [ $? -ne 0 ]; then |
| 141 | − echo "Unable to save internal cue sheet" | |
| 142 | − exit 1 | |
| 163 | + fatal "Unable to save internal cue sheet" | |
| 143 | 164 | fi |
| 144 | 165 | else |
| 145 | 166 | unset CUE |
| @@ -148,23 +169,20 @@ if [ -z "${CUE}" ]; then · 2 unmodified lines | ||
| 148 | 169 | fi |
| 149 | 170 | fi |
| 150 | 171 | |
| 151 | −# print some info and check arguments | |
| 152 | −echo "Input file : ${FILE:?No input filename given. Use -h for help.}" | |
| 153 | −echo "Cue sheet : ${CUE:?No cue sheet}" | |
| 172 | +# print cue sheet filename | |
| 173 | +$msg "${cG}Cue sheet :$cZ ${CUE:?No cue sheet}$cZ" | |
| 154 | 174 | |
| 155 | 175 | if [ -n "${CHARSET}" ]; then |
| 156 | − echo "Cue charset : ${CHARSET} -> utf-8" | |
| 176 | + $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ" | |
| 157 | 177 | CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null) |
| 158 | 178 | if [ $? -ne 0 ]; then |
| 159 | − echo "Unable to convert cue sheet from ${CHARSET} to utf-8" | |
| 160 | − exit 1 | |
| 179 | + fatal "Unable to convert cue sheet from ${CHARSET} to utf-8" | |
| 161 | 180 | fi |
| 162 | 181 | CUE="${TMPCUE}" |
| 163 | 182 | echo "${CUESHEET}" > "${CUE}" |
| 164 | 183 | |
| 165 | 184 | if [ $? -ne 0 ]; then |
| 166 | − echo "Unable to save converted cue sheet" | |
| 167 | − exit 1 | |
| 185 | + fatal "Unable to save converted cue sheet" | |
| 168 | 186 | fi |
| 169 | 187 | fi |
| 170 | 188 | |
| @@ -193,16 +211,16 @@ elif [ -z "${PIC}" ]; then · 22 unmodified lines | ||
| 193 | 211 | fi |
| 194 | 212 | fi |
| 195 | 213 | |
| 196 | −echo "Cover image : ${PIC:-not set}" | |
| 197 | −echo "Output dir : ${DIR:?Output directory was not set}" | |
| 214 | +$msg "${cG}Cover image :$cZ ${PIC:-not set}" | |
| 215 | +$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}" | |
| 198 | 216 | |
| 199 | 217 | # file removal warning |
| 200 | 218 | if [ ${REMOVE} -eq 1 ]; then |
| 201 | − echo -n "Also remove original" | |
| 219 | + msg_removal="\n${cR}Also remove original" | |
| 202 | 220 | if [ ${FORCE} -eq 1 ]; then |
| 203 | − echo | |
| 221 | + $msg "$msg_removal (WITHOUT ASKING)$cZ" | |
| 204 | 222 | else |
| 205 | − echo " if user says 'y'" | |
| 223 | + $msg "$msg_removal if user says 'y'$cZ" | |
| 206 | 224 | fi |
| 207 | 225 | fi |
| 208 | 226 | |
| @@ -214,7 +232,7 @@ if [ ${SAVE} -eq 1 ]; then · 5 unmodified lines | ||
| 214 | 232 | echo "NOPIC=${NOPIC}" >> "${CONFIG}" |
| 215 | 233 | echo "REMOVE=${REMOVE}" >> "${CONFIG}" |
| 216 | 234 | echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}" |
| 217 | − echo "Configuration saved" | |
| 235 | + $msg "${cP}Configuration saved$cZ" | |
| 218 | 236 | fi |
| 219 | 237 | |
| 220 | 238 | GETTAG="cueprint -n 1 -t" |
| @@ -236,14 +254,12 @@ if [ -n "${YEAR}" ]; then · 15 unmodified lines | ||
| 236 | 254 | fi |
| 237 | 255 | fi |
| 238 | 256 | |
| 239 | −echo | |
| 240 | −echo "Artist : ${TAG_ARTIST}" | |
| 241 | −echo "Album : ${TAG_ALBUM}" | |
| 257 | +$msg "\n${cG}Artist :$cZ ${TAG_ARTIST}" | |
| 258 | +$msg "${cG}Album :$cZ ${TAG_ALBUM}" | |
| 242 | 259 | if [ -n "${TAG_DATE}" ]; then |
| 243 | − echo "Year : ${TAG_DATE}" | |
| 260 | + $msg "${cG}Year :$cZ ${TAG_DATE}" | |
| 244 | 261 | fi |
| 245 | −echo "Tracks : ${TRACKS_NUM}" | |
| 246 | −echo | |
| 262 | +$msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n" | |
| 247 | 263 | |
| 248 | 264 | # prepare output directory |
| 249 | 265 | OUT="${DIR}" |
| @@ -259,30 +275,28 @@ if [ ${NOSUBDIRS} -ne 1 ]; then · 9 unmodified lines | ||
| 259 | 275 | OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}" |
| 260 | 276 | fi |
| 261 | 277 | |
| 262 | −echo "Saving tracks to \"${OUT}\"" | |
| 278 | +$msg "${cP}Saving tracks to $cZ\"${OUT}\"" | |
| 263 | 279 | |
| 264 | 280 | if [ ${DRY} -ne 1 ]; then |
| 265 | 281 | # create output dir |
| 266 | 282 | mkdir -p "${OUT}" |
| 267 | 283 | |
| 268 | 284 | if [ $? -ne 0 ]; then |
| 269 | − echo "Failed to create output directory" | |
| 270 | − exit 1 | |
| 285 | + fatal "Failed to create output directory" | |
| 271 | 286 | fi |
| 272 | 287 | |
| 273 | 288 | case ${FORMAT} in |
| 274 | 289 | flac) ENC="flac flac -8 - -o %f";; |
| 275 | 290 | mp3) ENC="cust ext=mp3 lame --preset extreme - %f";; |
| 276 | 291 | ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";; |
| 277 | − *) echo "Unknown output format ${FORMAT}"; exit 1;; | |
| 292 | + *) fatal "Unknown output format ${FORMAT}";; | |
| 278 | 293 | esac |
| 279 | 294 | |
| 280 | 295 | # split to tracks |
| 281 | 296 | cuebreakpoints "${CUE}" | \ |
| 282 | 297 | shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}" |
| 283 | 298 | if [ $? -ne 0 ]; then |
| 284 | − echo "Failed to split" | |
| 285 | − exit 1 | |
| 299 | + fatal "Failed to split" | |
| 286 | 300 | fi |
| 287 | 301 | |
| 288 | 302 | # prepare cover image |
| @@ -291,15 +305,14 @@ if [ ${DRY} -ne 1 ]; then · 2 unmodified lines | ||
| 291 | 305 | if [ $? -eq 0 ]; then |
| 292 | 306 | PIC="${TMPPIC}" |
| 293 | 307 | else |
| 294 | − echo "Failed to convert cover image" | |
| 308 | + $msg "${cR}Failed to convert cover image$cZ" | |
| 295 | 309 | unset PIC |
| 296 | 310 | fi |
| 297 | 311 | fi |
| 298 | 312 | fi |
| 299 | 313 | |
| 300 | 314 | # set tags and rename |
| 301 | −echo | |
| 302 | −echo "Setting tags" | |
| 315 | +$msg "\n${cP}Setting tags$cZ" | |
| 303 | 316 | |
| 304 | 317 | i=1 |
| 305 | 318 | while [ $i -le ${TRACKS_NUM} ]; do |
| @@ -308,15 +321,14 @@ while [ $i -le ${TRACKS_NUM} ]; do · 2 unmodified lines | ||
| 308 | 321 | FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE}) |
| 309 | 322 | f="${OUT}/${FILE_TRACK}.${FORMAT}" |
| 310 | 323 | |
| 311 | − echo "$i: ${TAG_TITLE}" | |
| 324 | + $msg "$i: $cG${TAG_TITLE}$cZ" | |
| 312 | 325 | |
| 313 | 326 | if [ ${NORENAME} -ne 1 ]; then |
| 314 | 327 | FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}" |
| 315 | 328 | if [ ${DRY} -ne 1 ]; then |
| 316 | 329 | mv "$f" "${FINAL}" |
| 317 | 330 | if [ $? -ne 0 ]; then |
| 318 | − echo "Failed to rename track file" | |
| 319 | − exit 1 | |
| 331 | + fatal "Failed to rename track file" | |
| 320 | 332 | fi |
| 321 | 333 | fi |
| 322 | 334 | else |
| @@ -373,16 +385,16 @@ while [ $i -le ${TRACKS_NUM} ]; do · 50 unmodified lines | ||
| 373 | 385 | RES=$((${RES} + $?)) |
| 374 | 386 | fi |
| 375 | 387 | ;; |
| 376 | − *) echo "Unknown output format ${FORMAT}"; exit 1;; | |
| 388 | + *) | |
| 389 | + fatal "Unknown output format ${FORMAT}";; | |
| 377 | 390 | esac |
| 378 | 391 | |
| 379 | 392 | if [ ${RES} -ne 0 ]; then |
| 380 | − echo "Failed to set tags for track" | |
| 381 | − exit 1 | |
| 393 | + fatal "Failed to set tags for track" | |
| 382 | 394 | fi |
| 383 | 395 | fi |
| 384 | 396 | |
| 385 | − echo " -> ${FINAL}" | |
| 397 | + $msg " -> ${cP}${FINAL}$cZ" | |
| 386 | 398 | |
| 387 | 399 | i=$(($i + 1)) |
| 388 | 400 | done |
| @@ -403,5 +415,4 @@ if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]; then · 14 unmodified lines | ||
| 403 | 415 | fi |
| 404 | 416 | fi |
| 405 | 417 | |
| 406 | −echo | |
| 407 | −echo "Finished" | |
| 418 | +$msg "\n${cP}Finished$cZ" | |