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
49unset CHARSET49unset CHARSET
50FORCE=050FORCE=0
51 51
52HELP="Usage: split2\${FORMAT}.sh [OPTIONS] FILE52cR="\033[31m"
53 -o DIRECTORY * - set output directory53cG="\033[32m"
54 -cue FILE - use file as a cue sheet54cP="\033[36m"
55 -f FORMAT - use specified output format (current is \${FORMAT})55cU="\033[4m"
56 -c FILE * - use file as a cover image56cZ="\033[0m"
57 -cuecharset CHARSET - convert cue sheet from CHARSET to UTF-8 (no conversion by default)57
58 -nc * - do not set any cover images58HELP="${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 -cs WxH * - set cover image size (current is \${PIC_SIZE})59
60 -d * - create artist/album subdirs60Usage: ${cZ}split2${FORMAT}.sh [${cU}OPTIONS$cZ] ${cU}FILE$cZ [${cU}OPTIONS$cZ]$cZ
61 -nd * - do not create any subdirs61 $cG-p$cZ - dry run
62 -r * - rename tracks to include title62 $cG-o ${cU}DIRECTORY$cZ $cR*$cZ - set output directory
63 -nr * - do not rename tracks (numbers only, e.g. '01.\${FORMAT}')63 $cG-cue ${cU}FILE$cZ - use file as a cue sheet
64 -p - dry run64 $cG-f ${cU}FORMAT$cZ - use specified output format $cP(current is ${FORMAT})$cZ
65 -D * - delete original file65 $cG-c ${cU}FILE$cZ $cR*$cZ - use file as a cover image
66 -nD * - do not remove the original66 $cG-cuecharset ${cU}CHARSET$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default)
67 -f - force deletion without asking67 $cG-nc ${cR}*$cZ - do not set any cover images
68 -s - save configuration to \"\${CONFIG}\"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
69 -h - print this message77 -h - print this message
70 -H - print README
71 78
72* - option has effect on configuration if -s option passed.79$cR*$cZ - option has effect on configuration if $cP'-s'$cZ option passed.
73NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one.80${cP}NOTE: $cG'-c some_file.jpg -s'$cP only ${cU}allows$cZ$cP cover images, it doesn't set a default one.
74Supported FORMATs: flac, mp3, ogg."81${cZ}Supported $cU${cG}FORMATs${cZ}: flac, mp3, ogg.
75 82
76README="split2flac splits one big APE/FLAC/WV file to FLAC/MP3/OGG tracks with tagging and renaming.83It's better to pass $cP'-p'$cZ option to see what will happen when actually splitting tracks.
77It's better to pass '-p' option to see what will happen when actually splitting tracks.84You may want to pass $cP'-s'$cZ option for the first run to save default configuration
78You may want to pass '-s' option for the first run to save default configuration
79(output dir, cover image size, etc.) so you won't need to pass a lot of options85(output dir, cover image size, etc.) so you won't need to pass a lot of options
80every time, just a filename.86every time, just a filename.
81Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets."87Script will try to find CUE sheet if it wasn't specified. It also supports internal CUE sheets."
82 88
89msg="echo -e"
90
91fatal ( ) {
92 $msg "${cR}$1${cZ}"
93 exit 1
94}
95
83# parse arguments96# parse arguments
84while [ "$1" ]; do97while [ "$1" ]; do
85 case "$1" in98 case "$1" in
@@ -97,18 +110,15 @@ while [ "$1" ]; do · 11 unmodified lines
97 -p) DRY=1;;110 -p) DRY=1;;
98 -D) REMOVE=1;;111 -D) REMOVE=1;;
99 -nD) REMOVE=0;;112 -nD) REMOVE=0;;
100 -f) FORCE=1;;113 -F) FORCE=1;;
101 -s) SAVE=1;;114 -s) SAVE=1;;
102 -h) eval "echo \"${HELP}\""; exit 0;;115 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;
103 -H) echo "${README}"; exit 0;;
104 *)116 *)
105 if [ -r "${FILE}" ]; then117 if [ -r "${FILE}" ]; then
106 echo "Unknown option $1"118 eval "$msg \"${HELP}\""
107 eval "echo \"${HELP}\""119 fatal "\nUnknown option $1"
108 exit 1
109 elif [ ! -r "$1" ]; then120 elif [ ! -r "$1" ]; then
110 echo "Unable to read $1"121 fatal "Unable to read $1"
111 exit 1
112 else122 else
113 FILE="$1"123 FILE="$1"
114 fi;;124 fi;;
@@ -120,6 +130,18 @@ METAFLAC="metaflac --no-utf8-convert" · 5 unmodified lines
120VORBISCOMMENT="vorbiscomment -R -a"130VORBISCOMMENT="vorbiscomment -R -a"
121ID3TAG="id3tag -2"131ID3TAG="id3tag -2"
122 132
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
137msg_format="${cG}Output format :$cZ"
138case ${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}\"";;
143esac
144
123# search for a cue sheet if not specified145# search for a cue sheet if not specified
124if [ -z "${CUE}" ]; then146if [ -z "${CUE}" ]; then
125 CUE="${FILE}.cue"147 CUE="${FILE}.cue"
@@ -138,8 +160,7 @@ if [ -z "${CUE}" ]; then · 12 unmodified lines
138 echo "${CUESHEET}" > "${CUE}"160 echo "${CUESHEET}" > "${CUE}"
139 161
140 if [ $? -ne 0 ]; then162 if [ $? -ne 0 ]; then
141 echo "Unable to save internal cue sheet"163 fatal "Unable to save internal cue sheet"
142 exit 1
143 fi164 fi
144 else165 else
145 unset CUE166 unset CUE
@@ -148,23 +169,20 @@ if [ -z "${CUE}" ]; then · 2 unmodified lines
148 fi169 fi
149fi170fi
150 171
151# print some info and check arguments172# print cue sheet filename
152echo "Input file : ${FILE:?No input filename given. Use -h for help.}"173$msg "${cG}Cue sheet :$cZ ${CUE:?No cue sheet}$cZ"
153echo "Cue sheet : ${CUE:?No cue sheet}"
154 174
155if [ -n "${CHARSET}" ]; then175if [ -n "${CHARSET}" ]; then
156 echo "Cue charset : ${CHARSET} -> utf-8"176 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"
157 CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)177 CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
158 if [ $? -ne 0 ]; then178 if [ $? -ne 0 ]; then
159 echo "Unable to convert cue sheet from ${CHARSET} to utf-8"179 fatal "Unable to convert cue sheet from ${CHARSET} to utf-8"
160 exit 1
161 fi180 fi
162 CUE="${TMPCUE}"181 CUE="${TMPCUE}"
163 echo "${CUESHEET}" > "${CUE}"182 echo "${CUESHEET}" > "${CUE}"
164 183
165 if [ $? -ne 0 ]; then184 if [ $? -ne 0 ]; then
166 echo "Unable to save converted cue sheet"185 fatal "Unable to save converted cue sheet"
167 exit 1
168 fi186 fi
169fi187fi
170 188
@@ -193,16 +211,16 @@ elif [ -z "${PIC}" ]; then · 22 unmodified lines
193 fi211 fi
194fi212fi
195 213
196echo "Cover image : ${PIC:-not set}"214$msg "${cG}Cover image :$cZ ${PIC:-not set}"
197echo "Output dir : ${DIR:?Output directory was not set}"215$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"
198 216
199# file removal warning217# file removal warning
200if [ ${REMOVE} -eq 1 ]; then218if [ ${REMOVE} -eq 1 ]; then
201 echo -n "Also remove original"219 msg_removal="\n${cR}Also remove original"
202 if [ ${FORCE} -eq 1 ]; then220 if [ ${FORCE} -eq 1 ]; then
203 echo221 $msg "$msg_removal (WITHOUT ASKING)$cZ"
204 else222 else
205 echo " if user says 'y'"223 $msg "$msg_removal if user says 'y'$cZ"
206 fi224 fi
207fi225fi
208 226
@@ -214,7 +232,7 @@ if [ ${SAVE} -eq 1 ]; then · 5 unmodified lines
214 echo "NOPIC=${NOPIC}" >> "${CONFIG}"232 echo "NOPIC=${NOPIC}" >> "${CONFIG}"
215 echo "REMOVE=${REMOVE}" >> "${CONFIG}"233 echo "REMOVE=${REMOVE}" >> "${CONFIG}"
216 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"234 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"
217 echo "Configuration saved"235 $msg "${cP}Configuration saved$cZ"
218fi236fi
219 237
220GETTAG="cueprint -n 1 -t"238GETTAG="cueprint -n 1 -t"
@@ -236,14 +254,12 @@ if [ -n "${YEAR}" ]; then · 15 unmodified lines
236 fi254 fi
237fi255fi
238 256
239echo257$msg "\n${cG}Artist :$cZ ${TAG_ARTIST}"
240echo "Artist : ${TAG_ARTIST}"258$msg "${cG}Album :$cZ ${TAG_ALBUM}"
241echo "Album : ${TAG_ALBUM}"
242if [ -n "${TAG_DATE}" ]; then259if [ -n "${TAG_DATE}" ]; then
243 echo "Year : ${TAG_DATE}"260 $msg "${cG}Year :$cZ ${TAG_DATE}"
244fi261fi
245echo "Tracks : ${TRACKS_NUM}"262$msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n"
246echo
247 263
248# prepare output directory264# prepare output directory
249OUT="${DIR}"265OUT="${DIR}"
@@ -259,30 +275,28 @@ if [ ${NOSUBDIRS} -ne 1 ]; then · 9 unmodified lines
259 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"275 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
260fi276fi
261 277
262echo "Saving tracks to \"${OUT}\""278$msg "${cP}Saving tracks to $cZ\"${OUT}\""
263 279
264if [ ${DRY} -ne 1 ]; then280if [ ${DRY} -ne 1 ]; then
265 # create output dir281 # create output dir
266 mkdir -p "${OUT}"282 mkdir -p "${OUT}"
267 283
268 if [ $? -ne 0 ]; then284 if [ $? -ne 0 ]; then
269 echo "Failed to create output directory"285 fatal "Failed to create output directory"
270 exit 1
271 fi286 fi
272 287
273 case ${FORMAT} in288 case ${FORMAT} in
274 flac) ENC="flac flac -8 - -o %f";;289 flac) ENC="flac flac -8 - -o %f";;
275 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;290 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
276 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;291 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
277 *) echo "Unknown output format ${FORMAT}"; exit 1;;292 *) fatal "Unknown output format ${FORMAT}";;
278 esac293 esac
279 294
280 # split to tracks295 # split to tracks
281 cuebreakpoints "${CUE}" | \296 cuebreakpoints "${CUE}" | \
282 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"297 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
283 if [ $? -ne 0 ]; then298 if [ $? -ne 0 ]; then
284 echo "Failed to split"299 fatal "Failed to split"
285 exit 1
286 fi300 fi
287 301
288 # prepare cover image302 # prepare cover image
@@ -291,15 +305,14 @@ if [ ${DRY} -ne 1 ]; then · 2 unmodified lines
291 if [ $? -eq 0 ]; then305 if [ $? -eq 0 ]; then
292 PIC="${TMPPIC}"306 PIC="${TMPPIC}"
293 else307 else
294 echo "Failed to convert cover image"308 $msg "${cR}Failed to convert cover image$cZ"
295 unset PIC309 unset PIC
296 fi310 fi
297 fi311 fi
298fi312fi
299 313
300# set tags and rename314# set tags and rename
301echo315$msg "\n${cP}Setting tags$cZ"
302echo "Setting tags"
303 316
304i=1317i=1
305while [ $i -le ${TRACKS_NUM} ]; do318while [ $i -le ${TRACKS_NUM} ]; do
@@ -308,15 +321,14 @@ while [ $i -le ${TRACKS_NUM} ]; do · 2 unmodified lines
308 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})321 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
309 f="${OUT}/${FILE_TRACK}.${FORMAT}"322 f="${OUT}/${FILE_TRACK}.${FORMAT}"
310 323
311 echo "$i: ${TAG_TITLE}"324 $msg "$i: $cG${TAG_TITLE}$cZ"
312 325
313 if [ ${NORENAME} -ne 1 ]; then326 if [ ${NORENAME} -ne 1 ]; then
314 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"327 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
315 if [ ${DRY} -ne 1 ]; then328 if [ ${DRY} -ne 1 ]; then
316 mv "$f" "${FINAL}"329 mv "$f" "${FINAL}"
317 if [ $? -ne 0 ]; then330 if [ $? -ne 0 ]; then
318 echo "Failed to rename track file"331 fatal "Failed to rename track file"
319 exit 1
320 fi332 fi
321 fi333 fi
322 else334 else
@@ -373,16 +385,16 @@ while [ $i -le ${TRACKS_NUM} ]; do · 50 unmodified lines
373 RES=$((${RES} + $?))385 RES=$((${RES} + $?))
374 fi386 fi
375 ;;387 ;;
376 *) echo "Unknown output format ${FORMAT}"; exit 1;;388 *)
389 fatal "Unknown output format ${FORMAT}";;
377 esac390 esac
378 391
379 if [ ${RES} -ne 0 ]; then392 if [ ${RES} -ne 0 ]; then
380 echo "Failed to set tags for track"393 fatal "Failed to set tags for track"
381 exit 1
382 fi394 fi
383 fi395 fi
384 396
385 echo " -> ${FINAL}"397 $msg " -> ${cP}${FINAL}$cZ"
386 398
387 i=$(($i + 1))399 i=$(($i + 1))
388done400done
@@ -403,5 +415,4 @@ if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]; then · 14 unmodified lines
403 fi415 fi
404fi416fi
405 417
406echo418$msg "\n${cP}Finished$cZ"
407echo "Finished"

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