Unified · Split
| @@ -35,6 +35,7 @@ NOSUBDIRS=0 · 34 unmodified lines | |||
| 35 | NORENAME=0 | 35 | NORENAME=0 |
| 36 | NOPIC=0 | 36 | NOPIC=0 |
| 37 | REMOVE=0 | 37 | REMOVE=0 |
| 38 | NOCOLORS=0 | ||
| 38 | PIC_SIZE="192x192" | 39 | PIC_SIZE="192x192" |
| 39 | FORMAT="${0##*split2}" | 40 | FORMAT="${0##*split2}" |
| 40 | FORMAT="${FORMAT%.sh}" | 41 | FORMAT="${FORMAT%.sh}" |
| @@ -46,41 +47,36 @@ SAVE=0 · 5 unmodified lines | |||
| 46 | unset PIC INPATH CUE CHARSET | 47 | unset PIC INPATH CUE CHARSET |
| 47 | FORCE=0 | 48 | FORCE=0 |
| 48 | 49 | ||
| 49 | cR="\033[31m" | 50 | HELP="\${cG}split2flac splits one big \${cU}APE/FLAC/WV\$cZ\$cG file to \${cU}FLAC/MP3/OGG_VORBIS\$cZ\$cG tracks with tagging and renaming. |
| 50 | cG="\033[32m" | 51 | |
| 51 | cC="\033[35m" | 52 | Usage: \${cZ}split2\${FORMAT}.sh [\${cU}OPTIONS\$cZ] \${cU}FILE\$cZ [\${cU}OPTIONS\$cZ]\$cZ |
| 52 | cP="\033[36m" | 53 | \${cZ}split2\${FORMAT}.sh [\${cU}OPTIONS\$cZ] \${cU}DIR\$cZ [\${cU}OPTIONS\$cZ]\$cZ |
| 53 | cU="\033[4m" | 54 | \$cG-p\$cZ - dry run |
| 54 | cZ="\033[0m" | 55 | \$cG-o \${cU}DIRECTORY\$cZ \$cR*\$cZ - set output directory |
| 55 | 56 | \$cG-cue \${cU}FILE\$cZ - use file as a cue sheet (does not work with \${cU}DIR\$cZ) | |
| 56 | HELP="${cG}split2flac splits one big ${cU}APE/FLAC/WV$cZ$cG file to ${cU}FLAC/MP3/OGG_VORBIS$cZ$cG tracks with tagging and renaming. | 57 | \$cG-cuecharset \${cU}CHARSET\$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default) |
| 57 | 58 | \$cG-f \${cU}FORMAT\$cZ - use specified output format \$cP(current is \${FORMAT})\$cZ | |
| 58 | Usage: ${cZ}split2${FORMAT}.sh [${cU}OPTIONS$cZ] ${cU}FILE$cZ [${cU}OPTIONS$cZ]$cZ | 59 | \$cG-c \${cU}FILE\$cZ \$cR*\$cZ - use file as a cover image (does not work with \${cU}DIR\$cZ) |
| 59 | ${cZ}split2${FORMAT}.sh [${cU}OPTIONS$cZ] ${cU}DIR$cZ [${cU}OPTIONS$cZ]$cZ | 60 | \$cG-nc \${cR}*\$cZ - do not set any cover images |
| 60 | $cG-p$cZ - dry run | 61 | \$cG-cs \${cU}WxH\$cZ \$cR*\$cZ - set cover image size \$cP(current is \${PIC_SIZE})\$cZ |
| 61 | $cG-o ${cU}DIRECTORY$cZ $cR*$cZ - set output directory | 62 | \$cG-d \$cR*\$cZ - create artist/album subdirs (default) |
| 62 | $cG-cue ${cU}FILE$cZ - use file as a cue sheet (does not work with ${cU}DIR$cZ) | 63 | \$cG-nd \$cR*\$cZ - do not create any subdirs |
| 63 | $cG-f ${cU}FORMAT$cZ - use specified output format $cP(current is ${FORMAT})$cZ | 64 | \$cG-r \$cR*\$cZ - rename tracks to include title (default) |
| 64 | $cG-c ${cU}FILE$cZ $cR*$cZ - use file as a cover image (does not work with ${cU}DIR$cZ) | 65 | \$cG-nr \$cR*\$cZ - do not rename tracks (numbers only, e.g. '01.\${FORMAT}') |
| 65 | $cG-cuecharset ${cU}CHARSET$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default) | 66 | \$cG-D \$cR*\$cZ - delete original file |
| 66 | $cG-nc ${cR}*$cZ - do not set any cover images | 67 | \$cG-nD \$cR*\$cZ - do not remove the original (default) |
| 67 | $cG-cs ${cU}WxH$cZ $cR*$cZ - set cover image size $cP(current is ${PIC_SIZE})$cZ | 68 | \$cG-F\$cZ - force deletion without asking |
| 68 | $cG-d $cR*$cZ - create artist/album subdirs | 69 | \$cG-colors\$cZ \$cR*\$cZ - colorized output (default) |
| 69 | $cG-nd $cR*$cZ - do not create any subdirs | 70 | \$cG-nocolors\$cZ \$cR*\$cZ - turn off colors |
| 70 | $cG-r $cR*$cZ - rename tracks to include title | 71 | \$cG-s\$cZ - save configuration to \$cP\"\${CONFIG}\"\$cZ |
| 71 | $cG-nr $cR*$cZ - do not rename tracks (numbers only, e.g. '01.${FORMAT}') | 72 | \$cG-h\$cZ - print this message |
| 72 | $cG-D $cR*$cZ - delete original file | 73 | |
| 73 | $cG-nD $cR*$cZ - do not remove the original | 74 | \$cR*\$cZ - option affects configuration if \$cP'-s'\$cZ option passed. |
| 74 | $cG-F$cZ - force deletion without asking | 75 | \${cP}NOTE: \$cG'-c some_file.jpg -s'$cP only \${cU}allows\$cZ\$cP cover images, it doesn't set a default one. |
| 75 | $cG-s$cZ - save configuration to $cP\"${CONFIG}\"$cZ | 76 | \${cZ}Supported \$cU\${cG}FORMATs\${cZ}: flac, mp3, ogg vorbis. |
| 76 | $cG-h$cZ - print this message | 77 | |
| 77 | 78 | It's better to pass \$cP'-p'\$cZ option to see what will happen when actually splitting tracks. | |
| 78 | $cR*$cZ - option affects configuration if $cP'-s'$cZ option passed. | 79 | You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration |
| 79 | ${cP}NOTE: $cG'-c some_file.jpg -s'$cP only ${cU}allows$cZ$cP cover images, it doesn't set a default one. | ||
| 80 | ${cZ}Supported $cU${cG}FORMATs${cZ}: flac, mp3, ogg vorbis. | ||
| 81 | |||
| 82 | It's better to pass $cP'-p'$cZ option to see what will happen when actually splitting tracks. | ||
| 83 | You may want to pass $cP'-s'$cZ option for the first run to save default configuration | ||
| 84 | (output dir, cover image size, etc.) so you won't need to pass a lot of options | 80 | (output dir, cover image size, etc.) so you won't need to pass a lot of options |
| 85 | every time, just a filename. | 81 | every time, just a filename. |
| 86 | Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets." | 82 | Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets." |
| @@ -91,14 +87,29 @@ emsg ( ) { · 4 unmodified lines | |||
| 91 | $msg "${cR}$1${cZ}" | 87 | $msg "${cR}$1${cZ}" |
| 92 | } | 88 | } |
| 93 | 89 | ||
| 90 | update_colors ( ) { | ||
| 91 | if [ "${NOCOLORS}" -eq 0 ]; then | ||
| 92 | cR="\033[31m" | ||
| 93 | cG="\033[32m" | ||
| 94 | cC="\033[35m" | ||
| 95 | cP="\033[36m" | ||
| 96 | cU="\033[4m" | ||
| 97 | cZ="\033[0m" | ||
| 98 | else | ||
| 99 | unset cR cG cC cP cU cZ | ||
| 100 | fi | ||
| 101 | } | ||
| 102 | |||
| 103 | update_colors | ||
| 104 | |||
| 94 | # parse arguments | 105 | # parse arguments |
| 95 | while [ "$1" ]; do | 106 | while [ "$1" ]; do |
| 96 | case "$1" in | 107 | case "$1" in |
| 97 | -o) DIR=$2; shift;; | 108 | -o) DIR=$2; shift;; |
| 98 | -cue) CUE=$2; shift;; | 109 | -cue) CUE=$2; shift;; |
| 110 | -cuecharset) CHARSET=$2; shift;; | ||
| 99 | -f) FORMAT=$2; shift;; | 111 | -f) FORMAT=$2; shift;; |
| 100 | -c) NOPIC=0; PIC=$2; shift;; | 112 | -c) NOPIC=0; PIC=$2; shift;; |
| 101 | -cuecharset) CHARSET=$2; shift;; | ||
| 102 | -nc) NOPIC=1;; | 113 | -nc) NOPIC=1;; |
| 103 | -cs) PIC_SIZE=$2; shift;; | 114 | -cs) PIC_SIZE=$2; shift;; |
| 104 | -d) NOSUBDIRS=0;; | 115 | -d) NOSUBDIRS=0;; |
| @@ -109,6 +120,8 @@ while [ "$1" ]; do · 4 unmodified lines | |||
| 109 | -D) REMOVE=1;; | 120 | -D) REMOVE=1;; |
| 110 | -nD) REMOVE=0;; | 121 | -nD) REMOVE=0;; |
| 111 | -F) FORCE=1;; | 122 | -F) FORCE=1;; |
| 123 | -colors) NOCOLORS=0; update_colors;; | ||
| 124 | -nocolors) NOCOLORS=1; update_colors;; | ||
| 112 | -s) SAVE=1;; | 125 | -s) SAVE=1;; |
| 113 | -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;; | 126 | -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;; |
| 114 | -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;; | 127 | -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;; |
| @@ -127,6 +140,18 @@ while [ "$1" ]; do · 12 unmodified lines | |||
| 127 | shift | 140 | shift |
| 128 | done | 141 | done |
| 129 | 142 | ||
| 143 | # save configuration if needed | ||
| 144 | if [ ${SAVE} -eq 1 ]; then | ||
| 145 | echo "DIR=\"${DIR}\"" > "${CONFIG}" | ||
| 146 | echo "NOSUBDIRS=${NOSUBDIRS}" >> "${CONFIG}" | ||
| 147 | echo "NORENAME=${NORENAME}" >> "${CONFIG}" | ||
| 148 | echo "NOPIC=${NOPIC}" >> "${CONFIG}" | ||
| 149 | echo "REMOVE=${REMOVE}" >> "${CONFIG}" | ||
| 150 | echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}" | ||
| 151 | echo "NOCOLORS=${NOCOLORS}" >> "${CONFIG}" | ||
| 152 | $msg "${cP}Configuration saved$cZ" | ||
| 153 | fi | ||
| 154 | |||
| 130 | METAFLAC="metaflac --no-utf8-convert" | 155 | METAFLAC="metaflac --no-utf8-convert" |
| 131 | VORBISCOMMENT="vorbiscomment -R -a" | 156 | VORBISCOMMENT="vorbiscomment -R -a" |
| 132 | ID3TAG="id3tag -2" | 157 | ID3TAG="id3tag -2" |
| @@ -237,17 +262,6 @@ split_file ( ) { · 104 unmodified lines | |||
| 237 | fi | 262 | fi |
| 238 | fi | 263 | fi |
| 239 | 264 | ||
| 240 | # save configuration if needed | ||
| 241 | if [ ${SAVE} -eq 1 ]; then | ||
| 242 | echo "DIR=\"${DIR}\"" > "${CONFIG}" | ||
| 243 | echo "NOSUBDIRS=${NOSUBDIRS}" >> "${CONFIG}" | ||
| 244 | echo "NORENAME=${NORENAME}" >> "${CONFIG}" | ||
| 245 | echo "NOPIC=${NOPIC}" >> "${CONFIG}" | ||
| 246 | echo "REMOVE=${REMOVE}" >> "${CONFIG}" | ||
| 247 | echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}" | ||
| 248 | $msg "${cP}Configuration saved$cZ" | ||
| 249 | fi | ||
| 250 | |||
| 251 | GETTAG="cueprint -n 1 -t" | 265 | GETTAG="cueprint -n 1 -t" |
| 252 | VALIDATE="sed s/[^-[:space:][:alnum:]&_#,.'\"]//g" | 266 | VALIDATE="sed s/[^-[:space:][:alnum:]&_#,.'\"]//g" |
| 253 | 267 | ||