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
5454 eval $(cat "${CONFIG}" 2>/dev/null)
5555 DRY=0
5656 SAVE=0
57+NASK=0
5758 unset PIC INPATH CUE CHARSET
5859 FORCE=0
5960
@@ -68,6 +69,7 @@ Usage: \${cZ}split2\${FORMAT}.sh [\${cU}OPTIONS\$cZ] \${cU}FILE\$cZ [\${cU}OPTIO · 8 unmodified lines
6869 \$cG-o \${cU}DIRECTORY\$cZ \$cR*\$cZ - set output directory (current is \$cP\${DIR}\$cZ)
6970 \$cG-cue \${cU}FILE\$cZ - use file as a cue sheet (does not work with \${cU}DIR\$cZ)
7071 \$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)
7173 \$cG-f \${cU}FORMAT\$cZ - use specified output format \$cP(current is \${FORMAT})\$cZ
7274 \$cG-c \${cU}FILE\$cZ \$cR*\$cZ - use file as a cover image (does not work with \${cU}DIR\$cZ)
7375 \$cG-nc \${cR}*\$cZ - do not set any cover images
@@ -124,6 +126,7 @@ while [ "$1" ]; do · 50 unmodified lines
124126 -o) DIR=$2; shift;;
125127 -cue) CUE=$2; shift;;
126128 -cuecharset) CHARSET=$2; shift;;
129+ -nask) NASK=1;;
127130 -f) FORMAT=$2; shift;;
128131 -c) NOPIC=0; PIC=$2; shift;;
129132 -nc) NOPIC=1;;
@@ -211,9 +214,7 @@ split_file () { · 81 unmodified lines
211214 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')
212215
213216 # try WV internal cue sheet
214− if [ -z "${CUESHEET}" ]; then
215− CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
216− fi
217+ [ -z "${CUESHEET}" ] && CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
217218
218219 # try APE internal cue sheet (omfg!)
219220 if [ -z "${CUESHEET}" ]; then
@@ -223,9 +224,7 @@ split_file () { · 3 unmodified lines
223224 tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1
224225 if [ $? -eq 0 ]; then
225226 CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null)
226− if [ $? -ne 0 ]; then
227− CUESHEET=""
228− fi
227+ [ $? -ne 0 ] && CUESHEET=""
229228 fi
230229 fi
231230 fi
@@ -252,13 +251,35 @@ split_file () { · 20 unmodified lines
252251 return 1
253252 fi
254253
255− if [ "${CHARSET}" ]; then
256− $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ\n"
257− CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
258− if [ $? -ne 0 ]; then
259− emsg "Unable to convert cue sheet from ${CHARSET} to utf-8\n"
260− return 1
254+ # cue sheet charset
255+ [ -z "${CHARSET}" ] && CHARSET="utf-8" || $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ\n"
256+
257+ CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
258+
259+ 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)
261279 fi
280+ fi
281+
282+ if [ "${CHARSET}" -a "${CHARSET}" != "utf-8" ]; then
262283 CUE="${TMPCUE}"
263284 echo "${CUESHEET}" > "${CUE}"
264285
@@ -299,11 +320,9 @@ split_file () { · 34 unmodified lines
299320 # file removal warning
300321 if [ ${REMOVE} -eq 1 ]; then
301322 msg_removal="\n${cR}Also remove original"
302− if [ ${FORCE} -eq 1 ]; then
303− $msg "$msg_removal (WITHOUT ASKING)$cZ\n"
304− else
305− $msg "$msg_removal if user says 'y'$cZ\n"
306− fi
323+ [ ${FORCE} -eq 1 ] \
324+ && $msg "$msg_removal (WITHOUT ASKING)$cZ\n" \
325+ || $msg "$msg_removal if user says 'y'$cZ\n"
307326 fi
308327
309328 # get common tags
@@ -328,19 +347,13 @@ split_file () { · 18 unmodified lines
328347 unset TAG_DATE
329348
330349 if [ "${YEAR}" ]; then
331− if [ ${YEAR} -ne 0 ]; then
332− TAG_DATE="${YEAR}"
333− fi
350+ [ ${YEAR} -ne 0 ] && TAG_DATE="${YEAR}"
334351 fi
335352
336353 $msg "\n${cG}Artist :$cZ ${TAG_ARTIST}\n"
337354 $msg "${cG}Album :$cZ ${TAG_ALBUM}\n"
338− if [ "${TAG_GENRE}" ]; then
339− $msg "${cG}Genre :$cZ ${TAG_GENRE}\n"
340− fi
341− if [ "${TAG_DATE}" ]; then
342− $msg "${cG}Year :$cZ ${TAG_DATE}\n"
343− fi
355+ [ "${TAG_GENRE}" ] && $msg "${cG}Genre :$cZ ${TAG_GENRE}\n"
356+ [ "${TAG_DATE}" ] && $msg "${cG}Year :$cZ ${TAG_DATE}\n"
344357 $msg "${cG}Tracks :$cZ ${TRACKS_NUM}\n\n"
345358
346359 # prepare output directory
@@ -350,13 +363,9 @@ split_file () { · 3 unmodified lines
350363 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})
351364 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})
352365
353− if [ "${TAG_DATE}" ]; then
354− DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"
355− fi
366+ [ "${TAG_DATE}" ] && DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"
367+ [ ${DRY} -ne 1 ] && mkdir -p "${OUT}/${DIR_ARTIST}"
356368
357− if [ ${DRY} -ne 1 ]; then
358− mkdir -p "${OUT}/${DIR_ARTIST}"
359− fi
360369 OUT="${OUT}/${DIR_ARTIST}/${DIR_ALBUM}"
361370 fi
362371
@@ -544,11 +553,11 @@ split_file () { · 181 unmodified lines
544553
545554 if [ ${DRY} -ne 1 ]; then
546555 ${RG} "${OUT}/"*.${FORMAT} >/dev/null
547− fi
548556
549− if [ $? -ne 0 ]; then
550− emsg "Failed to adjust gain for track\n"
551− return 1
557+ if [ $? -ne 0 ]; then
558+ emsg "Failed to adjust gain for track\n"
559+ return 1
560+ fi
552561 fi
553562 fi
554563
@@ -559,22 +568,29 @@ split_file () { · 4 unmodified lines
559568 YEP="n"
560569
561570 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] > "
563572 read YEP
564573 fi
565574
566− if [ "${YEP}" = "y" -o ${FORCE} -eq 1 ]; then
567− rm -f "${FILE}"
568− fi
575+ [ "${YEP}" = "y" -o "${YEP}" = "Y" -o ${FORCE} -eq 1 ] && rm -f "${FILE}"
569576 fi
570577
571578 return 0
572579 }
573580
581+# searches for files in a directory and splits them
574582 split_collection () {
583+ rm -f "${FAILED}"
575584 NUM_FAILED=0
576−
577− while read -r FILE; do
585+ OLDIFS=${IFS}
586+ 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}
578594 $msg "$cG>> $cC\"${FILE}\"$cZ\n"
579595 unset PIC CUE
580596 split_file "${FILE}"
@@ -600,19 +616,13 @@ split_collection () { · 19 unmodified lines
600616 return 0
601617 }
602618
603−# searches for files in a directory and splits them
604−split_dir () {
605− rm -f "${FAILED}"
606− find "$1" -iname '*.flac' -o -iname '*.ape' -o -iname '*.wv' | split_collection
607−}
608−
609619 if [ -d "${INPATH}" ]; then
610620 if [ ! -x "${INPATH}" ]; then
611621 emsg "Directory \"${INPATH}\" is not accessible\n"
612622 exit 2
613623 fi
614624 $msg "${cG}Input dir :$cZ ${INPATH}$cZ\n\n"
615− split_dir "${INPATH}"
625+ split_collection "${INPATH}"
616626 elif [ "${INPATH}" ]; then
617627 split_file "${INPATH}"
618628 else
@@ -620,11 +630,9 @@ else · 1 unmodified line
620630 exit 1
621631 fi
622632
623−# exit code of split_dir or split_file
633+# exit code of split_collection or split_file
624634 STATUS=$?
625635
626636 $msg "\n${cP}Finished$cZ\n"
627637
628−if [ ${STATUS} -ne 0 ]; then
629− exit 3
630−fi
638+[ ${STATUS} -ne 0 ] && exit 3

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