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