History

colorize

Serge Zirukin committed 16 years ago

Commit 4600c6f1 parent 42a21981 file · +83 −72Browse files

Unified · Split

split2flac.sh+83−72
@@ -49,37 +49,50 @@ unset CUE · 48 unmodified lines
4949 unset CHARSET
5050 FORCE=0
5151
52−HELP="Usage: split2\${FORMAT}.sh [OPTIONS] FILE
53− -o DIRECTORY * - set output directory
54− -cue FILE - use file as a cue sheet
55− -f FORMAT - use specified output format (current is \${FORMAT})
56− -c FILE * - use file as a cover image
57− -cuecharset CHARSET - convert cue sheet from CHARSET to UTF-8 (no conversion by default)
58− -nc * - do not set any cover images
59− -cs WxH * - set cover image size (current is \${PIC_SIZE})
60− -d * - create artist/album subdirs
61− -nd * - do not create any subdirs
62− -r * - rename tracks to include title
63− -nr * - do not rename tracks (numbers only, e.g. '01.\${FORMAT}')
64− -p - dry run
65− -D * - delete original file
66− -nD * - do not remove the original
67− -f - force deletion without asking
68− -s - save configuration to \"\${CONFIG}\"
52+cR="\033[31m"
53+cG="\033[32m"
54+cP="\033[36m"
55+cU="\033[4m"
56+cZ="\033[0m"
57+
58+HELP="${cG}split2flac splits one big ${cU}APE/FLAC/WV$cZ$cG file to ${cU}FLAC/MP3/OGG$cZ$cG tracks with tagging and renaming.
59+
60+Usage: ${cZ}split2${FORMAT}.sh [${cU}OPTIONS$cZ] ${cU}FILE$cZ [${cU}OPTIONS$cZ]$cZ
61+ $cG-p$cZ - dry run
62+ $cG-o ${cU}DIRECTORY$cZ $cR*$cZ - set output directory
63+ $cG-cue ${cU}FILE$cZ - use file as a cue sheet
64+ $cG-f ${cU}FORMAT$cZ - use specified output format $cP(current is ${FORMAT})$cZ
65+ $cG-c ${cU}FILE$cZ $cR*$cZ - use file as a cover image
66+ $cG-cuecharset ${cU}CHARSET$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default)
67+ $cG-nc ${cR}*$cZ - do not set any cover images
68+ $cG-cs ${cU}WxH$cZ $cR*$cZ - set cover image size $cP(current is ${PIC_SIZE})$cZ
69+ $cG-d $cR*$cZ - create artist/album subdirs
70+ $cG-nd $cR*$cZ - do not create any subdirs
71+ $cG-r $cR*$cZ - rename tracks to include title
72+ $cG-nr $cR*$cZ - do not rename tracks (numbers only, e.g. '01.${FORMAT}')
73+ $cG-D $cR*$cZ - delete original file
74+ $cG-nD $cR*$cZ - do not remove the original
75+ $cG-F$cZ - force deletion without asking
76+ -s - save configuration to $cP\"${CONFIG}\"$cZ
6977 -h - print this message
70− -H - print README
7178
72−* - option has effect on configuration if -s option passed.
73−NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one.
74−Supported FORMATs: flac, mp3, ogg."
79+$cR*$cZ - option has effect on configuration if $cP'-s'$cZ option passed.
80+${cP}NOTE: $cG'-c some_file.jpg -s'$cP only ${cU}allows$cZ$cP cover images, it doesn't set a default one.
81+${cZ}Supported $cU${cG}FORMATs${cZ}: flac, mp3, ogg.
7582
76−README="split2flac splits one big APE/FLAC/WV file to FLAC/MP3/OGG tracks with tagging and renaming.
77−It's better to pass '-p' option to see what will happen when actually splitting tracks.
78−You may want to pass '-s' option for the first run to save default configuration
83+It's better to pass $cP'-p'$cZ option to see what will happen when actually splitting tracks.
84+You may want to pass $cP'-s'$cZ option for the first run to save default configuration
7985 (output dir, cover image size, etc.) so you won't need to pass a lot of options
8086 every time, just a filename.
8187 Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets."
8288
89+msg="echo -e"
90+
91+fatal ( ) {
92+ $msg "${cR}$1${cZ}"
93+ exit 1
94+}
95+
8396 # parse arguments
8497 while [ "$1" ]; do
8598 case "$1" in
@@ -97,18 +110,15 @@ while [ "$1" ]; do · 11 unmodified lines
97110 -p) DRY=1;;
98111 -D) REMOVE=1;;
99112 -nD) REMOVE=0;;
100− -f) FORCE=1;;
113+ -F) FORCE=1;;
101114 -s) SAVE=1;;
102− -h) eval "echo \"${HELP}\""; exit 0;;
103− -H) echo "${README}"; exit 0;;
115+ -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;
104116 *)
105117 if [ -r "${FILE}" ]; then
106− echo "Unknown option $1"
107− eval "echo \"${HELP}\""
108− exit 1
118+ eval "$msg \"${HELP}\""
119+ fatal "\nUnknown option $1"
109120 elif [ ! -r "$1" ]; then
110− echo "Unable to read $1"
111− exit 1
121+ fatal "Unable to read $1"
112122 else
113123 FILE="$1"
114124 fi;;
@@ -120,6 +130,18 @@ METAFLAC="metaflac --no-utf8-convert" · 5 unmodified lines
120130 VORBISCOMMENT="vorbiscomment -R -a"
121131 ID3TAG="id3tag -2"
122132
133+# print input filename
134+$msg "${cG}Input file :$cZ ${FILE:?No input filename given. Use -h for help.}$cZ"
135+
136+# check & print output format
137+msg_format="${cG}Output format :$cZ"
138+case ${FORMAT} in
139+ flac) $msg "$msg_format FLAC";;
140+ mp3) $msg "$msg_format MP3";;
141+ ogg) $msg "$msg_format OGG VORBIS";;
142+ *) fatal "Unknown output format \"${FORMAT}\"";;
143+esac
144+
123145 # search for a cue sheet if not specified
124146 if [ -z "${CUE}" ]; then
125147 CUE="${FILE}.cue"
@@ -138,8 +160,7 @@ if [ -z "${CUE}" ]; then · 12 unmodified lines
138160 echo "${CUESHEET}" > "${CUE}"
139161
140162 if [ $? -ne 0 ]; then
141− echo "Unable to save internal cue sheet"
142− exit 1
163+ fatal "Unable to save internal cue sheet"
143164 fi
144165 else
145166 unset CUE
@@ -148,23 +169,20 @@ if [ -z "${CUE}" ]; then · 2 unmodified lines
148169 fi
149170 fi
150171
151−# print some info and check arguments
152−echo "Input file : ${FILE:?No input filename given. Use -h for help.}"
153−echo "Cue sheet : ${CUE:?No cue sheet}"
172+# print cue sheet filename
173+$msg "${cG}Cue sheet :$cZ ${CUE:?No cue sheet}$cZ"
154174
155175 if [ -n "${CHARSET}" ]; then
156− echo "Cue charset : ${CHARSET} -> utf-8"
176+ $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"
157177 CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
158178 if [ $? -ne 0 ]; then
159− echo "Unable to convert cue sheet from ${CHARSET} to utf-8"
160− exit 1
179+ fatal "Unable to convert cue sheet from ${CHARSET} to utf-8"
161180 fi
162181 CUE="${TMPCUE}"
163182 echo "${CUESHEET}" > "${CUE}"
164183
165184 if [ $? -ne 0 ]; then
166− echo "Unable to save converted cue sheet"
167− exit 1
185+ fatal "Unable to save converted cue sheet"
168186 fi
169187 fi
170188
@@ -193,16 +211,16 @@ elif [ -z "${PIC}" ]; then · 22 unmodified lines
193211 fi
194212 fi
195213
196−echo "Cover image : ${PIC:-not set}"
197−echo "Output dir : ${DIR:?Output directory was not set}"
214+$msg "${cG}Cover image :$cZ ${PIC:-not set}"
215+$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"
198216
199217 # file removal warning
200218 if [ ${REMOVE} -eq 1 ]; then
201− echo -n "Also remove original"
219+ msg_removal="\n${cR}Also remove original"
202220 if [ ${FORCE} -eq 1 ]; then
203− echo
221+ $msg "$msg_removal (WITHOUT ASKING)$cZ"
204222 else
205− echo " if user says 'y'"
223+ $msg "$msg_removal if user says 'y'$cZ"
206224 fi
207225 fi
208226
@@ -214,7 +232,7 @@ if [ ${SAVE} -eq 1 ]; then · 5 unmodified lines
214232 echo "NOPIC=${NOPIC}" >> "${CONFIG}"
215233 echo "REMOVE=${REMOVE}" >> "${CONFIG}"
216234 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"
217− echo "Configuration saved"
235+ $msg "${cP}Configuration saved$cZ"
218236 fi
219237
220238 GETTAG="cueprint -n 1 -t"
@@ -236,14 +254,12 @@ if [ -n "${YEAR}" ]; then · 15 unmodified lines
236254 fi
237255 fi
238256
239−echo
240−echo "Artist : ${TAG_ARTIST}"
241−echo "Album : ${TAG_ALBUM}"
257+$msg "\n${cG}Artist :$cZ ${TAG_ARTIST}"
258+$msg "${cG}Album :$cZ ${TAG_ALBUM}"
242259 if [ -n "${TAG_DATE}" ]; then
243− echo "Year : ${TAG_DATE}"
260+ $msg "${cG}Year :$cZ ${TAG_DATE}"
244261 fi
245−echo "Tracks : ${TRACKS_NUM}"
246−echo
262+$msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n"
247263
248264 # prepare output directory
249265 OUT="${DIR}"
@@ -259,30 +275,28 @@ if [ ${NOSUBDIRS} -ne 1 ]; then · 9 unmodified lines
259275 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
260276 fi
261277
262−echo "Saving tracks to \"${OUT}\""
278+$msg "${cP}Saving tracks to $cZ\"${OUT}\""
263279
264280 if [ ${DRY} -ne 1 ]; then
265281 # create output dir
266282 mkdir -p "${OUT}"
267283
268284 if [ $? -ne 0 ]; then
269− echo "Failed to create output directory"
270− exit 1
285+ fatal "Failed to create output directory"
271286 fi
272287
273288 case ${FORMAT} in
274289 flac) ENC="flac flac -8 - -o %f";;
275290 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
276291 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
277− *) echo "Unknown output format ${FORMAT}"; exit 1;;
292+ *) fatal "Unknown output format ${FORMAT}";;
278293 esac
279294
280295 # split to tracks
281296 cuebreakpoints "${CUE}" | \
282297 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
283298 if [ $? -ne 0 ]; then
284− echo "Failed to split"
285− exit 1
299+ fatal "Failed to split"
286300 fi
287301
288302 # prepare cover image
@@ -291,15 +305,14 @@ if [ ${DRY} -ne 1 ]; then · 2 unmodified lines
291305 if [ $? -eq 0 ]; then
292306 PIC="${TMPPIC}"
293307 else
294− echo "Failed to convert cover image"
308+ $msg "${cR}Failed to convert cover image$cZ"
295309 unset PIC
296310 fi
297311 fi
298312 fi
299313
300314 # set tags and rename
301−echo
302−echo "Setting tags"
315+$msg "\n${cP}Setting tags$cZ"
303316
304317 i=1
305318 while [ $i -le ${TRACKS_NUM} ]; do
@@ -308,15 +321,14 @@ while [ $i -le ${TRACKS_NUM} ]; do · 2 unmodified lines
308321 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
309322 f="${OUT}/${FILE_TRACK}.${FORMAT}"
310323
311− echo "$i: ${TAG_TITLE}"
324+ $msg "$i: $cG${TAG_TITLE}$cZ"
312325
313326 if [ ${NORENAME} -ne 1 ]; then
314327 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
315328 if [ ${DRY} -ne 1 ]; then
316329 mv "$f" "${FINAL}"
317330 if [ $? -ne 0 ]; then
318− echo "Failed to rename track file"
319− exit 1
331+ fatal "Failed to rename track file"
320332 fi
321333 fi
322334 else
@@ -373,16 +385,16 @@ while [ $i -le ${TRACKS_NUM} ]; do · 50 unmodified lines
373385 RES=$((${RES} + $?))
374386 fi
375387 ;;
376− *) echo "Unknown output format ${FORMAT}"; exit 1;;
388+ *)
389+ fatal "Unknown output format ${FORMAT}";;
377390 esac
378391
379392 if [ ${RES} -ne 0 ]; then
380− echo "Failed to set tags for track"
381− exit 1
393+ fatal "Failed to set tags for track"
382394 fi
383395 fi
384396
385− echo " -> ${FINAL}"
397+ $msg " -> ${cP}${FINAL}$cZ"
386398
387399 i=$(($i + 1))
388400 done
@@ -403,5 +415,4 @@ if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]; then · 14 unmodified lines
403415 fi
404416 fi
405417
406−echo
407−echo "Finished"
418+$msg "\n${cP}Finished$cZ"

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