Commit 9e3a7c92 authored by Cédric Marie's avatar Cédric Marie
Browse files

tag-sieve: Add support for TPOS tag in MP3 files



Add disc number tag (TPOS) in MP3 files, in case of multi-disc albums.
Signed-off-by: default avatarCédric Marie <cedric.marie@openmailbox.org>
parent b777e406
......@@ -153,14 +153,13 @@ if [ "$command" = "clean" ]; then
*) print_usage; exit 1;;
esac
done
multi_disc=0
tags_filename=/tmp/tag-sieve-clean.tags
# FLAC files
if [ "$flac_files" != "" ]; then
multi_disc=0
# Get album information from the first track
print_header "Get album information from the first track ($file)"
file=`ls -1 *.flac | grep -m 1 flac`
......@@ -280,6 +279,9 @@ if [ "$command" = "clean" ]; then
tag_album=${tag_album#*: }
tag_date=`grep "^TYER " $tags_filename`
tag_date=${tag_date#*: }
if grep -q "^TPOS " $tags_filename; then
multi_disc=1
fi
# Print album information
printf "\033[7m"
......@@ -305,7 +307,10 @@ if [ "$command" = "clean" ]; then
tag_title=${tag_title#*: }
tag_tracknumber=`grep "^TRCK " $tags_filename`
tag_tracknumber=${tag_tracknumber#*: }
if [ "$multi_disc" = "1" ]; then
tag_discnumber=`grep "^TPOS " $tags_filename`
tag_discnumber=${tag_discnumber#*: }
fi
old_size=`stat -c %s "$file"`
id3v2 --delete-all "$file" > /dev/null
id3v2 --id3v2-only --artist "$tag_artist" "$file"
......@@ -313,6 +318,9 @@ if [ "$command" = "clean" ]; then
id3v2 --id3v2-only --album "$tag_album" "$file"
id3v2 --id3v2-only --year "$tag_date" "$file"
id3v2 --id3v2-only --track "$tag_tracknumber" "$file"
if [ "$multi_disc" = "1" ]; then
id3v2 --id3v2-only --TPOS "$tag_discnumber" "$file"
fi
new_size=`stat -c %s "$file"`
printf "(saved %4d bytes) $file\n" $(($old_size - $new_size))
done
......@@ -444,6 +452,8 @@ fi
if [ "$command" = "uptn" ]; then
multi_disc=0
# FLAC files
if [ "$flac_files" != "" ]; then
......@@ -453,15 +463,12 @@ if [ "$command" = "uptn" ]; then
multi_disc=1
last_file=`ls -1r *.flac | grep -m 1 flac`
tag_disctotal=${last_file%% - *}
else
tag_tracktotal=`ls -1 *.flac | grep -c flac`
fi
if [ "$multi_disc" = "1" ]; then
print_header "Set track/disc numbers from filename and track/disc total in all tracks"
else
tag_tracktotal=`ls -1 *.flac | grep -c flac`
print_header "Set track numbers from filename and track total in all tracks"
fi
# Set read-write permission
chmod 644 *.flac
......@@ -497,7 +504,14 @@ if [ "$command" = "uptn" ]; then
# MP3 files
elif [ "$mp3_files" != "" ]; then
print_header "Set track numbers from filename in all tracks"
first_file=`ls -1 *.mp3 | grep -m 1 mp3`
if [ "${first_file%% - *}" = "1" ]; then
multi_disc=1
print_header "Set track/disc numbers from filename in all tracks"
else
print_header "Set track numbers from filename in all tracks"
fi
# Set read-write permission
chmod 644 *.mp3
......@@ -511,8 +525,14 @@ if [ "$command" = "uptn" ]; then
# Get the track number without leading 0
tag_tracknumber=${tag_tracknumber%% - *}
tag_tracknumber=${tag_tracknumber#0}
printf "track \033[7m$tag_tracknumber\033[0m: $file\n"
id3v2 --track "$tag_tracknumber" "$file"
if [ "$multi_disc" = "1" ]; then
tag_discnumber=${file%% - *}
id3v2 --TPOS "$tag_discnumber" "$file"
printf "track \033[7m$tag_tracknumber\033[0m, disc \033[7m$tag_discnumber\033[0m: $file\n"
else
printf "track \033[7m$tag_tracknumber\033[0m: $file\n"
fi
done
}
# Set read-only permission
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment