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