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
8080 You may want to pass \$cP'-s'\$cZ option for the first run to save default configuration
8181 (output dir, cover image size, etc.) so you won't need to pass a lot of options
8282 every time, just a filename. Script will try to find CUE sheet if it wasn't specified.
83−It also supports internal CUE sheets (FLAC and WV)."
83+It also supports internal CUE sheets (FLAC, APE and WV)."
8484
8585 msg="echo -e"
8686
87−emsg ( ) {
87+emsg () {
8888 $msg "${cR}$1${cZ}"
8989 }
9090
91−update_colors ( ) {
91+update_colors () {
9292 if [ "${NOCOLORS}" -eq 0 ]; then
9393 cR="\033[31m"
9494 cG="\033[32m"
@@ -173,7 +173,7 @@ esac · 78 unmodified lines
173173 $msg "${cG}Output dir :$cZ ${DIR:?Output directory was not set}"
174174
175175 # splits a file
176−split_file ( ) {
176+split_file () {
177177 FILE="$1"
178178
179179 if [ ! -r "${FILE}" ]; then
@@ -190,10 +190,26 @@ split_file ( ) { · 10 unmodified lines
190190 # try to extract internal one
191191 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/^cuesheet=//;s/^CUESHEET=//')
192192
193+ # try WV internal cue sheet
193194 if [ -z "${CUESHEET}" ]; then
194195 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
195196 fi
196197
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+
197213 if [ "${CUESHEET}" ]; then
198214 $msg "${cP}Found internal cue sheet$cZ"
199215 CUE="${TMPCUE}"
@@ -218,7 +234,7 @@ split_file ( ) { · 18 unmodified lines
218234
219235 if [ "${CHARSET}" ]; then
220236 $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)
222238 if [ $? -ne 0 ]; then
223239 emsg "Unable to convert cue sheet from ${CHARSET} to utf-8"
224240 return 1
@@ -271,9 +287,9 @@ split_file ( ) { · 46 unmodified lines
271287 fi
272288
273289 # get common tags
274− TAG_ARTIST=$(${GETTAG} %P "${CUE}")
275− TAG_ALBUM=$(${GETTAG} %T "${CUE}")
276− TRACKS_NUM=$(${GETTAG} %N "${CUE}")
290+ TAG_ARTIST=$(${GETTAG} %P "${CUE}" 2>/dev/null)
291+ TAG_ALBUM=$(${GETTAG} %T "${CUE}" 2>/dev/null)
292+ TRACKS_NUM=$(${GETTAG} %N "${CUE}" 2>/dev/null)
277293
278294 YEAR=$(awk '{ if (/REM[ \t]+DATE/) { printf "%i", $3; exit } }' < "${CUE}")
279295 YEAR=$(echo ${YEAR} | tr -d -C '[:digit:]')
@@ -322,7 +338,7 @@ split_file ( ) { · 42 unmodified lines
322338 fi
323339
324340 case ${FORMAT} in
325− flac) ENC="flac flac -8 - -o %f";;
341+ flac) ENC="flac flac -0 - -o %f";;
326342 m4a) ENC="cust ext=m4a faac -q 500 -o %f -";;
327343 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
328344 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
@@ -330,7 +346,7 @@ split_file ( ) { · 1 unmodified line
330346 esac
331347
332348 # split to tracks
333− cuebreakpoints "${CUE}" | \
349+ cuebreakpoints "${CUE}" 2>/dev/null | \
334350 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
335351 if [ $? -ne 0 ]; then
336352 emsg "Failed to split"
@@ -354,7 +370,7 @@ split_file ( ) { · 17 unmodified lines
354370
355371 i=1
356372 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)
358374 FILE_TRACK="$(printf %02i $i)"
359375 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
360376 f="${OUT}/${FILE_TRACK}.${FORMAT}"
@@ -481,7 +497,7 @@ split_file ( ) { · 120 unmodified lines
481497 return 0
482498 }
483499
484−split_collection ( ) {
500+split_collection () {
485501 while read -r FILE; do
486502 $msg "$cG>> $cC\"${FILE}\"$cZ"
487503 unset PIC CUE
@@ -496,7 +512,7 @@ split_collection ( ) { · 8 unmodified lines
496512 }
497513
498514 # searches for files in a directory and splits them
499−split_dir ( ) {
515+split_dir () {
500516 find "$1" -name '*.flac' -o -name '*.ape' -o -name '*.wv' | split_collection
501517 }
502518

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