History

apetagv2 cue sheets support; add -c to iconv options; redirect cue-tools errors to /dev/null

Serge Zirukin committed 16 years ago

Commit 62791a41 parent 9a028fe1 file · +29 −13Browse files

Unified · Split

split2flac.sh+29−13
@@ -80,15 +80,15 @@ It's better to pass \$cP'-p'\$cZ option to see what will happen when actually sp · 79 unmodified lines
80You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration80You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration
81(output dir, cover image size, etc.) so you won't need to pass a lot of options81(output dir, cover image size, etc.) so you won't need to pass a lot of options
82every time, just a filename. Script will try to find CUE sheet if it wasn't specified.82every time, just a filename. Script will try to find CUE sheet if it wasn't specified.
83It also supports internal CUE sheets (FLAC and WV)."83It also supports internal CUE sheets (FLAC, APE and WV)."
84 84
85msg="echo -e"85msg="echo -e"
86 86
87emsg ( ) {87emsg () {
88 $msg "${cR}$1${cZ}"88 $msg "${cR}$1${cZ}"
89}89}
90 90
91update_colors ( ) {91update_colors () {
92 if [ "${NOCOLORS}" -eq 0 ]; then92 if [ "${NOCOLORS}" -eq 0 ]; then
93 cR="\033[31m"93 cR="\033[31m"
94 cG="\033[32m"94 cG="\033[32m"
@@ -173,7 +173,7 @@ esac · 78 unmodified lines
173$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"173$msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"
174 174
175# splits a file175# splits a file
176split_file ( ) {176split_file () {
177 FILE="$1"177 FILE="$1"
178 178
179 if [ ! -r "${FILE}" ]; then179 if [ ! -r "${FILE}" ]; then
@@ -190,10 +190,26 @@ split_file ( ) { · 10 unmodified lines
190 # try to extract internal one190 # try to extract internal one
191 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')191 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')
192 192
193 # try WV internal cue sheet
193 if [ -z "${CUESHEET}" ]; then194 if [ -z "${CUESHEET}" ]; then
194 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)195 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
195 fi196 fi
196 197
198 # try APE internal cue sheet (omfg!)
199 if [ -z "${CHESHEET}" ]; then
200 APETAGEX=$(tail -c 32 "$1" | cut -b 1-8 2>/dev/null)
201 if [ "${APETAGEX}" = "APETAGEX" ]; then
202 LENGTH=$(tail -c 32 "$1" | cut -b 13-16 | od -t u4 | awk '{printf $2}') 2>/dev/null
203 tail -c ${LENGTH} "$1" | grep -a CUESHEET >/dev/null 2>&1
204 if [ $? -eq 0 ]; then
205 CUESHEET=$(tail -c ${LENGTH} "$1" | sed 's/.*CUESHEET.//g' 2>/dev/null)
206 if [ $? -ne 0 ]; then
207 CUESHEET=""
208 fi
209 fi
210 fi
211 fi
212
197 if [ "${CUESHEET}" ]; then213 if [ "${CUESHEET}" ]; then
198 $msg "${cP}Found internal cue sheet$cZ"214 $msg "${cP}Found internal cue sheet$cZ"
199 CUE="${TMPCUE}"215 CUE="${TMPCUE}"
@@ -218,7 +234,7 @@ split_file ( ) { · 18 unmodified lines
218 234
219 if [ "${CHARSET}" ]; then235 if [ "${CHARSET}" ]; then
220 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"236 $msg "${cG}Cue charset : $cP${CHARSET} -> utf-8$cZ"
221 CUESHEET=$(iconv -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)237 CUESHEET=$(iconv -c -f "${CHARSET}" -t utf-8 "${CUE}" 2>/dev/null)
222 if [ $? -ne 0 ]; then238 if [ $? -ne 0 ]; then
223 emsg "Unable to convert cue sheet from ${CHARSET} to utf-8"239 emsg "Unable to convert cue sheet from ${CHARSET} to utf-8"
224 return 1240 return 1
@@ -271,9 +287,9 @@ split_file ( ) { · 46 unmodified lines
271 fi287 fi
272 288
273 # get common tags289 # get common tags
274 TAG_ARTIST=$(${GETTAG} %P "${CUE}")290 TAG_ARTIST=$(${GETTAG} %P "${CUE}" 2>/dev/null)
275 TAG_ALBUM=$(${GETTAG} %T "${CUE}")291 TAG_ALBUM=$(${GETTAG} %T "${CUE}" 2>/dev/null)
276 TRACKS_NUM=$(${GETTAG} %N "${CUE}")292 TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)
277 293
278 YEAR=$(awk '{ if (/REM[ \t]+DATE/) { printf "%i", $3; exit } }' < "${CUE}")294 YEAR=$(awk '{ if (/REM[ \t]+DATE/) { printf "%i", $3; exit } }' < "${CUE}")
279 YEAR=$(echo ${YEAR} | tr -d -C '[:digit:]')295 YEAR=$(echo ${YEAR} | tr -d -C '[:digit:]')
@@ -322,7 +338,7 @@ split_file ( ) { · 42 unmodified lines
322 fi338 fi
323 339
324 case ${FORMAT} in340 case ${FORMAT} in
325 flac) ENC="flac flac -8 - -o %f";;341 flac) ENC="flac flac -0 - -o %f";;
326 m4a) ENC="cust ext=m4a faac -q 500 -o %f -";;342 m4a) ENC="cust ext=m4a faac -q 500 -o %f -";;
327 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;343 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
328 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;344 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
@@ -330,7 +346,7 @@ split_file ( ) { · 1 unmodified line
330 esac346 esac
331 347
332 # split to tracks348 # split to tracks
333 cuebreakpoints "${CUE}" | \349 cuebreakpoints "${CUE}" 2>/dev/null | \
334 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"350 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
335 if [ $? -ne 0 ]; then351 if [ $? -ne 0 ]; then
336 emsg "Failed to split"352 emsg "Failed to split"
@@ -354,7 +370,7 @@ split_file ( ) { · 17 unmodified lines
354 370
355 i=1371 i=1
356 while [ $i -le ${TRACKS_NUM} ]; do372 while [ $i -le ${TRACKS_NUM} ]; do
357 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}")373 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}" 2>/dev/null)
358 FILE_TRACK="$(printf %02i $i)"374 FILE_TRACK="$(printf %02i $i)"
359 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})375 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
360 f="${OUT}/${FILE_TRACK}.${FORMAT}"376 f="${OUT}/${FILE_TRACK}.${FORMAT}"
@@ -481,7 +497,7 @@ split_file ( ) { · 120 unmodified lines
481 return 0497 return 0
482}498}
483 499
484split_collection ( ) {500split_collection () {
485 while read -r FILE; do501 while read -r FILE; do
486 $msg "$cG>> $cC\"${FILE}\"$cZ"502 $msg "$cG>> $cC\"${FILE}\"$cZ"
487 unset PIC CUE503 unset PIC CUE
@@ -496,7 +512,7 @@ split_collection ( ) { · 8 unmodified lines
496}512}
497 513
498# searches for files in a directory and splits them514# searches for files in a directory and splits them
499split_dir ( ) {515split_dir () {
500 find "$1" -name '*.flac' -o -name '*.ape' -o -name '*.wv' | split_collection516 find "$1" -name '*.flac' -o -name '*.ape' -o -name '*.wv' | split_collection
501}517}
502 518

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