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
35NORENAME=035NORENAME=0
36NOPIC=036NOPIC=0
37REMOVE=037REMOVE=0
38NOCOLORS=0
38PIC_SIZE="192x192"39PIC_SIZE="192x192"
39FORMAT="${0##*split2}"40FORMAT="${0##*split2}"
40FORMAT="${FORMAT%.sh}"41FORMAT="${FORMAT%.sh}"
@@ -46,41 +47,36 @@ SAVE=0 · 5 unmodified lines
46unset PIC INPATH CUE CHARSET47unset PIC INPATH CUE CHARSET
47FORCE=048FORCE=0
48 49
49cR="\033[31m"50HELP="\${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.
50cG="\033[32m"51
51cC="\033[35m"52Usage: \${cZ}split2\${FORMAT}.sh [\${cU}OPTIONS\$cZ] \${cU}FILE\$cZ [\${cU}OPTIONS\$cZ]\$cZ
52cP="\033[36m"53 \${cZ}split2\${FORMAT}.sh [\${cU}OPTIONS\$cZ] \${cU}DIR\$cZ [\${cU}OPTIONS\$cZ]\$cZ
53cU="\033[4m"54 \$cG-p\$cZ - dry run
54cZ="\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)
56HELP="${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
58Usage: ${cZ}split2${FORMAT}.sh [${cU}OPTIONS$cZ] ${cU}FILE$cZ [${cU}OPTIONS$cZ]$cZ59 \$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]$cZ60 \$cG-nc \${cR}*\$cZ - do not set any cover images
60 $cG-p$cZ - dry run61 \$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 directory62 \$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})$cZ64 \$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 images67 \$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})$cZ68 \$cG-F\$cZ - force deletion without asking
68 $cG-d $cR*$cZ - create artist/album subdirs69 \$cG-colors\$cZ \$cR*\$cZ - colorized output (default)
69 $cG-nd $cR*$cZ - do not create any subdirs70 \$cG-nocolors\$cZ \$cR*\$cZ - turn off colors
70 $cG-r $cR*$cZ - rename tracks to include title71 \$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 file73
73 $cG-nD $cR*$cZ - do not remove the original74\$cR*\$cZ - option affects configuration if \$cP'-s'\$cZ option passed.
74 $cG-F$cZ - force deletion without asking75\${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}\"$cZ76\${cZ}Supported \$cU\${cG}FORMATs\${cZ}: flac, mp3, ogg vorbis.
76 $cG-h$cZ - print this message77
77 78It'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.79You 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
82It's better to pass $cP'-p'$cZ option to see what will happen when actually splitting tracks.
83You 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 options80(output dir, cover image size, etc.) so you won't need to pass a lot of options
85every time, just a filename.81every time, just a filename.
86Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets."82Script 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
90update_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
103update_colors
104
94# parse arguments105# parse arguments
95while [ "$1" ]; do106while [ "$1" ]; do
96 case "$1" in107 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 shift140 shift
128done141done
129 142
143# save configuration if needed
144if [ ${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"
153fi
154
130METAFLAC="metaflac --no-utf8-convert"155METAFLAC="metaflac --no-utf8-convert"
131VORBISCOMMENT="vorbiscomment -R -a"156VORBISCOMMENT="vorbiscomment -R -a"
132ID3TAG="id3tag -2"157ID3TAG="id3tag -2"
@@ -237,17 +262,6 @@ split_file ( ) { · 104 unmodified lines
237 fi262 fi
238 fi263 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

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