Unified · Split
| @@ -20,6 +20,12 @@ · 19 unmodified lines | |||
| 20 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 21 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | 22 | ||
| 23 | # Dependencies: | ||
| 24 | # shntool, cuetools | ||
| 25 | # SPLIT: flac, wavpack, mac | ||
| 26 | # CONVERT: flac, id3lib, lame, vorbis-tools | ||
| 27 | # ART: ImageMagick | ||
| 28 | |||
| 23 | CONFIG="${HOME}/.split2flac" | 29 | CONFIG="${HOME}/.split2flac" |
| 24 | TMPCUE="${HOME}/.split2flac_sheet.cue" | 30 | TMPCUE="${HOME}/.split2flac_sheet.cue" |
| 25 | TMPPIC="${HOME}/.split2flac_cover.jpg" | 31 | TMPPIC="${HOME}/.split2flac_cover.jpg" |
| @@ -29,6 +35,8 @@ NORENAME=0 · 3 unmodified lines | |||
| 29 | NOPIC=0 | 35 | NOPIC=0 |
| 30 | REMOVE=0 | 36 | REMOVE=0 |
| 31 | PIC_SIZE="192x192" | 37 | PIC_SIZE="192x192" |
| 38 | FORMAT=$(echo $0 | sed 's/^.*2//;s/\..*//') | ||
| 39 | FORMAT=${FORMAT:-"flac"} | ||
| 32 | 40 | ||
| 33 | # load settings | 41 | # load settings |
| 34 | eval $(cat "${CONFIG}" 2>/dev/null) | 42 | eval $(cat "${CONFIG}" 2>/dev/null) |
| @@ -42,25 +50,27 @@ FORCE=0 · 7 unmodified lines | |||
| 42 | HELP="Usage: split2flac.sh [OPTIONS] FILE | 50 | HELP="Usage: split2flac.sh [OPTIONS] FILE |
| 43 | -o DIRECTORY * - set output directory | 51 | -o DIRECTORY * - set output directory |
| 44 | -cue FILE - use file as a cue sheet | 52 | -cue FILE - use file as a cue sheet |
| 53 | -f FORMAT - use specified output format (current is \${FORMAT}) | ||
| 45 | -c FILE * - use file as a cover image | 54 | -c FILE * - use file as a cover image |
| 46 | -nc * - do not set any cover images | 55 | -nc * - do not set any cover images |
| 47 | -cs WxH * - set cover image size (current is ${PIC_SIZE}) | 56 | -cs WxH * - set cover image size (current is \${PIC_SIZE}) |
| 48 | -d * - create artist/album subdirs | 57 | -d * - create artist/album subdirs |
| 49 | -nd * - do not create any subdirs | 58 | -nd * - do not create any subdirs |
| 50 | -r * - rename tracks to include title | 59 | -r * - rename tracks to include title |
| 51 | -nr * - do not rename tracks (numbers only, e.g. '01.flac') | 60 | -nr * - do not rename tracks (numbers only, e.g. '01.\${FORMAT}') |
| 52 | -p - dry run | 61 | -p - dry run |
| 53 | -D * - delete original file | 62 | -D * - delete original file |
| 54 | -nD * - do not remove the original | 63 | -nD * - do not remove the original |
| 55 | -f - force deletion without asking | 64 | -f - force deletion without asking |
| 56 | -s - save configuration to \"${CONFIG}\" | 65 | -s - save configuration to \"\${CONFIG}\" |
| 57 | -h - print this message | 66 | -h - print this message |
| 58 | -H - print README | 67 | -H - print README |
| 59 | 68 | ||
| 60 | * - option has effect on configuration if -s option passed. | 69 | * - option has effect on configuration if -s option passed. |
| 61 | NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one." | 70 | NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one. |
| 71 | Supported FORMATs: flac, mp3, ogg." | ||
| 62 | 72 | ||
| 63 | README="split2flac.sh splits one big APE/FLAC/WV file to FLAC tracks with tagging and renaming. | 73 | README="split2flac.sh splits one big APE/FLAC/WV file to FLAC/MP3/OGG tracks with tagging and renaming. |
| 64 | It's better to pass '-p' option to see what will happen when actually splitting tracks. | 74 | It's better to pass '-p' option to see what will happen when actually splitting tracks. |
| 65 | You may want to pass '-s' option for the first run to save default configuration | 75 | You may want to pass '-s' option for the first run to save default configuration |
| 66 | (output dir, cover image size, etc.) so you won't need to pass a lot of options | 76 | (output dir, cover image size, etc.) so you won't need to pass a lot of options |
| @@ -73,6 +83,7 @@ do · 6 unmodified lines | |||
| 73 | case $1 in | 83 | case $1 in |
| 74 | -o) DIR=$2; shift;; | 84 | -o) DIR=$2; shift;; |
| 75 | -cue) CUE=$2; shift;; | 85 | -cue) CUE=$2; shift;; |
| 86 | -f) FORMAT=$2; shift;; | ||
| 76 | -c) NOPIC=0; PIC=$2; shift;; | 87 | -c) NOPIC=0; PIC=$2; shift;; |
| 77 | -nc) NOPIC=1;; | 88 | -nc) NOPIC=1;; |
| 78 | -cs) PIC_SIZE=$2; shift;; | 89 | -cs) PIC_SIZE=$2; shift;; |
| @@ -85,13 +96,13 @@ do · 6 unmodified lines | |||
| 85 | -nD) REMOVE=0;; | 96 | -nD) REMOVE=0;; |
| 86 | -f) FORCE=1;; | 97 | -f) FORCE=1;; |
| 87 | -s) SAVE=1;; | 98 | -s) SAVE=1;; |
| 88 | -h) echo "${HELP}"; exit 0;; | 99 | -h) eval "echo \"${HELP}\""; exit 0;; |
| 89 | -H) echo "${README}"; exit 0;; | 100 | -H) echo "${README}"; exit 0;; |
| 90 | *) | 101 | *) |
| 91 | if [ -r "${FILE}" ] | 102 | if [ -r "${FILE}" ] |
| 92 | then | 103 | then |
| 93 | echo "Unknown option $1" | 104 | echo "Unknown option $1" |
| 94 | echo "${HELP}" | 105 | eval "echo \"${HELP}\"" |
| 95 | exit 1 | 106 | exit 1 |
| 96 | elif [ ! -r "$1" ] | 107 | elif [ ! -r "$1" ] |
| 97 | then | 108 | then |
| @@ -105,6 +116,8 @@ do · 7 unmodified lines | |||
| 105 | done | 116 | done |
| 106 | 117 | ||
| 107 | METAFLAC="metaflac --no-utf8-convert" | 118 | METAFLAC="metaflac --no-utf8-convert" |
| 119 | VORBISCOMMENT="vorbiscomment -R -a" | ||
| 120 | ID3TAG="id3tag -2" | ||
| 108 | 121 | ||
| 109 | # search for a cue sheet if not specified | 122 | # search for a cue sheet if not specified |
| 110 | if [ -z "${CUE}" ] | 123 | if [ -z "${CUE}" ] |
| @@ -142,7 +155,7 @@ then · 31 unmodified lines | |||
| 142 | fi | 155 | fi |
| 143 | 156 | ||
| 144 | # print some info and check arguments | 157 | # print some info and check arguments |
| 145 | echo "Input file :" ${FILE:?"${HELP}"} | 158 | echo "Input file :" ${FILE:?"No input filename given. Use -h for help."} |
| 146 | echo "Cue sheet :" ${CUE:?"No cue sheet"} | 159 | echo "Cue sheet :" ${CUE:?"No cue sheet"} |
| 147 | 160 | ||
| 148 | # search for a front cover image | 161 | # search for a front cover image |
| @@ -264,9 +277,16 @@ then · 115 unmodified lines | |||
| 264 | exit 1 | 277 | exit 1 |
| 265 | fi | 278 | fi |
| 266 | 279 | ||
| 280 | case ${FORMAT} in | ||
| 281 | flac) ENC="flac flac -8 - -o %f";; | ||
| 282 | mp3) ENC="cust ext=mp3 lame --preset extreme - %f";; | ||
| 283 | ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";; | ||
| 284 | *) echo "Unknown output format ${FORMAT}"; exit 1;; | ||
| 285 | esac | ||
| 286 | |||
| 267 | # split to tracks | 287 | # split to tracks |
| 268 | cuebreakpoints "${CUE}" | \ | 288 | cuebreakpoints "${CUE}" | \ |
| 269 | shnsplit -O never -o "flac flac -8 - -o %f" -d "${OUT}" -t "%n" "${FILE}" | 289 | shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}" |
| 270 | if [ $? -ne 0 ] | 290 | if [ $? -ne 0 ] |
| 271 | then | 291 | then |
| 272 | echo "Failed to split" | 292 | echo "Failed to split" |
| @@ -295,15 +315,15 @@ i=1 · 22 unmodified lines | |||
| 295 | while [ $i -le ${TRACKS_NUM} ] | 315 | while [ $i -le ${TRACKS_NUM} ] |
| 296 | do | 316 | do |
| 297 | TAG_TITLE=$(cueprint -n $i -t %t "${CUE}") | 317 | TAG_TITLE=$(cueprint -n $i -t %t "${CUE}") |
| 298 | f="${OUT}/$(printf %02i $i).flac" | 318 | f="${OUT}/$(printf %02i $i).${FORMAT}" |
| 299 | FILE_TRACK=$(basename "$f" .flac) | 319 | FILE_TRACK=$(basename "$f" .${FORMAT}) |
| 300 | FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE}) | 320 | FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE}) |
| 301 | 321 | ||
| 302 | echo "$i: ${TAG_TITLE}" | 322 | echo "$i: ${TAG_TITLE}" |
| 303 | 323 | ||
| 304 | if [ ${NORENAME} -ne 1 ] | 324 | if [ ${NORENAME} -ne 1 ] |
| 305 | then | 325 | then |
| 306 | FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.flac" | 326 | FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}" |
| 307 | if [ ${DRY} -ne 1 ] | 327 | if [ ${DRY} -ne 1 ] |
| 308 | then | 328 | then |
| 309 | mv "$f" "${FINAL}" | 329 | mv "$f" "${FINAL}" |
| @@ -319,25 +339,62 @@ do · 9 unmodified lines | |||
| 319 | 339 | ||
| 320 | if [ ${DRY} -ne 1 ] | 340 | if [ ${DRY} -ne 1 ] |
| 321 | then | 341 | then |
| 322 | ${METAFLAC} --remove-all-tags \ | 342 | case ${FORMAT} in |
| 323 | --set-tag="ARTIST=${TAG_ARTIST}" \ | 343 | flac) |
| 324 | --set-tag="ALBUM=${TAG_ALBUM}" \ | 344 | ${METAFLAC} --remove-all-tags \ |
| 325 | --set-tag="TITLE=${TAG_TITLE}" \ | 345 | --set-tag="ARTIST=${TAG_ARTIST}" \ |
| 326 | --set-tag="TRACKNUMBER=$i" \ | 346 | --set-tag="ALBUM=${TAG_ALBUM}" \ |
| 327 | "${FINAL}" | 347 | --set-tag="TITLE=${TAG_TITLE}" \ |
| 328 | RES=$? | 348 | --set-tag="TRACKNUMBER=$i" \ |
| 329 | 349 | "${FINAL}" >/dev/null | |
| 330 | if [ -n "${TAG_DATE}" ] | 350 | RES=$? |
| 331 | then | 351 | |
| 332 | ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" | 352 | if [ -n "${TAG_DATE}" ] |
| 333 | RES=$((${RES} + $?)) | 353 | then |
| 334 | fi | 354 | ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" >/dev/null |
| 355 | RES=$((${RES} + $?)) | ||
| 356 | fi | ||
| 357 | |||
| 358 | if [ -n "${PIC}" ] | ||
| 359 | then | ||
| 360 | ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" >/dev/null | ||
| 361 | RES=$((${RES} + $?)) | ||
| 362 | fi | ||
| 363 | ;; | ||
| 364 | |||
| 365 | mp3) | ||
| 366 | ${ID3TAG} "-a${TAG_ARTIST}" \ | ||
| 367 | "-A${TAG_ALBUM}" \ | ||
| 368 | "-s${TAG_TITLE}" \ | ||
| 369 | "-t$i" \ | ||
| 370 | "-T${TRACKS_NUM}" \ | ||
| 371 | "${FINAL}" >/dev/null | ||
| 372 | RES=$? | ||
| 373 | |||
| 374 | if [ -n "${TAG_DATE}" ] | ||
| 375 | then | ||
| 376 | ${ID3TAG} -y"${TAG_DATE}" "${FINAL}" >/dev/null | ||
| 377 | RES=$((${RES} + $?)) | ||
| 378 | fi | ||
| 379 | ;; | ||
| 380 | |||
| 381 | ogg) | ||
| 382 | ${VORBISCOMMENT} "${FINAL}" \ | ||
| 383 | -t "ARTIST=${TAG_ARTIST}" \ | ||
| 384 | -t "ALBUM=${TAG_ALBUM}" \ | ||
| 385 | -t "TITLE=${TAG_TITLE}" \ | ||
| 386 | -t "TRACKNUMBER=$i" >/dev/null | ||
| 387 | RES=$? | ||
| 388 | |||
| 389 | if [ -n "${TAG_DATE}" ] | ||
| 390 | then | ||
| 391 | ${VORBISCOMMENT} "${FINAL}" -t "DATE=${TAG_DATE}" >/dev/null | ||
| 392 | RES=$((${RES} + $?)) | ||
| 393 | fi | ||
| 394 | ;; | ||
| 395 | *) echo "Unknown output format ${FORMAT}"; exit 1;; | ||
| 396 | esac | ||
| 335 | 397 | ||
| 336 | if [ -n "${PIC}" ] | ||
| 337 | then | ||
| 338 | ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" | ||
| 339 | RES=$((${RES} + $?)) | ||
| 340 | fi | ||
| 341 | 398 | ||
| 342 | if [ ${RES} -ne 0 ] | 399 | if [ ${RES} -ne 0 ] |
| 343 | then | 400 | then |