History

optionally (enabled by default) detect wrong cue charset, ask user for right charset. Fixes issue 8

Serge Zirukin committed 16 years ago

Commit 8462e141 parent a7ce4cc1 file · +61 −53Browse files

Unified · Split

split2flac.sh+61−53
@@ -54,6 +54,7 @@ DIR="." · 53 unmodified lines
54eval $(cat "${CONFIG}" 2>/dev/null)54eval $(cat "${CONFIG}" 2>/dev/null)
55DRY=055DRY=0
56SAVE=056SAVE=0
57NASK=0
57unset PIC INPATH CUE CHARSET58unset PIC INPATH CUE CHARSET
58FORCE=059FORCE=0
59 60
@@ -68,6 +69,7 @@ Usage: \${cZ}split2\${FORMAT}.sh [\${cU}OPTIONS\$cZ] \${cU}FILE\$cZ [\${cU}OPTIO · 8 unmodified lines
68 \$cG-o \${cU}DIRECTORY\$cZ \$cR*\$cZ - set output directory (current is \$cP\${DIR}\$cZ)69 \$cG-o \${cU}DIRECTORY\$cZ \$cR*\$cZ - set output directory (current is \$cP\${DIR}\$cZ)
69 \$cG-cue \${cU}FILE\$cZ - use file as a cue sheet (does not work with \${cU}DIR\$cZ)70 \$cG-cue \${cU}FILE\$cZ - use file as a cue sheet (does not work with \${cU}DIR\$cZ)
70 \$cG-cuecharset \${cU}CHARSET\$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default)71 \$cG-cuecharset \${cU}CHARSET\$cZ - convert cue sheet from CHARSET to UTF-8 (no conversion by default)
72 \$cG-nask\$cZ - do not ask to enter proper charset of a cue sheet (default is to ask)
71 \$cG-f \${cU}FORMAT\$cZ - use specified output format \$cP(current is \${FORMAT})\$cZ73 \$cG-f \${cU}FORMAT\$cZ - use specified output format \$cP(current is \${FORMAT})\$cZ
72 \$cG-c \${cU}FILE\$cZ \$cR*\$cZ - use file as a cover image (does not work with \${cU}DIR\$cZ)74 \$cG-c \${cU}FILE\$cZ \$cR*\$cZ - use file as a cover image (does not work with \${cU}DIR\$cZ)
73 \$cG-nc \${cR}*\$cZ - do not set any cover images75 \$cG-nc \${cR}*\$cZ - do not set any cover images
@@ -124,6 +126,7 @@ while [ "$1" ]; do · 50 unmodified lines
124 -o) DIR=$2; shift;;126 -o) DIR=$2; shift;;
125 -cue) CUE=$2; shift;;127 -cue) CUE=$2; shift;;
126 -cuecharset) CHARSET=$2; shift;;128 -cuecharset) CHARSET=$2; shift;;
129 -nask) NASK=1;;
127 -f) FORMAT=$2; shift;;130 -f) FORMAT=$2; shift;;
128 -c) NOPIC=0; PIC=$2; shift;;131 -c) NOPIC=0; PIC=$2; shift;;
129 -nc) NOPIC=1;;132 -nc) NOPIC=1;;
@@ -211,9 +214,7 @@ split_file () { · 81 unmodified lines
211 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')214 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')
212 215
213 # try WV internal cue sheet216 # try WV internal cue sheet
214 if [ -z "${CUESHEET}" ]; then217 [ -z "${CUESHEET}" ] && CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
215 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
216 fi
217 218
218 # try APE internal cue sheet (omfg!)219 # try APE internal cue sheet (omfg!)
219 if [ -z "${CUESHEET}" ]; then220 if [ -z "${CUESHEET}" ]; then
@@ -223,9 +224,7 @@ split_file () { · 3 unmodified lines
223 tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1224 tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1
224 if [ $? -eq 0 ]; then225 if [ $? -eq 0 ]; then
225 CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null)226 CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null)
226 if [ $? -ne 0 ]; then227 [ $? -ne 0 ] && CUESHEET=""
227 CUESHEET=""
228 fi
229 fi228 fi
230 fi229 fi
231 fi230 fi
@@ -252,13 +251,35 @@ split_file () { · 20 unmodified lines
252 return 1251 return 1
253 fi252 fi
254 253
255 if [ "${CHARSET}" ]; then254 # cue sheet charset
256 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ\n"255 [ -z "${CHARSET}" ] && CHARSET="utf-8" || $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ\n"
257 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)256
258 if [ $? -ne 0 ]; then257 CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
259 emsg "Unable to convert cue sheet from ${CHARSET} to utf-8\n"258
260 return 1259 if [ $? -ne 0 ]; then
260 [ "${CHARSET}" = "utf-8" ] \
261 && emsg "Cue sheet is not utf-8\n" \
262 || emsg "Unable to convert cue sheet from ${CHARSET} to utf-8\n"
263
264 if [ ${NASK} -eq 0 ]; then
265 while [ 1 ]; do
266 echo -n "Please enter the charset (or just press ENTER to ignore) > "
267 read CHARSET
268
269 [ -z "${CHARSET}" ] && break
270 $msg "${cG}Converted cue sheet:$cZ\n"
271 iconv -f "${CHARSET}" -t utf-8 "${CUE}" || continue
272
273 echo -n "Is this right? [Y/n] > "
274 read YEP
275 [ -z "${YEP}" -o "${YEP}" = "y" -o "${YEP}" = "Y" ] && break
276 done
277
278 CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
261 fi279 fi
280 fi
281
282 if [ "${CHARSET}" -a "${CHARSET}" != "utf-8" ]; then
262 CUE="${TMPCUE}"283 CUE="${TMPCUE}"
263 echo "${CUESHEET}" > "${CUE}"284 echo "${CUESHEET}" > "${CUE}"
264 285
@@ -299,11 +320,9 @@ split_file () { · 34 unmodified lines
299 # file removal warning320 # file removal warning
300 if [ ${REMOVE} -eq 1 ]; then321 if [ ${REMOVE} -eq 1 ]; then
301 msg_removal="\n${cR}Also remove original"322 msg_removal="\n${cR}Also remove original"
302 if [ ${FORCE} -eq 1 ]; then323 [ ${FORCE} -eq 1 ] \
303 $msg "$msg_removal (WITHOUT ASKING)$cZ\n"324 && $msg "$msg_removal (WITHOUT ASKING)$cZ\n" \
304 else325 || $msg "$msg_removal if user says 'y'$cZ\n"
305 $msg "$msg_removal if user says 'y'$cZ\n"
306 fi
307 fi326 fi
308 327
309 # get common tags328 # get common tags
@@ -328,19 +347,13 @@ split_file () { · 18 unmodified lines
328 unset TAG_DATE347 unset TAG_DATE
329 348
330 if [ "${YEAR}" ]; then349 if [ "${YEAR}" ]; then
331 if [ ${YEAR} -ne 0 ]; then350 [ ${YEAR} -ne 0 ] && TAG_DATE="${YEAR}"
332 TAG_DATE="${YEAR}"
333 fi
334 fi351 fi
335 352
336 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}\n"353 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}\n"
337 $msg "${cG}Album :$cZ ${TAG_ALBUM}\n"354 $msg "${cG}Album :$cZ ${TAG_ALBUM}\n"
338 if [ "${TAG_GENRE}" ]; then355 [ "${TAG_GENRE}" ] && $msg "${cG}Genre :$cZ ${TAG_GENRE}\n"
339 $msg "${cG}Genre :$cZ ${TAG_GENRE}\n"356 [ "${TAG_DATE}" ] && $msg "${cG}Year :$cZ ${TAG_DATE}\n"
340 fi
341 if [ "${TAG_DATE}" ]; then
342 $msg "${cG}Year :$cZ ${TAG_DATE}\n"
343 fi
344 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n\n"357 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n\n"
345 358
346 # prepare output directory359 # prepare output directory
@@ -350,13 +363,9 @@ split_file () { · 3 unmodified lines
350 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})363 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})
351 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})364 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})
352 365
353 if [ "${TAG_DATE}" ]; then366 [ "${TAG_DATE}" ] && DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"
354 DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"367 [ ${DRY} -ne 1 ] && mkdir -p "${OUT}/${DIR_ARTIST}"
355 fi
356 368
357 if [ ${DRY} -ne 1 ]; then
358 mkdir -p "${OUT}/${DIR_ARTIST}"
359 fi
360 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"369 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
361 fi370 fi
362 371
@@ -544,11 +553,11 @@ split_file () { · 181 unmodified lines
544 553
545 if [ ${DRY} -ne 1 ]; then554 if [ ${DRY} -ne 1 ]; then
546 ${RG} "${OUT}/"*.${FORMAT} >/dev/null555 ${RG} "${OUT}/"*.${FORMAT} >/dev/null
547 fi
548 556
549 if [ $? -ne 0 ]; then557 if [ $? -ne 0 ]; then
550 emsg "Failed to adjust gain for track\n"558 emsg "Failed to adjust gain for track\n"
551 return 1559 return 1
560 fi
552 fi561 fi
553 fi562 fi
554 563
@@ -559,22 +568,29 @@ split_file () { · 4 unmodified lines
559 YEP="n"568 YEP="n"
560 569
561 if [ ${FORCE} -ne 1 ]; then570 if [ ${FORCE} -ne 1 ]; then
562 echo -n "Are you sure you want to delete original? [y] >"571 echo -n "Are you sure you want to delete original? [y/N] > "
563 read YEP572 read YEP
564 fi573 fi
565 574
566 if [ "${YEP}" = "y" -o ${FORCE} -eq 1 ]; then575 [ "${YEP}" = "y" -o "${YEP}" = "Y" -o ${FORCE} -eq 1 ] && rm -f "${FILE}"
567 rm -f "${FILE}"
568 fi
569 fi576 fi
570 577
571 return 0578 return 0
572}579}
573 580
581# searches for files in a directory and splits them
574split_collection () {582split_collection () {
583 rm -f "${FAILED}"
575 NUM_FAILED=0584 NUM_FAILED=0
576 585 OLDIFS=${IFS}
577 while read -r FILE; do586 OLDCHARSET="${CHARSET}"
587 # set IFS to newline. we do not use 'read' here because we may want to ask user for input
588 IFS="
589"
590
591 for FILE in `find "$1" -iname '*.flac' -o -iname '*.ape' -o -iname '*.wv'`; do
592 IFS=${OLDIFS}
593 CHARSET=${OLDCHARSET}
578 $msg "$cG>> $cC\"${FILE}\"$cZ\n"594 $msg "$cG>> $cC\"${FILE}\"$cZ\n"
579 unset PIC CUE595 unset PIC CUE
580 split_file "${FILE}"596 split_file "${FILE}"
@@ -600,19 +616,13 @@ split_collection () { · 19 unmodified lines
600 return 0616 return 0
601}617}
602 618
603# searches for files in a directory and splits them
604split_dir () {
605 rm -f "${FAILED}"
606 find "$1" -iname '*.flac' -o -iname '*.ape' -o -iname '*.wv' | split_collection
607}
608
609if [ -d "${INPATH}" ]; then619if [ -d "${INPATH}" ]; then
610 if [ ! -x "${INPATH}" ]; then620 if [ ! -x "${INPATH}" ]; then
611 emsg "Directory \"${INPATH}\" is not accessible\n"621 emsg "Directory \"${INPATH}\" is not accessible\n"
612 exit 2622 exit 2
613 fi623 fi
614 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n\n"624 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n\n"
615 split_dir "${INPATH}"625 split_collection "${INPATH}"
616elif [ "${INPATH}" ]; then626elif [ "${INPATH}" ]; then
617 split_file "${INPATH}"627 split_file "${INPATH}"
618else628else
@@ -620,11 +630,9 @@ else · 1 unmodified line
620 exit 1630 exit 1
621fi631fi
622 632
623# exit code of split_dir or split_file633# exit code of split_collection or split_file
624STATUS=$?634STATUS=$?
625 635
626$msg "\n${cP}Finished$cZ\n"636$msg "\n${cP}Finished$cZ\n"
627 637
628if [ ${STATUS} -ne 0 ]; then638[ ${STATUS} -ne 0 ] && exit 3
629 exit 3
630fi

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