History

use tabs instead of spaces if possible

Serge Zirukin committed 16 years ago

Commit 10bb59c1 parent 390d89d1 file · +458 −458Browse files

Unified · Split

split2flac.sh+458−458
@@ -96,73 +96,73 @@ It also supports internal CUE sheets (FLAC, APE and WV)." · 95 unmodified lines
96msg="echo -e"96msg="echo -e"
97 97
98emsg () {98emsg () {
99 $msg "${cR}$1${cZ}"99 $msg "${cR}$1${cZ}"
100}100}
101 101
102update_colors () {102update_colors () {
103 if [ "${NOCOLORS}" -eq 0 ]; then103 if [ "${NOCOLORS}" -eq 0 ]; then
104 cR="\033[31m"104 cR="\033[31m"
105 cG="\033[32m"105 cG="\033[32m"
106 cC="\033[35m"106 cC="\033[35m"
107 cP="\033[36m"107 cP="\033[36m"
108 cU="\033[4m"108 cU="\033[4m"
109 cZ="\033[0m"109 cZ="\033[0m"
110 else110 else
111 unset cR cG cC cP cU cZ111 unset cR cG cC cP cU cZ
112 fi112 fi
113}113}
114 114
115update_colors115update_colors
116 116
117# parse arguments117# parse arguments
118while [ "$1" ]; do118while [ "$1" ]; do
119 case "$1" in119 case "$1" in
120 -o) DIR=$2; shift;;120 -o) DIR=$2; shift;;
121 -cue) CUE=$2; shift;;121 -cue) CUE=$2; shift;;
122 -cuecharset) CHARSET=$2; shift;;122 -cuecharset) CHARSET=$2; shift;;
123 -f) FORMAT=$2; shift;;123 -f) FORMAT=$2; shift;;
124 -c) NOPIC=0; PIC=$2; shift;;124 -c) NOPIC=0; PIC=$2; shift;;
125 -nc) NOPIC=1;;125 -nc) NOPIC=1;;
126 -cs) PIC_SIZE=$2; shift;;126 -cs) PIC_SIZE=$2; shift;;
127 -d) NOSUBDIRS=0;;127 -d) NOSUBDIRS=0;;
128 -nd) NOSUBDIRS=1;;128 -nd) NOSUBDIRS=1;;
129 -r) NORENAME=0;;129 -r) NORENAME=0;;
130 -nr) NORENAME=1;;130 -nr) NORENAME=1;;
131 -p) DRY=1;;131 -p) DRY=1;;
132 -D) REMOVE=1;;132 -D) REMOVE=1;;
133 -nD) REMOVE=0;;133 -nD) REMOVE=0;;
134 -F) FORCE=1;;134 -F) FORCE=1;;
135 -colors) NOCOLORS=0; update_colors;;135 -colors) NOCOLORS=0; update_colors;;
136 -nocolors) NOCOLORS=1; update_colors;;136 -nocolors) NOCOLORS=1; update_colors;;
137 -s) SAVE=1;;137 -s) SAVE=1;;
138 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;138 -h|--help|-help) eval "$msg \"${HELP}\""; exit 0;;
139 -v|--version) $msg "split2${FORMAT} version: ${VERSION}"; exit 0;;139 -v|--version) $msg "split2${FORMAT} version: ${VERSION}"; exit 0;;
140 -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;;140 -*) eval "$msg \"${HELP}\""; emsg "\nUnknown option $1"; exit 1;;
141 *)141 *)
142 if [ "${INPATH}" ]; then142 if [ "${INPATH}" ]; then
143 eval "$msg \"${HELP}\""143 eval "$msg \"${HELP}\""
144 emsg "\nUnknown option $1"144 emsg "\nUnknown option $1"
145 exit 1145 exit 1
146 elif [ ! -r "$1" ]; then146 elif [ ! -r "$1" ]; then
147 emsg "Unable to read $1"147 emsg "Unable to read $1"
148 exit 2148 exit 2
149 else149 else
150 INPATH="$1"150 INPATH="$1"
151 fi;;151 fi;;
152 esac152 esac
153 shift153 shift
154done154done
155 155
156# save configuration if needed156# save configuration if needed
157if [ ${SAVE} -eq 1 ]; then157if [ ${SAVE} -eq 1 ]; then
158 echo "DIR=\"${DIR}\"" > "${CONFIG}"158 echo "DIR=\"${DIR}\"" > "${CONFIG}"
159 echo "NOSUBDIRS=${NOSUBDIRS}" >> "${CONFIG}"159 echo "NOSUBDIRS=${NOSUBDIRS}" >> "${CONFIG}"
160 echo "NORENAME=${NORENAME}" >> "${CONFIG}"160 echo "NORENAME=${NORENAME}" >> "${CONFIG}"
161 echo "NOPIC=${NOPIC}" >> "${CONFIG}"161 echo "NOPIC=${NOPIC}" >> "${CONFIG}"
162 echo "REMOVE=${REMOVE}" >> "${CONFIG}"162 echo "REMOVE=${REMOVE}" >> "${CONFIG}"
163 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"163 echo "PIC_SIZE=${PIC_SIZE}" >> "${CONFIG}"
164 echo "NOCOLORS=${NOCOLORS}" >> "${CONFIG}"164 echo "NOCOLORS=${NOCOLORS}" >> "${CONFIG}"
165 $msg "${cP}Configuration saved$cZ"165 $msg "${cP}Configuration saved$cZ"
166fi166fi
167 167
168METAFLAC="metaflac --no-utf8-convert"168METAFLAC="metaflac --no-utf8-convert"
@@ -175,427 +175,427 @@ VALIDATE="sed s/[^-[:space:][:alnum:]&_#,.'\"\(\)!?]//g" · 6 unmodified lines
175# check & print output format175# check & print output format
176msg_format="${cG}Output format :$cZ"176msg_format="${cG}Output format :$cZ"
177case ${FORMAT} in177case ${FORMAT} in
178 flac) $msg "$msg_format FLAC";;178 flac) $msg "$msg_format FLAC";;
179 m4a) $msg "$msg_format M4A";;179 m4a) $msg "$msg_format M4A";;
180 mp3) $msg "$msg_format MP3";;180 mp3) $msg "$msg_format MP3";;
181 ogg) $msg "$msg_format OGG VORBIS";;181 ogg) $msg "$msg_format OGG VORBIS";;
182 wav) $msg "$msg_format WAVE";;182 wav) $msg "$msg_format WAVE";;
183 *) emsg "Unknown output format \"${FORMAT}\""; exit 1;;183 *) emsg "Unknown output format \"${FORMAT}\""; exit 1;;
184esac184esac
185 185
186$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"186$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"
187 187
188# splits a file188# splits a file
189split_file () {189split_file () {
190 FILE="$1"190 FILE="$1"
191 191
192 if [ ! -r "${FILE}" ]; then192 if [ ! -r "${FILE}" ]; then
193 emsg "Can not read the file"193 emsg "Can not read the file"
194 return 1194 return 1
195 fi195 fi
196 196
197 # search for a cue sheet if not specified197 # search for a cue sheet if not specified
198 if [ -z "${CUE}" ]; then198 if [ -z "${CUE}" ]; then
199 CUE="${FILE}.cue"199 CUE="${FILE}.cue"
200 if [ ! -r "${CUE}" ]; then200 if [ ! -r "${CUE}" ]; then
201 CUE="${FILE%.*}.cue"201 CUE="${FILE%.*}.cue"
202 if [ ! -r "${CUE}" ]; then202 if [ ! -r "${CUE}" ]; then
203 # try to extract internal one203 # try to extract internal one
204 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')204 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')
205 205
206 # try WV internal cue sheet206 # try WV internal cue sheet
207 if [ -z "${CUESHEET}" ]; then207 if [ -z "${CUESHEET}" ]; then
208 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)208 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
209 fi209 fi
210 210
211 # try APE internal cue sheet (omfg!)211 # try APE internal cue sheet (omfg!)
212 if [ -z "${CUESHEET}" ]; then212 if [ -z "${CUESHEET}" ]; then
213 APETAGEX=$(tail -c 32 "$1" | cut -b 1-8 2>/dev/null)213 APETAGEX=$(tail -c 32 "$1" | cut -b 1-8 2>/dev/null)
214 if [ "${APETAGEX}" = "APETAGEX" ]; then214 if [ "${APETAGEX}" = "APETAGEX" ]; then
215 LENGTH=$(tail -c 32 "$1" | cut -b 13-16 | od -t u4 | awk '{printf $2}') 2>/dev/null215 LENGTH=$(tail -c 32 "$1" | cut -b 13-16 | od -t u4 | awk '{printf $2}') 2>/dev/null
216 tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1216 tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1
217 if [ $? -eq 0 ]; then217 if [ $? -eq 0 ]; then
218 CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null)218 CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null)
219 if [ $? -ne 0 ]; then219 if [ $? -ne 0 ]; then
220 CUESHEET=""220 CUESHEET=""
221 fi221 fi
222 fi222 fi
223 fi223 fi
224 fi224 fi
225 225
226 if [ "${CUESHEET}" ]; then226 if [ "${CUESHEET}" ]; then
227 $msg "${cP}Found internal cue sheet$cZ"227 $msg "${cP}Found internal cue sheet$cZ"
228 CUE="${TMPCUE}"228 CUE="${TMPCUE}"
229 echo "${CUESHEET}" > "${CUE}"229 echo "${CUESHEET}" > "${CUE}"
230 230
231 if [ $? -ne 0 ]; then231 if [ $? -ne 0 ]; then
232 emsg "Unable to save internal cue sheet"232 emsg "Unable to save internal cue sheet"
233 return 1233 return 1
234 fi234 fi
235 else235 else
236 unset CUE236 unset CUE
237 fi237 fi
238 fi238 fi
239 fi239 fi
240 fi240 fi
241 241
242 # print cue sheet filename242 # print cue sheet filename
243 if [ -z "${CUE}" ]; then243 if [ -z "${CUE}" ]; then
244 emsg "No cue sheet"244 emsg "No cue sheet"
245 return 1245 return 1
246 fi246 fi
247 247
248 if [ "${CHARSET}" ]; then248 if [ "${CHARSET}" ]; then
249 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"249 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"
250 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)250 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
251 if [ $? -ne 0 ]; then251 if [ $? -ne 0 ]; then
252 emsg "Unable to convert cue sheet from ${CHARSET} to utf-8"252 emsg "Unable to convert cue sheet from ${CHARSET} to utf-8"
253 return 1253 return 1
254 fi254 fi
255 CUE="${TMPCUE}"255 CUE="${TMPCUE}"
256 echo "${CUESHEET}" > "${CUE}"256 echo "${CUESHEET}" > "${CUE}"
257 257
258 if [ $? -ne 0 ]; then258 if [ $? -ne 0 ]; then
259 emsg "Unable to save converted cue sheet"259 emsg "Unable to save converted cue sheet"
260 return 1260 return 1
261 fi261 fi
262 fi262 fi
263 263
264 # search for a front cover image264 # search for a front cover image
265 if [ ${NOPIC} -eq 1 ]; then265 if [ ${NOPIC} -eq 1 ]; then
266 unset PIC266 unset PIC
267 elif [ -z "${PIC}" ]; then267 elif [ -z "${PIC}" ]; then
268 # try common names 268 # try common names
269 SDIR=$(dirname "${FILE}")269 SDIR=$(dirname "${FILE}")
270 270
271 for i in cover.jpg front_cover.jpg folder.jpg; do271 for i in cover.jpg front_cover.jpg folder.jpg; do
272 if [ -r "${SDIR}/$i" ]; then272 if [ -r "${SDIR}/$i" ]; then
273 PIC="${SDIR}/$i"273 PIC="${SDIR}/$i"
274 break274 break
275 fi275 fi
276 done276 done
277 277
278 # try to extract internal one278 # try to extract internal one
279 if [ -z "${PIC}" ]; then279 if [ -z "${PIC}" ]; then
280 ${METAFLAC} --export-picture-to="${TMPPIC}" "${FILE}" 2>/dev/null280 ${METAFLAC} --export-picture-to="${TMPPIC}" "${FILE}" 2>/dev/null
281 if [ $? -ne 0 ]; then281 if [ $? -ne 0 ]; then
282 unset PIC282 unset PIC
283 else283 else
284 PIC="${TMPPIC}"284 PIC="${TMPPIC}"
285 fi285 fi
286 fi286 fi
287 fi287 fi
288 288
289 $msg "${cG}Cue sheet :$cZ ${CUE}"289 $msg "${cG}Cue sheet :$cZ ${CUE}"
290 $msg "${cG}Cover image :$cZ ${PIC:-not set}"290 $msg "${cG}Cover image :$cZ ${PIC:-not set}"
291 291
292 # file removal warning292 # file removal warning
293 if [ ${REMOVE} -eq 1 ]; then293 if [ ${REMOVE} -eq 1 ]; then
294 msg_removal="\n${cR}Also remove original"294 msg_removal="\n${cR}Also remove original"
295 if [ ${FORCE} -eq 1 ]; then295 if [ ${FORCE} -eq 1 ]; then
296 $msg "$msg_removal (WITHOUT ASKING)$cZ"296 $msg "$msg_removal (WITHOUT ASKING)$cZ"
297 else297 else
298 $msg "$msg_removal if user says 'y'$cZ"298 $msg "$msg_removal if user says 'y'$cZ"
299 fi299 fi
300 fi300 fi
301 301
302 # get common tags302 # get common tags
303 TAG_ARTIST=$(${GETTAG} %P "${CUE}" 2>/dev/null)303 TAG_ARTIST=$(${GETTAG} %P "${CUE}" 2>/dev/null)
304 TAG_ALBUM=$(${GETTAG} %T "${CUE}" 2>/dev/null)304 TAG_ALBUM=$(${GETTAG} %T "${CUE}" 2>/dev/null)
305 TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)305 TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)
306 306
307 if [ -z "${TRACKS_NUM}" ]; then307 if [ -z "${TRACKS_NUM}" ]; then
308 emsg "Failed to get number of tracks from CUE sheet."308 emsg "Failed to get number of tracks from CUE sheet."
309 emsg "There may be an error in the sheet."309 emsg "There may be an error in the sheet."
310 emsg "Running ${GETTAG} %N \"${CUE}\" produces this:"310 emsg "Running ${GETTAG} %N \"${CUE}\" produces this:"
311 ${GETTAG} %N "${CUE}"311 ${GETTAG} %N "${CUE}"
312 return 1312 return 1
313 fi313 fi
314 314
315 TAG_GENRE=$(awk '{ if (/REM[ \t]+GENRE[ \t]+(.*)/) { print $0; exit } }' < "${CUE}")315 TAG_GENRE=$(awk '{ if (/REM[ \t]+GENRE[ \t]+(.*)/) { print $0; exit } }' < "${CUE}")
316 TAG_GENRE=$(echo ${TAG_GENRE} | sed 's/REM[ \t]\+GENRE[ \t]\+//;s/"\(.*\)"/\1/')316 TAG_GENRE=$(echo ${TAG_GENRE} | sed 's/REM[ \t]\+GENRE[ \t]\+//;s/"\(.*\)"/\1/')
317 317
318 YEAR=$(awk '{ if (/REM[ \t]+DATE/) { printf "%i", $3; exit } }' < "${CUE}")318 YEAR=$(awk '{ if (/REM[ \t]+DATE/) { printf "%i", $3; exit } }' < "${CUE}")
319 YEAR=$(echo ${YEAR} | tr -d -c '[:digit:]')319 YEAR=$(echo ${YEAR} | tr -d -c '[:digit:]')
320 320
321 unset TAG_DATE321 unset TAG_DATE
322 322
323 if [ "${YEAR}" ]; then323 if [ "${YEAR}" ]; then
324 if [ ${YEAR} -ne 0 ]; then324 if [ ${YEAR} -ne 0 ]; then
325 TAG_DATE="${YEAR}"325 TAG_DATE="${YEAR}"
326 fi326 fi
327 fi327 fi
328 328
329 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}"329 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}"
330 $msg "${cG}Album :$cZ ${TAG_ALBUM}"330 $msg "${cG}Album :$cZ ${TAG_ALBUM}"
331 if [ "${TAG_GENRE}" ]; then331 if [ "${TAG_GENRE}" ]; then
332 $msg "${cG}Genre :$cZ ${TAG_GENRE}"332 $msg "${cG}Genre :$cZ ${TAG_GENRE}"
333 fi333 fi
334 if [ "${TAG_DATE}" ]; then334 if [ "${TAG_DATE}" ]; then
335 $msg "${cG}Year :$cZ ${TAG_DATE}"335 $msg "${cG}Year :$cZ ${TAG_DATE}"
336 fi336 fi
337 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n"337 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n"
338 338
339 # prepare output directory339 # prepare output directory
340 OUT="${DIR}"340 OUT="${DIR}"
341 341
342 if [ ${NOSUBDIRS} -ne 1 ]; then342 if [ ${NOSUBDIRS} -ne 1 ]; then
343 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})343 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})
344 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})344 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})
345 345
346 if [ "${TAG_DATE}" ]; then346 if [ "${TAG_DATE}" ]; then
347 DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"347 DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"
348 fi348 fi
349 349
350 if [ ${DRY} -ne 1 ]; then350 if [ ${DRY} -ne 1 ]; then
351 mkdir -p "${OUT}/${DIR_ARTIST}"351 mkdir -p "${OUT}/${DIR_ARTIST}"
352 fi352 fi
353 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"353 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
354 fi354 fi
355 355
356 $msg "${cP}Saving tracks to $cZ\"${OUT}\""356 $msg "${cP}Saving tracks to $cZ\"${OUT}\""
357 357
358 if [ ${DRY} -ne 1 ]; then358 if [ ${DRY} -ne 1 ]; then
359 # create output dir359 # create output dir
360 mkdir "${OUT}"360 mkdir "${OUT}"
361 361
362 if [ $? -ne 0 -a ${NOSUBDIRS} -ne 1 ]; then362 if [ $? -ne 0 -a ${NOSUBDIRS} -ne 1 ]; then
363 emsg "Failed to create output directory (already splitted?)"363 emsg "Failed to create output directory (already splitted?)"
364 return 1364 return 1
365 fi365 fi
366 366
367 case ${FORMAT} in367 case ${FORMAT} in
368 flac) ENC="flac flac -8 - -o %f";;368 flac) ENC="flac flac -8 - -o %f";;
369 m4a) ENC="cust ext=m4a faac -q 500 -o %f -";;369 m4a) ENC="cust ext=m4a faac -q 500 -o %f -";;
370 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;370 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
371 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;371 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
372 wav) ENC="wav";;372 wav) ENC="wav";;
373 *) emsg "Unknown output format ${FORMAT}"; exit 1;;373 *) emsg "Unknown output format ${FORMAT}"; exit 1;;
374 esac374 esac
375 375
376 # split to tracks376 # split to tracks
377 cuebreakpoints "${CUE}" 2>/dev/null | \377 cuebreakpoints "${CUE}" 2>/dev/null | \
378 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"378 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
379 if [ $? -ne 0 ]; then379 if [ $? -ne 0 ]; then
380 emsg "Failed to split"380 emsg "Failed to split"
381 return 1381 return 1
382 fi382 fi
383 383
384 # prepare cover image384 # prepare cover image
385 if [ "${PIC}" ]; then385 if [ "${PIC}" ]; then
386 convert "${PIC}" -resize "${PIC_SIZE}" "${TMPPIC}"386 convert "${PIC}" -resize "${PIC_SIZE}" "${TMPPIC}"
387 if [ $? -eq 0 ]; then387 if [ $? -eq 0 ]; then
388 PIC="${TMPPIC}"388 PIC="${TMPPIC}"
389 else389 else
390 $msg "${cR}Failed to convert cover image$cZ"390 $msg "${cR}Failed to convert cover image$cZ"
391 unset PIC391 unset PIC
392 fi392 fi
393 fi393 fi
394 fi394 fi
395 395
396 # set tags and rename396 # set tags and rename
397 $msg "\n${cP}Setting tags$cZ"397 $msg "\n${cP}Setting tags$cZ"
398 398
399 i=1399 i=1
400 while [ $i -le ${TRACKS_NUM} ]; do400 while [ $i -le ${TRACKS_NUM} ]; do
401 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}" 2>/dev/null)401 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}" 2>/dev/null)
402 FILE_TRACK="$(printf %02i $i)"402 FILE_TRACK="$(printf %02i $i)"
403 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})403 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
404 f="${OUT}/${FILE_TRACK}.${FORMAT}"404 f="${OUT}/${FILE_TRACK}.${FORMAT}"
405 405
406 $msg "$i: $cG${TAG_TITLE}$cZ"406 $msg "$i: $cG${TAG_TITLE}$cZ"
407 407
408 if [ ${NORENAME} -ne 1 ]; then408 if [ ${NORENAME} -ne 1 ]; then
409 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"409 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
410 if [ ${DRY} -ne 1 ]; then410 if [ ${DRY} -ne 1 ]; then
411 mv "$f" "${FINAL}"411 mv "$f" "${FINAL}"
412 if [ $? -ne 0 ]; then412 if [ $? -ne 0 ]; then
413 emsg "Failed to rename track file"413 emsg "Failed to rename track file"
414 return 1414 return 1
415 fi415 fi
416 fi416 fi
417 else417 else
418 FINAL="$f"418 FINAL="$f"
419 fi419 fi
420 420
421 if [ ${DRY} -ne 1 ]; then421 if [ ${DRY} -ne 1 ]; then
422 case ${FORMAT} in422 case ${FORMAT} in
423 flac)423 flac)
424 ${METAFLAC} --remove-all-tags \424 ${METAFLAC} --remove-all-tags \
425 --set-tag="ARTIST=${TAG_ARTIST}" \425 --set-tag="ARTIST=${TAG_ARTIST}" \
426 --set-tag="ALBUM=${TAG_ALBUM}" \426 --set-tag="ALBUM=${TAG_ALBUM}" \
427 --set-tag="TITLE=${TAG_TITLE}" \427 --set-tag="TITLE=${TAG_TITLE}" \
428 --set-tag="TRACKNUMBER=$i" \428 --set-tag="TRACKNUMBER=$i" \
429 "${FINAL}" >/dev/null429 "${FINAL}" >/dev/null
430 RES=$?430 RES=$?
431 431
432 if [ "${TAG_GENRE}" ]; then432 if [ "${TAG_GENRE}" ]; then
433 ${METAFLAC} --set-tag="GENRE=${TAG_GENRE}" "${FINAL}" >/dev/null433 ${METAFLAC} --set-tag="GENRE=${TAG_GENRE}" "${FINAL}" >/dev/null
434 RES=$RES$?434 RES=$RES$?
435 fi435 fi
436 436
437 if [ "${TAG_DATE}" ]; then437 if [ "${TAG_DATE}" ]; then
438 ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" >/dev/null438 ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" >/dev/null
439 RES=$RES$?439 RES=$RES$?
440 fi440 fi
441 441
442 if [ "${PIC}" ]; then442 if [ "${PIC}" ]; then
443 ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" >/dev/null443 ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" >/dev/null
444 RES=$RES$?444 RES=$RES$?
445 fi445 fi
446 ;;446 ;;
447 447
448 mp3)448 mp3)
449 ${ID3TAG} "-a${TAG_ARTIST}" \449 ${ID3TAG} "-a${TAG_ARTIST}" \
450 "-A${TAG_ALBUM}" \450 "-A${TAG_ALBUM}" \
451 "-s${TAG_TITLE}" \451 "-s${TAG_TITLE}" \
452 "-t$i" \452 "-t$i" \
453 "-T${TRACKS_NUM}" \453 "-T${TRACKS_NUM}" \
454 "${FINAL}" >/dev/null454 "${FINAL}" >/dev/null
455 RES=$?455 RES=$?
456 456
457 if [ "${TAG_GENRE}" ]; then457 if [ "${TAG_GENRE}" ]; then
458 ${ID3TAG} -g"${TAG_GENRE}" "${FINAL}" >/dev/null458 ${ID3TAG} -g"${TAG_GENRE}" "${FINAL}" >/dev/null
459 RES=$RES$?459 RES=$RES$?
460 fi460 fi
461 461
462 if [ "${TAG_DATE}" ]; then462 if [ "${TAG_DATE}" ]; then
463 ${ID3TAG} -y"${TAG_DATE}" "${FINAL}" >/dev/null463 ${ID3TAG} -y"${TAG_DATE}" "${FINAL}" >/dev/null
464 RES=$RES$?464 RES=$RES$?
465 fi465 fi
466 ;;466 ;;
467 467
468 ogg)468 ogg)
469 ${VORBISCOMMENT} "${FINAL}" \469 ${VORBISCOMMENT} "${FINAL}" \
470 -t "ARTIST=${TAG_ARTIST}" \470 -t "ARTIST=${TAG_ARTIST}" \
471 -t "ALBUM=${TAG_ALBUM}" \471 -t "ALBUM=${TAG_ALBUM}" \
472 -t "TITLE=${TAG_TITLE}" \472 -t "TITLE=${TAG_TITLE}" \
473 -t "TRACKNUMBER=$i" >/dev/null473 -t "TRACKNUMBER=$i" >/dev/null
474 RES=$?474 RES=$?
475 475
476 if [ "${TAG_GENRE}" ]; then476 if [ "${TAG_GENRE}" ]; then
477 ${VORBISCOMMENT} "${FINAL}" -t "GENRE=${TAG_GENRE}" >/dev/null477 ${VORBISCOMMENT} "${FINAL}" -t "GENRE=${TAG_GENRE}" >/dev/null
478 RES=$RES$?478 RES=$RES$?
479 fi479 fi
480 480
481 if [ "${TAG_DATE}" ]; then481 if [ "${TAG_DATE}" ]; then
482 ${VORBISCOMMENT} "${FINAL}" -t "DATE=${TAG_DATE}" >/dev/null482 ${VORBISCOMMENT} "${FINAL}" -t "DATE=${TAG_DATE}" >/dev/null
483 RES=$RES$?483 RES=$RES$?
484 fi484 fi
485 ;;485 ;;
486 486
487 m4a)487 m4a)
488 ${MP4TAGS} "${FINAL}" \488 ${MP4TAGS} "${FINAL}" \
489 -a "${TAG_ARTIST}" \489 -a "${TAG_ARTIST}" \
490 -A "${TAG_ALBUM}" \490 -A "${TAG_ALBUM}" \
491 -s "${TAG_TITLE}" \491 -s "${TAG_TITLE}" \
492 -t "$i" \492 -t "$i" \
493 -T "${TRACKS_NUM}" >/dev/null493 -T "${TRACKS_NUM}" >/dev/null
494 RES=$?494 RES=$?
495 495
496 if [ "${TAG_GENRE}" ]; then496 if [ "${TAG_GENRE}" ]; then
497 ${MP4TAGS} "${FINAL}" -g "${TAG_GENRE}" >/dev/null497 ${MP4TAGS} "${FINAL}" -g "${TAG_GENRE}" >/dev/null
498 RES=$RES$?498 RES=$RES$?
499 fi499 fi
500 500
501 if [ "${TAG_DATE}" ]; then501 if [ "${TAG_DATE}" ]; then
502 ${MP4TAGS} "${FINAL}" -y "${TAG_DATE}" >/dev/null502 ${MP4TAGS} "${FINAL}" -y "${TAG_DATE}" >/dev/null
503 RES=$RES$?503 RES=$RES$?
504 fi504 fi
505 505
506 if [ "${PIC}" ]; then506 if [ "${PIC}" ]; then
507 ${MP4TAGS} "${FINAL}" -P "${PIC}" >/dev/null507 ${MP4TAGS} "${FINAL}" -P "${PIC}" >/dev/null
508 RES=$RES$?508 RES=$RES$?
509 fi509 fi
510 ;;510 ;;
511 511
512 wav)512 wav)
513 RES=0513 RES=0
514 ;;514 ;;
515 515
516 *)516 *)
517 emsg "Unknown output format ${FORMAT}"517 emsg "Unknown output format ${FORMAT}"
518 return 1518 return 1
519 ;;519 ;;
520 esac520 esac
521 521
522 if [ ${RES} -ne 0 ]; then522 if [ ${RES} -ne 0 ]; then
523 emsg "Failed to set tags for track"523 emsg "Failed to set tags for track"
524 return 1524 return 1
525 fi525 fi
526 fi526 fi
527 527
528 $msg " -> ${cP}${FINAL}$cZ"528 $msg " -> ${cP}${FINAL}$cZ"
529 529
530 i=$(($i + 1))530 i=$(($i + 1))
531 done531 done
532 532
533 rm -f "${TMPPIC}"533 rm -f "${TMPPIC}"
534 rm -f "${TMPCUE}"534 rm -f "${TMPCUE}"
535 535
536 if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]; then536 if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]; then
537 YEP="n"537 YEP="n"
538 538
539 if [ ${FORCE} -ne 1 ]; then539 if [ ${FORCE} -ne 1 ]; then
540 echo -n "Are you sure you want to delete original? [y] >"540 echo -n "Are you sure you want to delete original? [y] >"
541 read YEP541 read YEP
542 fi542 fi
543 543
544 if [ "${YEP}" = "y" -o ${FORCE} -eq 1 ]; then544 if [ "${YEP}" = "y" -o ${FORCE} -eq 1 ]; then
545 rm -f "${FILE}"545 rm -f "${FILE}"
546 fi546 fi
547 fi547 fi
548 548
549 return 0549 return 0
550}550}
551 551
552split_collection () {552split_collection () {
553 NUM_FAILED=0553 NUM_FAILED=0
554 554
555 while read -r FILE; do555 while read -r FILE; do
556 $msg "$cG>> $cC\"${FILE}\"$cZ"556 $msg "$cG>> $cC\"${FILE}\"$cZ"
557 unset PIC CUE557 unset PIC CUE
558 split_file "${FILE}"558 split_file "${FILE}"
559 559
560 if [ ! $? -eq 0 ]; then560 if [ ! $? -eq 0 ]; then
561 emsg "Failed to split \"${FILE}\""561 emsg "Failed to split \"${FILE}\""
562 echo "${FILE}" >> "${FAILED}"562 echo "${FILE}" >> "${FAILED}"
563 NUM_FAILED=$((${NUM_FAILED} + 1))563 NUM_FAILED=$((${NUM_FAILED} + 1))
564 fi564 fi
565 565
566 echo566 echo
567 done567 done
568 568
569 if [ ${NUM_FAILED} -ne 0 ]; then569 if [ ${NUM_FAILED} -ne 0 ]; then
570 emsg "${NUM_FAILED} file(s) failed to split (already splited?):"570 emsg "${NUM_FAILED} file(s) failed to split (already splited?):"
571 $msg "${cR}"571 $msg "${cR}"
572 sort "${FAILED}" -o "${FAILED}"572 sort "${FAILED}" -o "${FAILED}"
573 cat "${FAILED}"573 cat "${FAILED}"
574 emsg "\nThese files are also listed in ${FAILED}."574 emsg "\nThese files are also listed in ${FAILED}."
575 return 1575 return 1
576 fi576 fi
577 577
578 return 0578 return 0
579}579}
580 580
581# searches for files in a directory and splits them581# searches for files in a directory and splits them
582split_dir () {582split_dir () {
583 rm -f "${FAILED}"583 rm -f "${FAILED}"
584 find "$1" -iname '*.flac' -o -iname '*.ape' -o -iname '*.wv' | split_collection584 find "$1" -iname '*.flac' -o -iname '*.ape' -o -iname '*.wv' | split_collection
585}585}
586 586
587if [ -d "${INPATH}" ]; then587if [ -d "${INPATH}" ]; then
588 if [ ! -x "${INPATH}" ]; then588 if [ ! -x "${INPATH}" ]; then
589 emsg "Directory \"${INPATH}\" is not accessible"589 emsg "Directory \"${INPATH}\" is not accessible"
590 exit 2590 exit 2
591 fi591 fi
592 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n"592 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n"
593 split_dir "${INPATH}"593 split_dir "${INPATH}"
594elif [ "${INPATH}" ]; then594elif [ "${INPATH}" ]; then
595 split_file "${INPATH}"595 split_file "${INPATH}"
596else596else
597 emsg "No input filename given. Use -h for help."597 emsg "No input filename given. Use -h for help."
598 exit 1598 exit 1
599fi599fi
600 600
601# exit code of split_dir or split_file601# exit code of split_dir or split_file
@@ -604,5 +604,5 @@ STATUS=$? · 2 unmodified lines
604$msg "\n${cP}Finished$cZ"604$msg "\n${cP}Finished$cZ"
605 605
606if [ ${STATUS} -ne 0 ]; then606if [ ${STATUS} -ne 0 ]; then
607 exit 3607 exit 3
608fi608fi

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