You are not logged in.
Hello, I'm writing simple script to automate splitting and tagging audio files.
Here's the code:
#!/bin/bash
cuefile=$1
extension=${cuefile##*.}
basename=${cuefile%.*}
if [[ $# -eq 1 ]] && [[ $extension = "cue" ]]; then
if [ -e "$basename.flac" ]; then
type="flac"
elif [ -e "$basename.ape" ]; then
type="ape"
elif [ -e "$basename.wv" ]; then
type="wv"
elif [ -e "$basename.wav" ]; then
type="wav"
fi
else
echo "You can split only flac, ape, wv and wav files!"
fi
shntool split -f "$basename.cue" -o flac -t %p_-_%n_-_%t -m \ _ "$basename.$type"
performer=`grep -m 1 'PERFORMER' "$cuefile" | sed 's/PERFORMER //g;s/"//g;s/\ /_/g'`
cuetag.sh "$cuefile" "$performer*.flac"Everything works fine except the last line. I got error message like this:
~/code/bash/cuesplit Infatuation\ With\ Malevolence.cue
warning: number of files does not match number of tracks
*.flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE"
The FLAC file could not be opened. Most likely the file does not exist
or is not readable.The strange thing is that if I run "cuetag.sh some_filename.cue artist*.flac" from prompt line it works.
I suspect that problem lies in proper use of regular expression, but I can't find out how to do it right.
Thanks in advance for any help.
Offline
Without seeing some of the input that causes that output, I'm not sure I can be of great help - but I do know that a grep+pipe+sed can almost always be simplified to an awk line. Simplifying this way might help reign in the unwanted behavior too.
Edit: example
performer=`awk '/^PERFORMER/ { print $2_$3_$4_$5 }' $cuefile`Of course you'd have to edit the number of parameters given to print, or if it varies, use a for loop from 2 to $NF.
Last edited by Trilby (2012-02-21 00:34:52)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Hello, I'm writing simple script to automate splitting and tagging audio files.
Here's the code:
cuetag.sh "$cuefile" "$performer*.flac"
You're quoting a glob, meaning it will never expand. You shouldn't be confident that it'll expand, either. You can do something like this:
shopt -s nullglob
files=("$performer"*.flac)
if (( ${#files[*]} )); then
cuetag.sh "$cuefile" "${files[@]}"
else
echo "no files found!"
fiOffline
[karol@black foo1]$ cat a1
#!/bin/bash
cuefile=$1
performer="foo bar baz"
echo "$cuefile" "$performer*.flac"
[karol@black foo1]$ ./a1 test
test foo bar baz*.flacAs falconindy said, '*' will be treated literally because of the quotes - not what you want.
Offline
You're quoting a glob, meaning it will never expand. You shouldn't be confident that it'll expand, either. You can do something like this:
shopt -s nullglob files=("$performer"*.flac) if (( ${#files[*]} )); then cuetag.sh "$cuefile" "${files[@]}" else echo "no files found!" fi
Unfortunately this doesn't work either. I guess the easiest solution will be to parse a cue file to get the exact names of the files to proceed. It will also solve the problem with compilations. I don't have time now, but I will try to do it tomorrow.
[...] but I do know that a grep+pipe+sed can almost always be simplified to an awk line. Simplifying this way might help reign in the unwanted behavior too.
Thanks for the tip.
Offline
I would use find+xargs
find ./ -name "$performer*.flac" -print0 | xargs -0 cuetag.sh "$cuefile"Offline