diff --git a/music_tagmove_lib b/music_tagmove_lib index 5f5fa38..5664905 100644 --- a/music_tagmove_lib +++ b/music_tagmove_lib @@ -78,12 +78,16 @@ function read_tag_id3 { local tag="$1" local file="$2" - # TODO: Amorphis/Eclipse eclipse uses 3char id3v2 rfc822 codes declare -A id3v2_map=( [artist]=TPE1 \ [album]=TALB \ [title]=TIT2 \ [date]=TYER \ [track]=TRCK ) + declare -A id3v2_map_alt=( [artist]=TP1 \ + [album]=TAL \ + [title]=TT2 \ + [date]=TYE \ + [track]=TRK ) local id3v2_content_rfc822 id3v2_content_rfc822=$(id3v2 -R "$file") @@ -102,14 +106,26 @@ function read_tag_id3 { error "Unknown tag \"$tag\" requested for file \"$file\"" return fi + + local substr_idx=6 local line=$(grep -E "^$rfc822tag:\s" <<<"$id3v2_content_rfc822" | head -1) - local result=${line:6} + if [[ -z $line ]]; then + rfc822tag=${id3v2_map_alt[$tag]} + line=$(grep -E "^$rfc822tag:\s" <<<"$id3v2_content_rfc822" | head -1) + substr_idx=5 + fi + + local result=${line:${substr_idx}} if [[ -z $result ]]; then error "Reading tag \"$tag\" from \"$file\" failed: empty value" return fi + if [[ $tag == 'track' ]]; then + result=$(grep -oE '^[[:digit:]]+' <<<"$result") + fi + echo "$result" fi }