History

save config once; add -(no)colors; fix help msg eval

Serge Zirukin committed 16 years ago

Commit c0903e41 parent d9922f31 file · +61 −47Browse files

Unified · Split

split2flac.sh+61−47
@@ -35,6 +35,7 @@ NOSUBDIRS=0 · 34 unmodified lines
3535 NORENAME=0
3636 NOPIC=0
3737 REMOVE=0
38+NOCOLORS=0
3839 PIC_SIZE="192x192"
3940 FORMAT="${0##*split2}"
4041 FORMAT="${FORMAT%.sh}"
@@ -46,41 +47,36 @@ SAVE=0 · 5 unmodified lines
4647 unset PIC INPATH CUE CHARSET
4748 FORCE=0
4849
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
8480 (output dir, cover image size, etc.) so you won't need to pass a lot of options
8581 every time, just a filename.
8682 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
9187 $msg "${cR}$1${cZ}"
9288 }
9389
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+
94105 # parse arguments
95106 while [ "$1" ]; do
96107 case "$1" in
97108 -o) DIR=$2; shift;;
98109 -cue) CUE=$2; shift;;
110+ -cuecharset) CHARSET=$2; shift;;
99111 -f) FORMAT=$2; shift;;
100112 -c) NOPIC=0; PIC=$2; shift;;
101− -cuecharset) CHARSET=$2; shift;;
102113 -nc) NOPIC=1;;
103114 -cs) PIC_SIZE=$2; shift;;
104115 -d) NOSUBDIRS=0;;
@@ -109,6 +120,8 @@ while [ "$1" ]; do · 4 unmodified lines
109120 -D) REMOVE=1;;
110121 -nD) REMOVE=0;;
111122 -F) FORCE=1;;
123+ -colors) NOCOLORS=0; update_colors;;
124+ -nocolors) NOCOLORS=1; update_colors;;
112125 -s) SAVE=1;;
113126 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;
114127 -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;;
@@ -127,6 +140,18 @@ while [ "$1" ]; do · 12 unmodified lines
127140 shift
128141 done
129142
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+
130155 METAFLAC="metaflac --no-utf8-convert"
131156 VORBISCOMMENT="vorbiscomment -R -a"
132157 ID3TAG="id3tag -2"
@@ -237,17 +262,6 @@ split_file ( ) { · 104 unmodified lines
237262 fi
238263 fi
239264
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−
251265 GETTAG="cueprint -n 1 -t"
252266 VALIDATE="sed s/[^-[:space:][:alnum:]&_#,.'\"]//g"
253267

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t