Unified · Split
| @@ -80,15 +80,15 @@ It's better to pass \$cP'-p'\$cZ option to see what will happen when actually sp · 79 unmodified lines | ||
| 80 | 80 | You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration |
| 81 | 81 | (output dir, cover image size, etc.) so you won't need to pass a lot of options |
| 82 | 82 | every time, just a filename. Script will try to find CUE sheet if it wasn't specified. |
| 83 | −It also supports internal CUE sheets (FLAC and WV)." | |
| 83 | +It also supports internal CUE sheets (FLAC, APE and WV)." | |
| 84 | 84 | |
| 85 | 85 | msg="echo -e" |
| 86 | 86 | |
| 87 | −emsg ( ) { | |
| 87 | +emsg () { | |
| 88 | 88 | $msg "${cR}$1${cZ}" |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | −update_colors ( ) { | |
| 91 | +update_colors () { | |
| 92 | 92 | if [ "${NOCOLORS}" -eq 0 ]; then |
| 93 | 93 | cR="\033[31m" |
| 94 | 94 | cG="\033[32m" |
| @@ -173,7 +173,7 @@ esac · 78 unmodified lines | ||
| 173 | 173 | $msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}" |
| 174 | 174 | |
| 175 | 175 | # splits a file |
| 176 | −split_file ( ) { | |
| 176 | +split_file () { | |
| 177 | 177 | FILE="$1" |
| 178 | 178 | |
| 179 | 179 | if [ ! -r "${FILE}" ]; then |
| @@ -190,10 +190,26 @@ split_file ( ) { · 10 unmodified lines | ||
| 190 | 190 | # try to extract internal one |
| 191 | 191 | CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//') |
| 192 | 192 | |
| 193 | + # try WV internal cue sheet | |
| 193 | 194 | if [ -z "${CUESHEET}" ]; then |
| 194 | 195 | CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null) |
| 195 | 196 | fi |
| 196 | 197 | |
| 198 | + # try APE internal cue sheet (omfg!) | |
| 199 | + if [ -z "${CHESHEET}" ]; then | |
| 200 | + APETAGEX=$(tail -c 32 "$1" | cut -b 1-8 2>/dev/null) | |
| 201 | + if [ "${APETAGEX}" = "APETAGEX" ]; then | |
| 202 | + LENGTH=$(tail -c 32 "$1" | cut -b 13-16 | od -t u4 | awk '{printf $2}') 2>/dev/null | |
| 203 | + tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1 | |
| 204 | + if [ $? -eq 0 ]; then | |
| 205 | + CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null) | |
| 206 | + if [ $? -ne 0 ]; then | |
| 207 | + CUESHEET="" | |
| 208 | + fi | |
| 209 | + fi | |
| 210 | + fi | |
| 211 | + fi | |
| 212 | + | |
| 197 | 213 | if [ "${CUESHEET}" ]; then |
| 198 | 214 | $msg "${cP}Found internal cue sheet$cZ" |
| 199 | 215 | CUE="${TMPCUE}" |
| @@ -218,7 +234,7 @@ split_file ( ) { · 18 unmodified lines | ||
| 218 | 234 | |
| 219 | 235 | if [ "${CHARSET}" ]; then |
| 220 | 236 | $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ" |
| 221 | − CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null) | |
| 237 | + CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null) | |
| 222 | 238 | if [ $? -ne 0 ]; then |
| 223 | 239 | emsg "Unable to convert cue sheet from ${CHARSET} to utf-8" |
| 224 | 240 | return 1 |
| @@ -271,9 +287,9 @@ split_file ( ) { · 46 unmodified lines | ||
| 271 | 287 | fi |
| 272 | 288 | |
| 273 | 289 | # get common tags |
| 274 | − TAG_ARTIST=$(${GETTAG} %P "${CUE}") | |
| 275 | − TAG_ALBUM=$(${GETTAG} %T "${CUE}") | |
| 276 | − TRACKS_NUM=$(${GETTAG} %N "${CUE}") | |
| 290 | + TAG_ARTIST=$(${GETTAG} %P "${CUE}" 2>/dev/null) | |
| 291 | + TAG_ALBUM=$(${GETTAG} %T "${CUE}" 2>/dev/null) | |
| 292 | + TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null) | |
| 277 | 293 | |
| 278 | 294 | YEAR=$(awk '{ if (/REM[ \t]+DATE/) { printf "%i", $3; exit } }' < "${CUE}") |
| 279 | 295 | YEAR=$(echo ${YEAR} | tr -d -C '[:digit:]') |
| @@ -322,7 +338,7 @@ split_file ( ) { · 42 unmodified lines | ||
| 322 | 338 | fi |
| 323 | 339 | |
| 324 | 340 | case ${FORMAT} in |
| 325 | − flac) ENC="flac flac -8 - -o %f";; | |
| 341 | + flac) ENC="flac flac -0 - -o %f";; | |
| 326 | 342 | m4a) ENC="cust ext=m4a faac -q 500 -o %f -";; |
| 327 | 343 | mp3) ENC="cust ext=mp3 lame --preset extreme - %f";; |
| 328 | 344 | ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";; |
| @@ -330,7 +346,7 @@ split_file ( ) { · 1 unmodified line | ||
| 330 | 346 | esac |
| 331 | 347 | |
| 332 | 348 | # split to tracks |
| 333 | − cuebreakpoints "${CUE}" | \ | |
| 349 | + cuebreakpoints "${CUE}" 2>/dev/null | \ | |
| 334 | 350 | shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}" |
| 335 | 351 | if [ $? -ne 0 ]; then |
| 336 | 352 | emsg "Failed to split" |
| @@ -354,7 +370,7 @@ split_file ( ) { · 17 unmodified lines | ||
| 354 | 370 | |
| 355 | 371 | i=1 |
| 356 | 372 | while [ $i -le ${TRACKS_NUM} ]; do |
| 357 | − TAG_TITLE=$(cueprint -n $i -t %t "${CUE}") | |
| 373 | + TAG_TITLE=$(cueprint -n $i -t %t "${CUE}" 2>/dev/null) | |
| 358 | 374 | FILE_TRACK="$(printf %02i $i)" |
| 359 | 375 | FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE}) |
| 360 | 376 | f="${OUT}/${FILE_TRACK}.${FORMAT}" |
| @@ -481,7 +497,7 @@ split_file ( ) { · 120 unmodified lines | ||
| 481 | 497 | return 0 |
| 482 | 498 | } |
| 483 | 499 | |
| 484 | −split_collection ( ) { | |
| 500 | +split_collection () { | |
| 485 | 501 | while read -r FILE; do |
| 486 | 502 | $msg "$cG>> $cC\"${FILE}\"$cZ" |
| 487 | 503 | unset PIC CUE |
| @@ -496,7 +512,7 @@ split_collection ( ) { · 8 unmodified lines | ||
| 496 | 512 | } |
| 497 | 513 | |
| 498 | 514 | # searches for files in a directory and splits them |
| 499 | −split_dir ( ) { | |
| 515 | +split_dir () { | |
| 500 | 516 | find "$1" -name '*.flac' -o -name '*.ape' -o -name '*.wv' | split_collection |
| 501 | 517 | } |
| 502 | 518 | |